2 from __future__ import unicode_literals
6 from .common import InfoExtractor
18 class RadioCanadaIE(InfoExtractor):
19 IE_NAME = 'radiocanada'
20 _VALID_URL = r'(?:radiocanada:|https?://ici\.radio-canada\.ca/widgets/mediaconsole/)(?P<app_code>[^:/]+)[:/](?P<id>[0-9]+)'
22 'url': 'http://ici.radio-canada.ca/widgets/mediaconsole/medianet/7184272',
26 'title': 'Le parcours du tireur capté sur vidéo',
27 'description': 'Images des caméras de surveillance fournies par la GRC montrant le parcours du tireur d\'Ottawa',
28 'upload_date': '20141023',
32 'skip_download': True,
36 def _real_extract(self, url):
37 app_code, video_id = re.match(self._VALID_URL, url).groups()
39 device_types = ['ipad']
40 if app_code != 'toutv':
41 device_types.append('flash')
44 # TODO: extract f4m formats
45 # f4m formats can be extracted using flashhd device_type but they produce unplayable file
46 for device_type in device_types:
47 v_data = self._download_xml(
48 'http://api.radio-canada.ca/validationMedia/v1/Validation.ashx',
49 video_id, note='Downloading %s XML' % device_type, query={
52 'connectionType': 'broadband',
53 'multibitrate': 'true',
54 'deviceType': device_type,
55 # paysJ391wsHjbOJwvCs26toz and bypasslock are used to bypass geo-restriction
56 'paysJ391wsHjbOJwvCs26toz': 'CA',
57 'bypasslock': 'NZt5K62gRqfc',
59 v_url = xpath_text(v_data, 'url')
63 raise ExtractorError('%s said: %s' % (
64 self.IE_NAME, xpath_text(v_data, 'message')), expected=True)
65 ext = determine_ext(v_url)
67 formats.extend(self._extract_m3u8_formats(
68 v_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
70 formats.extend(self._extract_f4m_formats(v_url, video_id, f4m_id='hds', fatal=False))
72 ext = determine_ext(v_url)
73 bitrates = xpath_element(v_data, 'bitrates')
74 for url_e in bitrates.findall('url'):
75 tbr = int_or_none(url_e.get('bitrate'))
79 'format_id': 'rtmp-%d' % tbr,
80 'url': re.sub(r'\d+\.%s' % ext, '%d.%s' % (tbr, ext), v_url),
83 'width': int_or_none(url_e.get('width')),
84 'height': int_or_none(url_e.get('height')),
87 self._sort_formats(formats)
89 metadata = self._download_xml(
90 'http://api.radio-canada.ca/metaMedia/v1/index.ashx',
91 video_id, note='Downloading metadata XML', query={
97 el = find_xpath_attr(metadata, './/Meta', 'name', name)
98 return el.text if el is not None else None
102 'title': get_meta('Title'),
103 'description': get_meta('Description') or get_meta('ShortDescription'),
104 'thumbnail': get_meta('imageHR') or get_meta('imageMR') or get_meta('imageBR'),
105 'duration': int_or_none(get_meta('length')),
106 'series': get_meta('Emission'),
107 'season_number': int_or_none('SrcSaison'),
108 'episode_number': int_or_none('SrcEpisode'),
109 'upload_date': unified_strdate(get_meta('Date')),
114 class RadioCanadaAudioVideoIE(InfoExtractor):
115 'radiocanada:audiovideo'
116 _VALID_URL = r'https?://ici\.radio-canada\.ca/audio-video/media-(?P<id>[0-9]+)'
118 'url': 'http://ici.radio-canada.ca/audio-video/media-7527184/barack-obama-au-vietnam',
122 'title': 'Barack Obama au Vietnam',
123 'description': 'Les États-Unis lèvent l\'embargo sur la vente d\'armes qui datait de la guerre du Vietnam',
124 'upload_date': '20160523',
128 'skip_download': True,
132 def _real_extract(self, url):
133 return self.url_result('radiocanada:medianet:%s' % self._match_id(url))