]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/radiocanada.py
8ec402646767a22f8a1e7cedbc89eb8576b59804
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
19 class RadioCanadaIE(InfoExtractor
):
20 IE_NAME
= 'radiocanada'
21 _VALID_URL
= r
'(?:radiocanada:|https?://ici\.radio-canada\.ca/widgets/mediaconsole/)(?P<app_code>[^:/]+)[:/](?P<id>[0-9]+)'
23 'url': 'http://ici.radio-canada.ca/widgets/mediaconsole/medianet/7184272',
27 'title': 'Le parcours du tireur capté sur vidéo',
28 'description': 'Images des caméras de surveillance fournies par la GRC montrant le parcours du tireur d\'Ottawa',
29 'upload_date': '20141023',
33 'skip_download': True,
37 def _real_extract(self
, url
):
38 app_code
, video_id
= re
.match(self
._VALID
_URL
, url
).groups()
40 device_types
= ['ipad', 'android']
41 if app_code
!= 'toutv':
42 device_types
.append('flash')
45 # TODO: extract f4m formats
46 # f4m formats can be extracted using flashhd device_type but they produce unplayable file
47 for device_type
in device_types
:
48 v_data
= self
._download
_xml
(
49 'http://api.radio-canada.ca/validationMedia/v1/Validation.ashx',
50 video_id
, note
='Downloading %s XML' % device_type
, query
={
53 'connectionType': 'broadband',
54 'multibitrate': 'true',
55 'deviceType': device_type
,
56 # paysJ391wsHjbOJwvCs26toz and bypasslock are used to bypass geo-restriction
57 'paysJ391wsHjbOJwvCs26toz': 'CA',
58 'bypasslock': 'NZt5K62gRqfc',
60 v_url
= xpath_text(v_data
, 'url')
64 raise ExtractorError('%s said: %s' % (
65 self
.IE_NAME
, xpath_text(v_data
, 'message')), expected
=True)
66 ext
= determine_ext(v_url
)
68 formats
.extend(self
._extract
_m
3u8_formats
(
69 v_url
, video_id
, 'mp4', m3u8_id
='hls', fatal
=False))
71 formats
.extend(self
._extract
_f
4m
_formats
(
72 v_url
, video_id
, f4m_id
='hds', fatal
=False))
74 ext
= determine_ext(v_url
)
75 bitrates
= xpath_element(v_data
, 'bitrates')
76 for url_e
in bitrates
.findall('url'):
77 tbr
= int_or_none(url_e
.get('bitrate'))
80 f_url
= re
.sub(r
'\d+\.%s' % ext
, '%d.%s' % (tbr
, ext
), v_url
)
81 protocol
= determine_protocol({'url': f_url
})
83 'format_id': '%s-%d' % (protocol
, tbr
),
85 'ext': 'flv' if protocol
== 'rtmp' else ext
,
87 'width': int_or_none(url_e
.get('width')),
88 'height': int_or_none(url_e
.get('height')),
91 if protocol
== 'rtsp':
92 base_url
= self
._search
_regex
(
93 r
'rtsp://([^?]+)', f_url
, 'base url', default
=None)
95 base_url
= 'http://' + base_url
96 formats
.extend(self
._extract
_m
3u8_formats
(
97 base_url
+ '/playlist.m3u8', video_id
, 'mp4',
98 'm3u8_native', m3u8_id
='hls', fatal
=False))
99 formats
.extend(self
._extract
_f
4m
_formats
(
100 base_url
+ '/manifest.f4m', video_id
,
101 f4m_id
='hds', fatal
=False))
102 self
._sort
_formats
(formats
)
104 metadata
= self
._download
_xml
(
105 'http://api.radio-canada.ca/metaMedia/v1/index.ashx',
106 video_id
, note
='Downloading metadata XML', query
={
112 el
= find_xpath_attr(metadata
, './/Meta', 'name', name
)
113 return el
.text
if el
is not None else None
117 'title': get_meta('Title'),
118 'description': get_meta('Description') or get_meta('ShortDescription'),
119 'thumbnail': get_meta('imageHR') or get_meta('imageMR') or get_meta('imageBR'),
120 'duration': int_or_none(get_meta('length')),
121 'series': get_meta('Emission'),
122 'season_number': int_or_none('SrcSaison'),
123 'episode_number': int_or_none('SrcEpisode'),
124 'upload_date': unified_strdate(get_meta('Date')),
129 class RadioCanadaAudioVideoIE(InfoExtractor
):
130 'radiocanada:audiovideo'
131 _VALID_URL
= r
'https?://ici\.radio-canada\.ca/audio-video/media-(?P<id>[0-9]+)'
133 'url': 'http://ici.radio-canada.ca/audio-video/media-7527184/barack-obama-au-vietnam',
137 'title': 'Barack Obama au Vietnam',
138 'description': 'Les États-Unis lèvent l\'embargo sur la vente d\'armes qui datait de la guerre du Vietnam',
139 'upload_date': '20160523',
143 'skip_download': True,
147 def _real_extract(self
, url
):
148 return self
.url_result('radiocanada:medianet:%s' % self
._match
_id
(url
))