2 from __future__ import unicode_literals
6 from .common import InfoExtractor
16 class RadioCanadaIE(InfoExtractor):
17 IE_NAME = 'radiocanada'
18 _VALID_URL = r'(?:radiocanada:|https?://ici\.radio-canada\.ca/widgets/mediaconsole/)(?P<app_code>[^:/]+)[:/](?P<id>[0-9]+)'
21 'url': 'http://ici.radio-canada.ca/widgets/mediaconsole/medianet/7184272',
25 'title': 'Le parcours du tireur capté sur vidéo',
26 'description': 'Images des caméras de surveillance fournies par la GRC montrant le parcours du tireur d\'Ottawa',
27 'upload_date': '20141023',
31 'skip_download': True,
36 'url': 'http://ici.radio-canada.ca/widgets/mediaconsole/medianet/7754998/',
40 'title': 'letelejournal22h',
41 'description': 'INTEGRALE WEB 22H-TJ',
42 'upload_date': '20170720',
46 'skip_download': True,
50 # with protectionType but not actually DRM protected
51 'url': 'radiocanada:toutv:140872',
55 'series': 'District 31',
57 'only_matching': True,
60 _GEO_COUNTRIES = ['CA']
62 def _call_api(self, path, video_id, app_code, query):
68 return self._download_json(
69 'https://services.radio-canada.ca/media/' + path, video_id, headers={
70 'Authorization': 'Client-Key 773aea60-0e80-41bb-9c7f-e6d7c3ad17fb'
73 def _real_extract(self, url):
74 url, smuggled_data = unsmuggle_url(url, {})
75 app_code, video_id = re.match(self._VALID_URL, url).groups()
77 metas = self._call_api('meta/v1/index.ashx', video_id, app_code, {})['Metas']
81 if meta.get('name') == name:
82 text = meta.get('text')
86 # protectionType does not necessarily mean the video is DRM protected (see
87 # https://github.com/rg3/youtube-dl/pull/18609).
88 if get_meta('protectionType'):
89 self.report_warning('This video is probably DRM protected.')
92 'connectionType': 'hd',
94 'multibitrate': 'true',
97 query.update(smuggled_data)
98 v_data = self._call_api('validation/v2/', video_id, app_code, query)
99 v_url = v_data.get('url')
101 error = v_data['message']
102 if error == "Le contenu sélectionné n'est pas disponible dans votre pays":
103 raise self.raise_geo_restricted(error, self._GEO_COUNTRIES)
104 raise ExtractorError(
105 '%s said: %s' % (self.IE_NAME, error), expected=True)
106 formats = self._extract_m3u8_formats(v_url, video_id, 'mp4')
107 self._sort_formats(formats)
110 closed_caption_url = get_meta('closedCaption') or get_meta('closedCaptionHTML5')
111 if closed_caption_url:
113 'url': closed_caption_url,
114 'ext': determine_ext(closed_caption_url, 'vtt'),
119 'title': get_meta('Title') or get_meta('AV-nomEmission'),
120 'description': get_meta('Description') or get_meta('ShortDescription'),
121 'thumbnail': get_meta('imageHR') or get_meta('imageMR') or get_meta('imageBR'),
122 'duration': int_or_none(get_meta('length')),
123 'series': get_meta('Emission'),
124 'season_number': int_or_none('SrcSaison'),
125 'episode_number': int_or_none('SrcEpisode'),
126 'upload_date': unified_strdate(get_meta('Date')),
127 'subtitles': subtitles,
132 class RadioCanadaAudioVideoIE(InfoExtractor):
133 'radiocanada:audiovideo'
134 _VALID_URL = r'https?://ici\.radio-canada\.ca/([^/]+/)*media-(?P<id>[0-9]+)'
136 'url': 'http://ici.radio-canada.ca/audio-video/media-7527184/barack-obama-au-vietnam',
140 'title': 'Barack Obama au Vietnam',
141 'description': 'Les États-Unis lèvent l\'embargo sur la vente d\'armes qui datait de la guerre du Vietnam',
142 'upload_date': '20160523',
146 'skip_download': True,
149 'url': 'https://ici.radio-canada.ca/info/videos/media-7527184/barack-obama-au-vietnam',
150 'only_matching': True,
153 def _real_extract(self, url):
154 return self.url_result('radiocanada:medianet:%s' % self._match_id(url))