]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/radiocanada.py
2 from __future__
import unicode_literals
5 from .common
import InfoExtractor
6 from ..compat
import compat_HTTPError
15 class RadioCanadaIE(InfoExtractor
):
16 IE_NAME
= 'radiocanada'
17 _VALID_URL
= r
'(?:radiocanada:|https?://ici\.radio-canada\.ca/widgets/mediaconsole/)(?P<app_code>[^:/]+)[:/](?P<id>[0-9]+)'
20 'url': 'http://ici.radio-canada.ca/widgets/mediaconsole/medianet/7184272',
24 'title': 'Le parcours du tireur capté sur vidéo',
25 'description': 'Images des caméras de surveillance fournies par la GRC montrant le parcours du tireur d\'Ottawa',
26 'upload_date': '20141023',
30 'skip_download': True,
35 'url': 'http://ici.radio-canada.ca/widgets/mediaconsole/medianet/7754998/',
39 'title': 'letelejournal22h',
40 'description': 'INTEGRALE WEB 22H-TJ',
41 'upload_date': '20170720',
45 'skip_download': True,
49 # with protectionType but not actually DRM protected
50 'url': 'radiocanada:toutv:140872',
54 'series': 'District 31',
56 'only_matching': True,
59 _GEO_COUNTRIES
= ['CA']
63 def _call_api(self
, path
, video_id
=None, app_code
=None, query
=None):
67 'client_key': '773aea60-0e80-41bb-9c7f-e6d7c3ad17fb',
75 if self
._access
_token
:
76 query
['access_token'] = self
._access
_token
78 return self
._download
_json
(
79 'https://services.radio-canada.ca/media/' + path
, video_id
, query
=query
)
80 except ExtractorError
as e
:
81 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
in (401, 422):
82 data
= self
._parse
_json
(e
.cause
.read().decode(), None)
83 error
= data
.get('error_description') or data
['errorMessage']['text']
84 raise ExtractorError(error
, expected
=True)
87 def _extract_info(self
, app_code
, video_id
):
88 metas
= self
._call
_api
('meta/v1/index.ashx', video_id
, app_code
)['Metas']
92 if meta
.get('name') == name
:
93 text
= meta
.get('text')
97 # protectionType does not necessarily mean the video is DRM protected (see
98 # https://github.com/ytdl-org/youtube-dl/pull/18609).
99 if get_meta('protectionType'):
100 self
.report_warning('This video is probably DRM protected.')
103 'connectionType': 'hd',
104 'deviceType': 'ipad',
105 'multibitrate': 'true',
108 query
['claims'] = self
._claims
109 v_data
= self
._call
_api
('validation/v2/', video_id
, app_code
, query
)
110 v_url
= v_data
.get('url')
112 error
= v_data
['message']
113 if error
== "Le contenu sélectionné n'est pas disponible dans votre pays":
114 raise self
.raise_geo_restricted(error
, self
._GEO
_COUNTRIES
)
115 if error
== 'Le contenu sélectionné est disponible seulement en premium':
116 self
.raise_login_required(error
)
117 raise ExtractorError(
118 '%s said: %s' % (self
.IE_NAME
, error
), expected
=True)
119 formats
= self
._extract
_m
3u8_formats
(v_url
, video_id
, 'mp4')
120 self
._sort
_formats
(formats
)
123 closed_caption_url
= get_meta('closedCaption') or get_meta('closedCaptionHTML5')
124 if closed_caption_url
:
126 'url': closed_caption_url
,
127 'ext': determine_ext(closed_caption_url
, 'vtt'),
132 'title': get_meta('Title') or get_meta('AV-nomEmission'),
133 'description': get_meta('Description') or get_meta('ShortDescription'),
134 'thumbnail': get_meta('imageHR') or get_meta('imageMR') or get_meta('imageBR'),
135 'duration': int_or_none(get_meta('length')),
136 'series': get_meta('Emission'),
137 'season_number': int_or_none('SrcSaison'),
138 'episode_number': int_or_none('SrcEpisode'),
139 'upload_date': unified_strdate(get_meta('Date')),
140 'subtitles': subtitles
,
144 def _real_extract(self
, url
):
145 return self
._extract
_info
(*self
._match
_valid
_url
(url
).groups())
148 class RadioCanadaAudioVideoIE(InfoExtractor
):
149 IE_NAME
= 'radiocanada:audiovideo'
150 _VALID_URL
= r
'https?://ici\.radio-canada\.ca/([^/]+/)*media-(?P<id>[0-9]+)'
152 'url': 'http://ici.radio-canada.ca/audio-video/media-7527184/barack-obama-au-vietnam',
156 'title': 'Barack Obama au Vietnam',
157 'description': 'Les États-Unis lèvent l\'embargo sur la vente d\'armes qui datait de la guerre du Vietnam',
158 'upload_date': '20160523',
162 'skip_download': True,
165 'url': 'https://ici.radio-canada.ca/info/videos/media-7527184/barack-obama-au-vietnam',
166 'only_matching': True,
169 def _real_extract(self
, url
):
170 return self
.url_result('radiocanada:medianet:%s' % self
._match
_id
(url
))