]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/tenplay.py
[tenplay] Improve extractor (#3280)
[yt-dlp.git] / yt_dlp / extractor / tenplay.py
CommitLineData
dd90451f
RA
1# coding: utf-8
2from __future__ import unicode_literals
3
74e001af 4from datetime import datetime
5import base64
6
dd90451f
RA
7from .common import InfoExtractor
8from ..utils import (
29f7c58a 9 HEADRequest,
dc57e74a 10 int_or_none,
74e001af 11 urlencode_postdata,
dd90451f
RA
12)
13
14
15class TenPlayIE(InfoExtractor):
c97f5e93 16 _VALID_URL = r'https?://(?:www\.)?10play\.com\.au/(?:[^/]+/)+(?P<id>tpv\d{6}[a-z]{5})'
74e001af 17 _NETRC_MACHINE = '10play'
c97f5e93 18 _TESTS = [{
dc57e74a 19 'url': 'https://10play.com.au/neighbours/web-extras/season-39/nathan-borg-is-the-first-aussie-actor-with-a-cochlear-implant-to-join-neighbours/tpv210128qupwd',
20 'info_dict': {
21 'id': '6226844312001',
22 'ext': 'mp4',
23 'title': 'Nathan Borg Is The First Aussie Actor With A Cochlear Implant To Join Neighbours',
24 'alt_title': 'Nathan Borg Is The First Aussie Actor With A Cochlear Implant To Join Neighbours',
25 'description': 'md5:a02d0199c901c2dd4c796f1e7dd0de43',
26 'duration': 186,
27 'season': 39,
28 'series': 'Neighbours',
29 'thumbnail': r're:https://.*\.jpg',
30 'uploader': 'Channel 10',
31 'age_limit': 15,
32 'timestamp': 1611810000,
33 'upload_date': '20210128',
34 'uploader_id': '2199827728001',
35 },
36 'params': {
37 'skip_download': True,
38 },
39 'skip': 'Only available in Australia',
40 }, {
74e001af 41 'url': 'https://10play.com.au/todd-sampsons-body-hack/episodes/season-4/episode-7/tpv200921kvngh',
dd90451f 42 'info_dict': {
74e001af 43 'id': '6192880312001',
dd90451f 44 'ext': 'mp4',
74e001af 45 'title': "Todd Sampson's Body Hack - S4 Ep. 2",
46 'description': 'md5:fa278820ad90f08ea187f9458316ac74',
47 'age_limit': 15,
48 'timestamp': 1600770600,
49 'upload_date': '20200922',
50 'uploader': 'Channel 10',
51 'uploader_id': '2199827728001'
dd90451f
RA
52 },
53 'params': {
dd90451f
RA
54 'skip_download': True,
55 }
c97f5e93
S
56 }, {
57 'url': 'https://10play.com.au/how-to-stay-married/web-extras/season-1/terrys-talks-ep-1-embracing-change/tpv190915ylupc',
58 'only_matching': True,
59 }]
29f7c58a 60 _GEO_BYPASS = False
74e001af 61
62 _AUS_AGES = {
63 'G': 0,
64 'PG': 15,
65 'M': 15,
66 'MA': 15,
1bd3639f 67 'MA15+': 15,
74e001af 68 'R': 18,
69 'X': 18
70 }
71
72 def _get_bearer_token(self, video_id):
73 username, password = self._get_login_info()
74 if username is None or password is None:
75 self.raise_login_required('Your 10play account\'s details must be provided with --username and --password.')
76 _timestamp = datetime.now().strftime('%Y%m%d000000')
77 _auth_header = base64.b64encode(_timestamp.encode('ascii')).decode('ascii')
78 data = self._download_json('https://10play.com.au/api/user/auth', video_id, 'Getting bearer token', headers={
79 'X-Network-Ten-Auth': _auth_header,
80 }, data=urlencode_postdata({
81 'email': username,
82 'password': password,
83 }))
9222c381 84 return 'Bearer ' + data['jwt']['accessToken']
dd90451f
RA
85
86 def _real_extract(self, url):
87 content_id = self._match_id(url)
88 data = self._download_json(
74e001af 89 'https://10play.com.au/api/v1/videos/' + content_id, content_id)
dc57e74a 90 headers = {}
91
92 if data.get('memberGated') is True:
93 _token = self._get_bearer_token(content_id)
94 headers = {'Authorization': _token}
95
74e001af 96 _video_url = self._download_json(
97 data.get('playbackApiEndpoint'), content_id, 'Downloading video JSON',
dc57e74a 98 headers=headers).get('source')
29f7c58a 99 m3u8_url = self._request_webpage(HEADRequest(
74e001af 100 _video_url), content_id).geturl()
29f7c58a 101 if '10play-not-in-oz' in m3u8_url:
102 self.raise_geo_restricted(countries=['AU'])
74e001af 103 formats = self._extract_m3u8_formats(m3u8_url, content_id, 'mp4')
29f7c58a 104 self._sort_formats(formats)
dd90451f
RA
105
106 return {
29f7c58a 107 'formats': formats,
dc57e74a 108 'subtitles': {'en': [{'url': data.get('captionUrl')}]} if data.get('captionUrl') else None,
74e001af 109 'id': data.get('altId') or content_id,
dc57e74a 110 'duration': data.get('duration'),
111 'title': data.get('subtitle'),
112 'alt_title': data.get('title'),
74e001af 113 'description': data.get('description'),
1bd3639f 114 'age_limit': self._AUS_AGES.get(data.get('classification')),
dc57e74a 115 'series': data.get('tvShow'),
116 'season': int_or_none(data.get('season')),
117 'episode_number': int_or_none(data.get('episode')),
74e001af 118 'timestamp': data.get('published'),
119 'thumbnail': data.get('imageUrl'),
120 'uploader': 'Channel 10',
29f7c58a 121 'uploader_id': '2199827728001',
dd90451f 122 }