mirror of https://github.com/yt-dlp/yt-dlp
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
3.5 KiB
Python
94 lines
3.5 KiB
Python
11 years ago
|
# coding: utf-8
|
||
11 years ago
|
from __future__ import unicode_literals
|
||
|
|
||
6 years ago
|
import json
|
||
7 years ago
|
|
||
6 years ago
|
from .radiocanada import RadioCanadaIE
|
||
6 years ago
|
from ..compat import compat_HTTPError
|
||
8 years ago
|
from ..utils import (
|
||
6 years ago
|
ExtractorError,
|
||
8 years ago
|
int_or_none,
|
||
6 years ago
|
merge_dicts,
|
||
8 years ago
|
)
|
||
11 years ago
|
|
||
|
|
||
6 years ago
|
class TouTvIE(RadioCanadaIE):
|
||
8 years ago
|
_NETRC_MACHINE = 'toutv'
|
||
11 years ago
|
IE_NAME = 'tou.tv'
|
||
7 years ago
|
_VALID_URL = r'https?://ici\.tou\.tv/(?P<id>[a-zA-Z0-9_-]+(?:/S[0-9]+[EC][0-9]+)?)'
|
||
11 years ago
|
|
||
8 years ago
|
_TESTS = [{
|
||
9 years ago
|
'url': 'http://ici.tou.tv/garfield-tout-court/S2015E17',
|
||
11 years ago
|
'info_dict': {
|
||
9 years ago
|
'id': '122017',
|
||
10 years ago
|
'ext': 'mp4',
|
||
9 years ago
|
'title': 'Saison 2015 Épisode 17',
|
||
|
'description': 'La photo de famille 2',
|
||
|
'upload_date': '20100717',
|
||
11 years ago
|
},
|
||
11 years ago
|
'params': {
|
||
9 years ago
|
# m3u8 download
|
||
|
'skip_download': True,
|
||
11 years ago
|
},
|
||
8 years ago
|
'skip': '404 Not Found',
|
||
8 years ago
|
}, {
|
||
|
'url': 'http://ici.tou.tv/hackers',
|
||
|
'only_matching': True,
|
||
7 years ago
|
}, {
|
||
|
'url': 'https://ici.tou.tv/l-age-adulte/S01C501',
|
||
|
'only_matching': True,
|
||
8 years ago
|
}]
|
||
6 years ago
|
_CLIENT_KEY = '90505c8d-9c34-4f34-8da1-3a85bdc6d4f4'
|
||
11 years ago
|
|
||
8 years ago
|
def _real_initialize(self):
|
||
|
email, password = self._get_login_info()
|
||
|
if email is None:
|
||
|
return
|
||
6 years ago
|
try:
|
||
|
self._access_token = self._download_json(
|
||
|
'https://services.radio-canada.ca/toutv/profiling/accounts/login',
|
||
|
None, 'Logging in', data=json.dumps({
|
||
|
'ClientId': self._CLIENT_KEY,
|
||
|
'ClientSecret': '34026772-244b-49b6-8b06-317b30ac9a20',
|
||
|
'Email': email,
|
||
|
'Password': password,
|
||
|
'Scope': 'id.write media-validation.read',
|
||
|
}).encode(), headers={
|
||
|
'Authorization': 'client-key ' + self._CLIENT_KEY,
|
||
|
'Content-Type': 'application/json;charset=utf-8',
|
||
|
})['access_token']
|
||
|
except ExtractorError as e:
|
||
|
if isinstance(e.cause, compat_HTTPError) and e.cause.code == 401:
|
||
|
error = self._parse_json(e.cause.read().decode(), None)['Message']
|
||
|
raise ExtractorError(error, expected=True)
|
||
|
raise
|
||
6 years ago
|
self._claims = self._call_api('validation/v2/getClaims')['claims']
|
||
8 years ago
|
|
||
11 years ago
|
def _real_extract(self, url):
|
||
9 years ago
|
path = self._match_id(url)
|
||
6 years ago
|
metadata = self._download_json(
|
||
|
'https://services.radio-canada.ca/toutv/presentation/%s' % path, path, query={
|
||
|
'client_key': self._CLIENT_KEY,
|
||
|
'device': 'web',
|
||
|
'version': 4,
|
||
|
})
|
||
7 years ago
|
# IsDrm does not necessarily mean the video is DRM protected (see
|
||
6 years ago
|
# https://github.com/ytdl-org/youtube-dl/issues/13994).
|
||
4 years ago
|
if not self._downloader.params.get('allow_unplayable_formats') and metadata.get('IsDrm'):
|
||
7 years ago
|
self.report_warning('This video is probably DRM protected.', path)
|
||
9 years ago
|
video_id = metadata['IdMedia']
|
||
|
details = metadata['Details']
|
||
11 years ago
|
|
||
6 years ago
|
return merge_dicts({
|
||
11 years ago
|
'id': video_id,
|
||
6 years ago
|
'title': details.get('OriginalTitle'),
|
||
6 years ago
|
'description': details.get('Description'),
|
||
9 years ago
|
'thumbnail': details.get('ImageUrl'),
|
||
|
'duration': int_or_none(details.get('LengthInSeconds')),
|
||
6 years ago
|
'series': metadata.get('ProgramTitle'),
|
||
|
'season_number': int_or_none(metadata.get('SeasonNumber')),
|
||
|
'season': metadata.get('SeasonTitle'),
|
||
|
'episode_number': int_or_none(metadata.get('EpisodeNumber')),
|
||
|
'episode': metadata.get('EpisodeTitle'),
|
||
6 years ago
|
}, self._extract_info(metadata.get('AppCode', 'toutv'), video_id))
|