]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/toutv.py
Completely change project name to yt-dlp (#85)
[yt-dlp.git] / yt_dlp / extractor / toutv.py
CommitLineData
59040888 1# coding: utf-8
8c820776
S
2from __future__ import unicode_literals
3
829685b8 4import json
d7df3089 5
8fecc735 6from .radiocanada import RadioCanadaIE
7b6e7608 7from ..compat import compat_HTTPError
98b7506e 8from ..utils import (
7b6e7608 9 ExtractorError,
98b7506e 10 int_or_none,
8fecc735 11 merge_dicts,
98b7506e 12)
59040888
PH
13
14
8fecc735 15class TouTvIE(RadioCanadaIE):
98b7506e 16 _NETRC_MACHINE = 'toutv'
8c820776 17 IE_NAME = 'tou.tv'
e6b8803d 18 _VALID_URL = r'https?://ici\.tou\.tv/(?P<id>[a-zA-Z0-9_-]+(?:/S[0-9]+[EC][0-9]+)?)'
59040888 19
de328af3 20 _TESTS = [{
882af14d 21 'url': 'http://ici.tou.tv/garfield-tout-court/S2015E17',
8c820776 22 'info_dict': {
882af14d 23 'id': '122017',
057c0609 24 'ext': 'mp4',
882af14d 25 'title': 'Saison 2015 Épisode 17',
26 'description': 'La photo de famille 2',
27 'upload_date': '20100717',
59040888 28 },
8c820776 29 'params': {
882af14d 30 # m3u8 download
31 'skip_download': True,
59040888 32 },
98b7506e 33 'skip': '404 Not Found',
de328af3
S
34 }, {
35 'url': 'http://ici.tou.tv/hackers',
36 'only_matching': True,
e6b8803d
RA
37 }, {
38 'url': 'https://ici.tou.tv/l-age-adulte/S01C501',
39 'only_matching': True,
de328af3 40 }]
8361e7f9 41 _CLIENT_KEY = '90505c8d-9c34-4f34-8da1-3a85bdc6d4f4'
59040888 42
98b7506e
RA
43 def _real_initialize(self):
44 email, password = self._get_login_info()
45 if email is None:
46 return
7b6e7608
RA
47 try:
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',
53 'Email': email,
54 'Password': password,
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',
59 })['access_token']
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)
64 raise
8fecc735 65 self._claims = self._call_api('validation/v2/getClaims')['claims']
98b7506e 66
59040888 67 def _real_extract(self, url):
882af14d 68 path = self._match_id(url)
50d66047
RA
69 metadata = self._download_json(
70 'https://services.radio-canada.ca/toutv/presentation/%s' % path, path, query={
71 'client_key': self._CLIENT_KEY,
72 'device': 'web',
73 'version': 4,
74 })
8d7a24af 75 # IsDrm does not necessarily mean the video is DRM protected (see
067aa17e 76 # https://github.com/ytdl-org/youtube-dl/issues/13994).
63ad4d43 77 if not self._downloader.params.get('allow_unplayable_formats') and metadata.get('IsDrm'):
8d7a24af 78 self.report_warning('This video is probably DRM protected.', path)
882af14d 79 video_id = metadata['IdMedia']
80 details = metadata['Details']
59040888 81
8fecc735 82 return merge_dicts({
59040888 83 'id': video_id,
8fecc735 84 'title': details.get('OriginalTitle'),
50d66047 85 'description': details.get('Description'),
882af14d 86 'thumbnail': details.get('ImageUrl'),
87 'duration': int_or_none(details.get('LengthInSeconds')),
50d66047
RA
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'),
8fecc735 93 }, self._extract_info(metadata.get('AppCode', 'toutv'), video_id))