]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/toutv.py
2 from __future__
import unicode_literals
6 from .radiocanada
import RadioCanadaIE
7 from ..compat
import compat_HTTPError
15 class TouTvIE(RadioCanadaIE
):
16 _NETRC_MACHINE
= 'toutv'
18 _VALID_URL
= r
'https?://ici\.tou\.tv/(?P<id>[a-zA-Z0-9_-]+(?:/S[0-9]+[EC][0-9]+)?)'
21 'url': 'http://ici.tou.tv/garfield-tout-court/S2015E17',
25 'title': 'Saison 2015 Épisode 17',
26 'description': 'La photo de famille 2',
27 'upload_date': '20100717',
31 'skip_download': True,
33 'skip': '404 Not Found',
35 'url': 'http://ici.tou.tv/hackers',
36 'only_matching': True,
38 'url': 'https://ici.tou.tv/l-age-adulte/S01C501',
39 'only_matching': True,
41 _CLIENT_KEY
= '4dd36440-09d5-4468-8923-b6d91174ad36'
43 def _real_initialize(self
):
44 email
, password
= self
._get
_login
_info
()
48 self
._access
_token
= self
._download
_json
(
49 'https://services.radio-canada.ca/toutv/profiling/accounts/login',
50 None, 'Logging in', data
=json
.dumps({
51 'ClientId': self
._CLIENT
_KEY
,
52 'ClientSecret': '34026772-244b-49b6-8b06-317b30ac9a20',
55 'Scope': 'id.write media-validation.read',
56 }).encode(), headers
={
57 'Authorization': 'client-key ' + self
._CLIENT
_KEY
,
58 'Content-Type': 'application/json;charset=utf-8',
60 except ExtractorError
as e
:
61 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 401:
62 error
= self
._parse
_json
(e
.cause
.read().decode(), None)['Message']
63 raise ExtractorError(error
, expected
=True)
65 self
._claims
= self
._call
_api
('validation/v2/getClaims')['claims']
67 def _real_extract(self
, url
):
68 path
= self
._match
_id
(url
)
69 metadata
= self
._download
_json
(
70 'https://services.radio-canada.ca/toutv/presentation/%s' % path
, path
, query
={
71 'client_key': self
._CLIENT
_KEY
,
75 # IsDrm does not necessarily mean the video is DRM protected (see
76 # https://github.com/ytdl-org/youtube-dl/issues/13994).
77 if metadata
.get('IsDrm'):
78 self
.report_warning('This video is probably DRM protected.', path
)
79 video_id
= metadata
['IdMedia']
80 details
= metadata
['Details']
84 'title': details
.get('OriginalTitle'),
85 'description': details
.get('Description'),
86 'thumbnail': details
.get('ImageUrl'),
87 'duration': int_or_none(details
.get('LengthInSeconds')),
88 'series': metadata
.get('ProgramTitle'),
89 'season_number': int_or_none(metadata
.get('SeasonNumber')),
90 'season': metadata
.get('SeasonTitle'),
91 'episode_number': int_or_none(metadata
.get('EpisodeNumber')),
92 'episode': metadata
.get('EpisodeTitle'),
93 }, self
._extract
_info
(metadata
.get('AppCode', 'toutv'), video_id
))