[cleanup] Make more playlist entries lazy (#11763)
[yt-dlp.git] / yt_dlp / extractor / tenplay.py
blobcc7bc3b2fceaab52a29ab7bbd76cc51547a3a70a
1 import itertools
3 from .common import InfoExtractor
4 from ..networking import HEADRequest
5 from ..utils import int_or_none, traverse_obj, url_or_none, urljoin
8 class TenPlayIE(InfoExtractor):
9 _VALID_URL = r'https?://(?:www\.)?10play\.com\.au/(?:[^/]+/)+(?P<id>tpv\d{6}[a-z]{5})'
10 _NETRC_MACHINE = '10play'
11 _TESTS = [{
12 'url': 'https://10play.com.au/neighbours/web-extras/season-41/heres-a-first-look-at-mischa-bartons-neighbours-debut/tpv230911hyxnz',
13 'info_dict': {
14 'id': '6336940246112',
15 'ext': 'mp4',
16 'title': 'Here\'s A First Look At Mischa Barton\'s Neighbours Debut',
17 'alt_title': 'Here\'s A First Look At Mischa Barton\'s Neighbours Debut',
18 'description': 'Neighbours Premieres Monday, September 18 At 4:30pm On 10 And 10 Play And 6:30pm On 10 Peach',
19 'duration': 74,
20 'season': 'Season 41',
21 'season_number': 41,
22 'series': 'Neighbours',
23 'thumbnail': r're:https://.*\.jpg',
24 'uploader': 'Channel 10',
25 'age_limit': 15,
26 'timestamp': 1694386800,
27 'upload_date': '20230910',
28 'uploader_id': '2199827728001',
30 'params': {
31 'skip_download': True,
33 'skip': 'Only available in Australia',
34 }, {
35 'url': 'https://10play.com.au/neighbours/episodes/season-42/episode-9107/tpv240902nzqyp',
36 'info_dict': {
37 'id': '9000000000091177',
38 'ext': 'mp4',
39 'title': 'Neighbours - S42 Ep. 9107',
40 'alt_title': 'Thu 05 Sep',
41 'description': 'md5:37a1f4271be34b9ee2b533426a5fbaef',
42 'duration': 1388,
43 'episode': 'Episode 9107',
44 'episode_number': 9107,
45 'season': 'Season 42',
46 'season_number': 42,
47 'series': 'Neighbours',
48 'thumbnail': r're:https://.*\.jpg',
49 'age_limit': 15,
50 'timestamp': 1725517860,
51 'upload_date': '20240905',
52 'uploader': 'Channel 10',
53 'uploader_id': '2199827728001',
55 'params': {
56 'skip_download': True,
58 'skip': 'Only available in Australia',
59 }, {
60 'url': 'https://10play.com.au/how-to-stay-married/web-extras/season-1/terrys-talks-ep-1-embracing-change/tpv190915ylupc',
61 'only_matching': True,
63 _GEO_BYPASS = False
65 _AUS_AGES = {
66 'G': 0,
67 'PG': 15,
68 'M': 15,
69 'MA': 15,
70 'MA15+': 15,
71 'R': 18,
72 'X': 18,
75 def _real_extract(self, url):
76 content_id = self._match_id(url)
77 data = self._download_json(
78 'https://10play.com.au/api/v1/videos/' + content_id, content_id)
80 video_data = self._download_json(
81 f'https://vod.ten.com.au/api/videos/bcquery?command=find_videos_by_id&video_id={data["altId"]}',
82 content_id, 'Downloading video JSON')
83 m3u8_url = self._request_webpage(
84 HEADRequest(video_data['items'][0]['HLSURL']),
85 content_id, 'Checking stream URL').url
86 if '10play-not-in-oz' in m3u8_url:
87 self.raise_geo_restricted(countries=['AU'])
88 # Attempt to get a higher quality stream
89 m3u8_url = m3u8_url.replace(',150,75,55,0000', ',300,150,75,55,0000')
90 formats = self._extract_m3u8_formats(m3u8_url, content_id, 'mp4')
92 return {
93 'id': content_id,
94 'formats': formats,
95 'subtitles': {'en': [{'url': data['captionUrl']}]} if url_or_none(data.get('captionUrl')) else None,
96 'uploader': 'Channel 10',
97 'uploader_id': '2199827728001',
98 **traverse_obj(data, {
99 'id': ('altId', {str}),
100 'duration': ('duration', {int_or_none}),
101 'title': ('subtitle', {str}),
102 'alt_title': ('title', {str}),
103 'description': ('description', {str}),
104 'age_limit': ('classification', {self._AUS_AGES.get}),
105 'series': ('tvShow', {str}),
106 'season_number': ('season', {int_or_none}),
107 'episode_number': ('episode', {int_or_none}),
108 'timestamp': ('published', {int_or_none}),
109 'thumbnail': ('imageUrl', {url_or_none}),
114 class TenPlaySeasonIE(InfoExtractor):
115 _VALID_URL = r'https?://(?:www\.)?10play\.com\.au/(?P<show>[^/?#]+)/episodes/(?P<season>[^/?#]+)/?(?:$|[?#])'
116 _TESTS = [{
117 'url': 'https://10play.com.au/masterchef/episodes/season-14',
118 'info_dict': {
119 'title': 'Season 14',
120 'id': 'MjMyOTIy',
122 'playlist_mincount': 64,
123 }, {
124 'url': 'https://10play.com.au/the-bold-and-the-beautiful-fast-tracked/episodes/season-2022',
125 'info_dict': {
126 'title': 'Season 2022',
127 'id': 'Mjc0OTIw',
129 'playlist_mincount': 256,
132 def _entries(self, load_more_url, display_id=None):
133 skip_ids = []
134 for page in itertools.count(1):
135 episodes_carousel = self._download_json(
136 load_more_url, display_id, query={'skipIds[]': skip_ids},
137 note=f'Fetching episodes page {page}')
139 episodes_chunk = episodes_carousel['items']
140 skip_ids.extend(ep['id'] for ep in episodes_chunk)
142 for ep in episodes_chunk:
143 yield ep['cardLink']
144 if not episodes_carousel['hasMore']:
145 break
147 def _real_extract(self, url):
148 show, season = self._match_valid_url(url).group('show', 'season')
149 season_info = self._download_json(
150 f'https://10play.com.au/api/shows/{show}/episodes/{season}', f'{show}/{season}')
152 episodes_carousel = traverse_obj(season_info, (
153 'content', 0, 'components', (
154 lambda _, v: v['title'].lower() == 'episodes',
155 (..., {dict}),
156 )), get_all=False) or {}
158 playlist_id = episodes_carousel['tpId']
160 return self.playlist_from_matches(
161 self._entries(urljoin(url, episodes_carousel['loadMoreUrl']), playlist_id),
162 playlist_id, traverse_obj(season_info, ('content', 0, 'title', {str})),
163 getter=urljoin(url))