]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/toutv.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / toutv.py
CommitLineData
829685b8 1import json
d7df3089 2
8fecc735 3from .radiocanada import RadioCanadaIE
3d2623a8 4from ..networking.exceptions import HTTPError
98b7506e 5from ..utils import (
7b6e7608 6 ExtractorError,
98b7506e 7 int_or_none,
8fecc735 8 merge_dicts,
98b7506e 9)
59040888
PH
10
11
6368e2e6 12class TouTvIE(RadioCanadaIE): # XXX: Do not subclass from concrete IE
98b7506e 13 _NETRC_MACHINE = 'toutv'
8c820776 14 IE_NAME = 'tou.tv'
e6b8803d 15 _VALID_URL = r'https?://ici\.tou\.tv/(?P<id>[a-zA-Z0-9_-]+(?:/S[0-9]+[EC][0-9]+)?)'
59040888 16
de328af3 17 _TESTS = [{
882af14d 18 'url': 'http://ici.tou.tv/garfield-tout-court/S2015E17',
8c820776 19 'info_dict': {
882af14d 20 'id': '122017',
057c0609 21 'ext': 'mp4',
882af14d 22 'title': 'Saison 2015 Épisode 17',
23 'description': 'La photo de famille 2',
24 'upload_date': '20100717',
59040888 25 },
8c820776 26 'params': {
882af14d 27 # m3u8 download
28 'skip_download': True,
59040888 29 },
98b7506e 30 'skip': '404 Not Found',
de328af3
S
31 }, {
32 'url': 'http://ici.tou.tv/hackers',
33 'only_matching': True,
e6b8803d
RA
34 }, {
35 'url': 'https://ici.tou.tv/l-age-adulte/S01C501',
36 'only_matching': True,
de328af3 37 }]
8361e7f9 38 _CLIENT_KEY = '90505c8d-9c34-4f34-8da1-3a85bdc6d4f4'
59040888 39
52efa4b3 40 def _perform_login(self, username, password):
7b6e7608
RA
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',
52efa4b3 47 'Email': username,
7b6e7608
RA
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:
3d2623a8 55 if isinstance(e.cause, HTTPError) and e.cause.status == 401:
56 error = self._parse_json(e.cause.response.read().decode(), None)['Message']
7b6e7608
RA
57 raise ExtractorError(error, expected=True)
58 raise
8fecc735 59 self._claims = self._call_api('validation/v2/getClaims')['claims']
98b7506e 60
59040888 61 def _real_extract(self, url):
882af14d 62 path = self._match_id(url)
50d66047 63 metadata = self._download_json(
add96eb9 64 f'https://services.radio-canada.ca/toutv/presentation/{path}', path, query={
50d66047
RA
65 'client_key': self._CLIENT_KEY,
66 'device': 'web',
67 'version': 4,
68 })
8d7a24af 69 # IsDrm does not necessarily mean the video is DRM protected (see
067aa17e 70 # https://github.com/ytdl-org/youtube-dl/issues/13994).
a06916d9 71 if not self.get_param('allow_unplayable_formats') and metadata.get('IsDrm'):
8d7a24af 72 self.report_warning('This video is probably DRM protected.', path)
882af14d 73 video_id = metadata['IdMedia']
74 details = metadata['Details']
59040888 75
8fecc735 76 return merge_dicts({
59040888 77 'id': video_id,
8fecc735 78 'title': details.get('OriginalTitle'),
50d66047 79 'description': details.get('Description'),
882af14d 80 'thumbnail': details.get('ImageUrl'),
81 'duration': int_or_none(details.get('LengthInSeconds')),
50d66047
RA
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'),
8fecc735 87 }, self._extract_info(metadata.get('AppCode', 'toutv'), video_id))