]>
Commit | Line | Data |
---|---|---|
1 | import json | |
2 | ||
3 | from .radiocanada import RadioCanadaIE | |
4 | from ..compat import compat_HTTPError | |
5 | from ..utils import ( | |
6 | ExtractorError, | |
7 | int_or_none, | |
8 | merge_dicts, | |
9 | ) | |
10 | ||
11 | ||
12 | class TouTvIE(RadioCanadaIE): | |
13 | _NETRC_MACHINE = 'toutv' | |
14 | IE_NAME = 'tou.tv' | |
15 | _VALID_URL = r'https?://ici\.tou\.tv/(?P<id>[a-zA-Z0-9_-]+(?:/S[0-9]+[EC][0-9]+)?)' | |
16 | ||
17 | _TESTS = [{ | |
18 | 'url': 'http://ici.tou.tv/garfield-tout-court/S2015E17', | |
19 | 'info_dict': { | |
20 | 'id': '122017', | |
21 | 'ext': 'mp4', | |
22 | 'title': 'Saison 2015 Épisode 17', | |
23 | 'description': 'La photo de famille 2', | |
24 | 'upload_date': '20100717', | |
25 | }, | |
26 | 'params': { | |
27 | # m3u8 download | |
28 | 'skip_download': True, | |
29 | }, | |
30 | 'skip': '404 Not Found', | |
31 | }, { | |
32 | 'url': 'http://ici.tou.tv/hackers', | |
33 | 'only_matching': True, | |
34 | }, { | |
35 | 'url': 'https://ici.tou.tv/l-age-adulte/S01C501', | |
36 | 'only_matching': True, | |
37 | }] | |
38 | _CLIENT_KEY = '90505c8d-9c34-4f34-8da1-3a85bdc6d4f4' | |
39 | ||
40 | def _perform_login(self, username, password): | |
41 | try: | |
42 | self._access_token = self._download_json( | |
43 | 'https://services.radio-canada.ca/toutv/profiling/accounts/login', | |
44 | None, 'Logging in', data=json.dumps({ | |
45 | 'ClientId': self._CLIENT_KEY, | |
46 | 'ClientSecret': '34026772-244b-49b6-8b06-317b30ac9a20', | |
47 | 'Email': username, | |
48 | 'Password': password, | |
49 | 'Scope': 'id.write media-validation.read', | |
50 | }).encode(), headers={ | |
51 | 'Authorization': 'client-key ' + self._CLIENT_KEY, | |
52 | 'Content-Type': 'application/json;charset=utf-8', | |
53 | })['access_token'] | |
54 | except ExtractorError as e: | |
55 | if isinstance(e.cause, compat_HTTPError) and e.cause.code == 401: | |
56 | error = self._parse_json(e.cause.read().decode(), None)['Message'] | |
57 | raise ExtractorError(error, expected=True) | |
58 | raise | |
59 | self._claims = self._call_api('validation/v2/getClaims')['claims'] | |
60 | ||
61 | def _real_extract(self, url): | |
62 | path = self._match_id(url) | |
63 | metadata = self._download_json( | |
64 | 'https://services.radio-canada.ca/toutv/presentation/%s' % path, path, query={ | |
65 | 'client_key': self._CLIENT_KEY, | |
66 | 'device': 'web', | |
67 | 'version': 4, | |
68 | }) | |
69 | # IsDrm does not necessarily mean the video is DRM protected (see | |
70 | # https://github.com/ytdl-org/youtube-dl/issues/13994). | |
71 | if not self.get_param('allow_unplayable_formats') and metadata.get('IsDrm'): | |
72 | self.report_warning('This video is probably DRM protected.', path) | |
73 | video_id = metadata['IdMedia'] | |
74 | details = metadata['Details'] | |
75 | ||
76 | return merge_dicts({ | |
77 | 'id': video_id, | |
78 | 'title': details.get('OriginalTitle'), | |
79 | 'description': details.get('Description'), | |
80 | 'thumbnail': details.get('ImageUrl'), | |
81 | 'duration': int_or_none(details.get('LengthInSeconds')), | |
82 | 'series': metadata.get('ProgramTitle'), | |
83 | 'season_number': int_or_none(metadata.get('SeasonNumber')), | |
84 | 'season': metadata.get('SeasonTitle'), | |
85 | 'episode_number': int_or_none(metadata.get('EpisodeNumber')), | |
86 | 'episode': metadata.get('EpisodeTitle'), | |
87 | }, self._extract_info(metadata.get('AppCode', 'toutv'), video_id)) |