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