4 from datetime
import datetime
6 from .common
import InfoExtractor
7 from ..networking
import HEADRequest
8 from ..utils
import int_or_none
, traverse_obj
, urlencode_postdata
, urljoin
11 class TenPlayIE(InfoExtractor
):
12 _VALID_URL
= r
'https?://(?:www\.)?10play\.com\.au/(?:[^/]+/)+(?P<id>tpv\d{6}[a-z]{5})'
13 _NETRC_MACHINE
= '10play'
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',
17 'id': '6226844312001',
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',
24 'series': 'Neighbours',
25 'thumbnail': r
're:https://.*\.jpg',
26 'uploader': 'Channel 10',
28 'timestamp': 1611810000,
29 'upload_date': '20210128',
30 'uploader_id': '2199827728001',
33 'skip_download': True,
35 'skip': 'Only available in Australia',
37 'url': 'https://10play.com.au/todd-sampsons-body-hack/episodes/season-4/episode-7/tpv200921kvngh',
39 'id': '6192880312001',
41 'title': "Todd Sampson's Body Hack - S4 Ep. 2",
42 'description': 'md5:fa278820ad90f08ea187f9458316ac74',
44 'timestamp': 1600770600,
45 'upload_date': '20200922',
46 'uploader': 'Channel 10',
47 'uploader_id': '2199827728001'
50 'skip_download': True,
53 'url': 'https://10play.com.au/how-to-stay-married/web-extras/season-1/terrys-talks-ep-1-embracing-change/tpv190915ylupc',
54 'only_matching': True,
68 def _get_bearer_token(self
, video_id
):
69 username
, password
= self
._get
_login
_info
()
70 if username
is None or password
is None:
71 self
.raise_login_required('Your 10play account\'s details must be provided with --username and --password.')
72 _timestamp
= datetime
.now().strftime('%Y%m%d000000')
73 _auth_header
= base64
.b64encode(_timestamp
.encode('ascii')).decode('ascii')
74 data
= self
._download
_json
('https://10play.com.au/api/user/auth', video_id
, 'Getting bearer token', headers
={
75 'X-Network-Ten-Auth': _auth_header
,
76 }, data
=urlencode_postdata({
80 return 'Bearer ' + data
['jwt']['accessToken']
82 def _real_extract(self
, url
):
83 content_id
= self
._match
_id
(url
)
84 data
= self
._download
_json
(
85 'https://10play.com.au/api/v1/videos/' + content_id
, content_id
)
88 if data
.get('memberGated') is True:
89 _token
= self
._get
_bearer
_token
(content_id
)
90 headers
= {'Authorization': _token}
92 _video_url
= self
._download
_json
(
93 data
.get('playbackApiEndpoint'), content_id
, 'Downloading video JSON',
94 headers
=headers
).get('source')
95 m3u8_url
= self
._request
_webpage
(HEADRequest(
96 _video_url
), content_id
).url
97 if '10play-not-in-oz' in m3u8_url
:
98 self
.raise_geo_restricted(countries
=['AU'])
99 formats
= self
._extract
_m
3u8_formats
(m3u8_url
, content_id
, 'mp4')
103 'subtitles': {'en': [{'url': data.get('captionUrl')}
]} if data
.get('captionUrl') else None,
104 'id': data
.get('altId') or content_id
,
105 'duration': data
.get('duration'),
106 'title': data
.get('subtitle'),
107 'alt_title': data
.get('title'),
108 'description': data
.get('description'),
109 'age_limit': self
._AUS
_AGES
.get(data
.get('classification')),
110 'series': data
.get('tvShow'),
111 'season': int_or_none(data
.get('season')),
112 'episode_number': int_or_none(data
.get('episode')),
113 'timestamp': data
.get('published'),
114 'thumbnail': data
.get('imageUrl'),
115 'uploader': 'Channel 10',
116 'uploader_id': '2199827728001',
120 class TenPlaySeasonIE(InfoExtractor
):
121 _VALID_URL
= r
'https?://(?:www\.)?10play\.com\.au/(?P<show>[^/?#]+)/episodes/(?P<season>[^/?#]+)/?(?:$|[?#])'
123 'url': 'https://10play.com.au/masterchef/episodes/season-14',
125 'title': 'Season 14',
128 'playlist_mincount': 64,
130 'url': 'https://10play.com.au/the-bold-and-the-beautiful-fast-tracked/episodes/season-2022',
132 'title': 'Season 2022',
135 'playlist_mincount': 256,
138 def _entries(self
, load_more_url
, display_id
=None):
140 for page
in itertools
.count(1):
141 episodes_carousel
= self
._download
_json
(
142 load_more_url
, display_id
, query
={'skipIds[]': skip_ids}
,
143 note
=f
'Fetching episodes page {page}')
145 episodes_chunk
= episodes_carousel
['items']
146 skip_ids
.extend(ep
['id'] for ep
in episodes_chunk
)
148 for ep
in episodes_chunk
:
150 if not episodes_carousel
['hasMore']:
153 def _real_extract(self
, url
):
154 show
, season
= self
._match
_valid
_url
(url
).group('show', 'season')
155 season_info
= self
._download
_json
(
156 f
'https://10play.com.au/api/shows/{show}/episodes/{season}', f
'{show}/{season}')
158 episodes_carousel
= traverse_obj(season_info
, (
159 'content', 0, 'components', (
160 lambda _
, v
: v
['title'].lower() == 'episodes',
162 )), get_all
=False) or {}
164 playlist_id
= episodes_carousel
['tpId']
166 return self
.playlist_from_matches(
167 self
._entries
(urljoin(url
, episodes_carousel
['loadMoreUrl']), playlist_id
),
168 playlist_id
, traverse_obj(season_info
, ('content', 0, 'title', {str}
)),
169 getter
=functools
.partial(urljoin
, url
))