]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/radiocanada.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from ..compat
import compat_HTTPError
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']
64 def _call_api(self
, path
, video_id
=None, app_code
=None, query
=None):
68 'client_key': '773aea60-0e80-41bb-9c7f-e6d7c3ad17fb',
76 if self
._access
_token
:
77 query
['access_token'] = self
._access
_token
79 return self
._download
_json
(
80 'https://services.radio-canada.ca/media/' + path
, video_id
, query
=query
)
81 except ExtractorError
as e
:
82 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
in (401, 422):
83 data
= self
._parse
_json
(e
.cause
.read().decode(), None)
84 error
= data
.get('error_description') or data
['errorMessage']['text']
85 raise ExtractorError(error
, expected
=True)
88 def _extract_info(self
, app_code
, video_id
):
89 metas
= self
._call
_api
('meta/v1/index.ashx', video_id
, app_code
)['Metas']
93 if meta
.get('name') == name
:
94 text
= meta
.get('text')
98 # protectionType does not necessarily mean the video is DRM protected (see
99 # https://github.com/ytdl-org/youtube-dl/pull/18609).
100 if get_meta('protectionType'):
101 self
.report_warning('This video is probably DRM protected.')
104 'connectionType': 'hd',
105 'deviceType': 'ipad',
106 'multibitrate': 'true',
109 query
['claims'] = self
._claims
110 v_data
= self
._call
_api
('validation/v2/', video_id
, app_code
, query
)
111 v_url
= v_data
.get('url')
113 error
= v_data
['message']
114 if error
== "Le contenu sélectionné n'est pas disponible dans votre pays":
115 raise self
.raise_geo_restricted(error
, self
._GEO
_COUNTRIES
)
116 if error
== 'Le contenu sélectionné est disponible seulement en premium':
117 self
.raise_login_required(error
)
118 raise ExtractorError(
119 '%s said: %s' % (self
.IE_NAME
, error
), expected
=True)
120 formats
= self
._extract
_m
3u8_formats
(v_url
, video_id
, 'mp4')
121 self
._sort
_formats
(formats
)
124 closed_caption_url
= get_meta('closedCaption') or get_meta('closedCaptionHTML5')
125 if closed_caption_url
:
127 'url': closed_caption_url
,
128 'ext': determine_ext(closed_caption_url
, 'vtt'),
133 'title': get_meta('Title') or get_meta('AV-nomEmission'),
134 'description': get_meta('Description') or get_meta('ShortDescription'),
135 'thumbnail': get_meta('imageHR') or get_meta('imageMR') or get_meta('imageBR'),
136 'duration': int_or_none(get_meta('length')),
137 'series': get_meta('Emission'),
138 'season_number': int_or_none('SrcSaison'),
139 'episode_number': int_or_none('SrcEpisode'),
140 'upload_date': unified_strdate(get_meta('Date')),
141 'subtitles': subtitles
,
145 def _real_extract(self
, url
):
146 return self
._extract
_info
(*re
.match(self
._VALID
_URL
, url
).groups())
149 class RadioCanadaAudioVideoIE(InfoExtractor
):
150 IE_NAME
= 'radiocanada:audiovideo'
151 _VALID_URL
= r
'https?://ici\.radio-canada\.ca/([^/]+/)*media-(?P<id>[0-9]+)'
153 'url': 'http://ici.radio-canada.ca/audio-video/media-7527184/barack-obama-au-vietnam',
157 'title': 'Barack Obama au Vietnam',
158 'description': 'Les États-Unis lèvent l\'embargo sur la vente d\'armes qui datait de la guerre du Vietnam',
159 'upload_date': '20160523',
163 'skip_download': True,
166 'url': 'https://ici.radio-canada.ca/info/videos/media-7527184/barack-obama-au-vietnam',
167 'only_matching': True,
170 def _real_extract(self
, url
):
171 return self
.url_result('radiocanada:medianet:%s' % self
._match
_id
(url
))