]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/tenplay.py
[cleanup] Fix infodict returned fields (#8906)
[yt-dlp.git] / yt_dlp / extractor / tenplay.py
CommitLineData
74e001af 1import base64
88a99c87
MV
2import functools
3import itertools
4from datetime import datetime
74e001af 5
dd90451f 6from .common import InfoExtractor
3d2623a8 7from ..networking import HEADRequest
88a99c87 8from ..utils import int_or_none, traverse_obj, urlencode_postdata, urljoin
dd90451f
RA
9
10
11class TenPlayIE(InfoExtractor):
c97f5e93 12 _VALID_URL = r'https?://(?:www\.)?10play\.com\.au/(?:[^/]+/)+(?P<id>tpv\d{6}[a-z]{5})'
74e001af 13 _NETRC_MACHINE = '10play'
c97f5e93 14 _TESTS = [{
dc57e74a 15 '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',
16 'info_dict': {
17 'id': '6226844312001',
18 'ext': 'mp4',
19 'title': 'Nathan Borg Is The First Aussie Actor With A Cochlear Implant To Join Neighbours',
20 'alt_title': 'Nathan Borg Is The First Aussie Actor With A Cochlear Implant To Join Neighbours',
21 'description': 'md5:a02d0199c901c2dd4c796f1e7dd0de43',
22 'duration': 186,
f4f9f6d0 23 'season': 'Season 39',
24 'season_number': 39,
dc57e74a 25 'series': 'Neighbours',
26 'thumbnail': r're:https://.*\.jpg',
27 'uploader': 'Channel 10',
28 'age_limit': 15,
29 'timestamp': 1611810000,
30 'upload_date': '20210128',
31 'uploader_id': '2199827728001',
32 },
33 'params': {
34 'skip_download': True,
35 },
36 'skip': 'Only available in Australia',
37 }, {
74e001af 38 'url': 'https://10play.com.au/todd-sampsons-body-hack/episodes/season-4/episode-7/tpv200921kvngh',
dd90451f 39 'info_dict': {
74e001af 40 'id': '6192880312001',
dd90451f 41 'ext': 'mp4',
74e001af 42 'title': "Todd Sampson's Body Hack - S4 Ep. 2",
43 'description': 'md5:fa278820ad90f08ea187f9458316ac74',
44 'age_limit': 15,
45 'timestamp': 1600770600,
46 'upload_date': '20200922',
47 'uploader': 'Channel 10',
48 'uploader_id': '2199827728001'
dd90451f
RA
49 },
50 'params': {
dd90451f
RA
51 'skip_download': True,
52 }
c97f5e93
S
53 }, {
54 'url': 'https://10play.com.au/how-to-stay-married/web-extras/season-1/terrys-talks-ep-1-embracing-change/tpv190915ylupc',
55 'only_matching': True,
56 }]
29f7c58a 57 _GEO_BYPASS = False
74e001af 58
59 _AUS_AGES = {
60 'G': 0,
61 'PG': 15,
62 'M': 15,
63 'MA': 15,
1bd3639f 64 'MA15+': 15,
74e001af 65 'R': 18,
66 'X': 18
67 }
68
69 def _get_bearer_token(self, video_id):
70 username, password = self._get_login_info()
71 if username is None or password is None:
72 self.raise_login_required('Your 10play account\'s details must be provided with --username and --password.')
73 _timestamp = datetime.now().strftime('%Y%m%d000000')
74 _auth_header = base64.b64encode(_timestamp.encode('ascii')).decode('ascii')
75 data = self._download_json('https://10play.com.au/api/user/auth', video_id, 'Getting bearer token', headers={
76 'X-Network-Ten-Auth': _auth_header,
77 }, data=urlencode_postdata({
78 'email': username,
79 'password': password,
80 }))
9222c381 81 return 'Bearer ' + data['jwt']['accessToken']
dd90451f
RA
82
83 def _real_extract(self, url):
84 content_id = self._match_id(url)
85 data = self._download_json(
74e001af 86 'https://10play.com.au/api/v1/videos/' + content_id, content_id)
dc57e74a 87 headers = {}
88
89 if data.get('memberGated') is True:
90 _token = self._get_bearer_token(content_id)
91 headers = {'Authorization': _token}
92
74e001af 93 _video_url = self._download_json(
94 data.get('playbackApiEndpoint'), content_id, 'Downloading video JSON',
dc57e74a 95 headers=headers).get('source')
29f7c58a 96 m3u8_url = self._request_webpage(HEADRequest(
3d2623a8 97 _video_url), content_id).url
29f7c58a 98 if '10play-not-in-oz' in m3u8_url:
99 self.raise_geo_restricted(countries=['AU'])
74e001af 100 formats = self._extract_m3u8_formats(m3u8_url, content_id, 'mp4')
dd90451f
RA
101
102 return {
29f7c58a 103 'formats': formats,
dc57e74a 104 'subtitles': {'en': [{'url': data.get('captionUrl')}]} if data.get('captionUrl') else None,
74e001af 105 'id': data.get('altId') or content_id,
dc57e74a 106 'duration': data.get('duration'),
107 'title': data.get('subtitle'),
108 'alt_title': data.get('title'),
74e001af 109 'description': data.get('description'),
1bd3639f 110 'age_limit': self._AUS_AGES.get(data.get('classification')),
dc57e74a 111 'series': data.get('tvShow'),
f4f9f6d0 112 'season_number': int_or_none(data.get('season')),
dc57e74a 113 'episode_number': int_or_none(data.get('episode')),
74e001af 114 'timestamp': data.get('published'),
115 'thumbnail': data.get('imageUrl'),
116 'uploader': 'Channel 10',
29f7c58a 117 'uploader_id': '2199827728001',
dd90451f 118 }
88a99c87
MV
119
120
121class TenPlaySeasonIE(InfoExtractor):
122 _VALID_URL = r'https?://(?:www\.)?10play\.com\.au/(?P<show>[^/?#]+)/episodes/(?P<season>[^/?#]+)/?(?:$|[?#])'
123 _TESTS = [{
124 'url': 'https://10play.com.au/masterchef/episodes/season-14',
125 'info_dict': {
126 'title': 'Season 14',
127 'id': 'MjMyOTIy',
128 },
129 'playlist_mincount': 64,
130 }, {
131 'url': 'https://10play.com.au/the-bold-and-the-beautiful-fast-tracked/episodes/season-2022',
132 'info_dict': {
133 'title': 'Season 2022',
134 'id': 'Mjc0OTIw',
135 },
136 'playlist_mincount': 256,
137 }]
138
139 def _entries(self, load_more_url, display_id=None):
140 skip_ids = []
141 for page in itertools.count(1):
142 episodes_carousel = self._download_json(
143 load_more_url, display_id, query={'skipIds[]': skip_ids},
144 note=f'Fetching episodes page {page}')
145
146 episodes_chunk = episodes_carousel['items']
147 skip_ids.extend(ep['id'] for ep in episodes_chunk)
148
149 for ep in episodes_chunk:
150 yield ep['cardLink']
151 if not episodes_carousel['hasMore']:
152 break
153
154 def _real_extract(self, url):
155 show, season = self._match_valid_url(url).group('show', 'season')
156 season_info = self._download_json(
157 f'https://10play.com.au/api/shows/{show}/episodes/{season}', f'{show}/{season}')
158
159 episodes_carousel = traverse_obj(season_info, (
160 'content', 0, 'components', (
161 lambda _, v: v['title'].lower() == 'episodes',
162 (..., {dict}),
163 )), get_all=False) or {}
164
165 playlist_id = episodes_carousel['tpId']
166
167 return self.playlist_from_matches(
168 self._entries(urljoin(url, episodes_carousel['loadMoreUrl']), playlist_id),
169 playlist_id, traverse_obj(season_info, ('content', 0, 'title', {str})),
170 getter=functools.partial(urljoin, url))