[cleanup] Make more playlist entries lazy (#11763)
[yt-dlp.git] / yt_dlp / extractor / dropout.py
blob7e97c4d40c9ac1ba3a59c81ea8dd53ef62ca8438
1 import functools
3 from .common import InfoExtractor
4 from .vimeo import VHXEmbedIE
5 from ..utils import (
6 ExtractorError,
7 OnDemandPagedList,
8 clean_html,
9 extract_attributes,
10 get_element_by_class,
11 get_element_by_id,
12 get_elements_html_by_class,
13 int_or_none,
14 traverse_obj,
15 unified_strdate,
16 urlencode_postdata,
20 class DropoutIE(InfoExtractor):
21 _LOGIN_URL = 'https://www.dropout.tv/login'
22 _NETRC_MACHINE = 'dropout'
24 _VALID_URL = r'https?://(?:www\.)?dropout\.tv/(?:[^/]+/)*videos/(?P<id>[^/]+)/?$'
25 _TESTS = [
27 'url': 'https://www.dropout.tv/game-changer/season:2/videos/yes-or-no',
28 'note': 'Episode in a series',
29 'md5': '5e000fdfd8d8fa46ff40456f1c2af04a',
30 'info_dict': {
31 'id': '738153',
32 'display_id': 'yes-or-no',
33 'ext': 'mp4',
34 'title': 'Yes or No',
35 'description': 'Ally, Brennan, and Zac are asked a simple question, but is there a correct answer?',
36 'release_date': '20200508',
37 'thumbnail': 'https://vhx.imgix.net/chuncensoredstaging/assets/351e3f24-c4a3-459a-8b79-dc80f1e5b7fd.jpg',
38 'series': 'Game Changer',
39 'season_number': 2,
40 'season': 'Season 2',
41 'episode_number': 6,
42 'episode': 'Yes or No',
43 'duration': 1180,
44 'uploader_id': 'user80538407',
45 'uploader_url': 'https://vimeo.com/user80538407',
46 'uploader': 'OTT Videos',
48 'expected_warnings': ['Ignoring subtitle tracks found in the HLS manifest'],
51 'url': 'https://www.dropout.tv/dimension-20-fantasy-high/season:1/videos/episode-1',
52 'note': 'Episode in a series (missing release_date)',
53 'md5': '712caf7c191f1c47c8f1879520c2fa5c',
54 'info_dict': {
55 'id': '320562',
56 'display_id': 'episode-1',
57 'ext': 'mp4',
58 'title': 'The Beginning Begins',
59 'description': 'The cast introduces their PCs, including a neurotic elf, a goblin PI, and a corn-worshipping cleric.',
60 'thumbnail': 'https://vhx.imgix.net/chuncensoredstaging/assets/4421ed0d-f630-4c88-9004-5251b2b8adfa.jpg',
61 'series': 'Dimension 20: Fantasy High',
62 'season_number': 1,
63 'season': 'Season 1',
64 'episode_number': 1,
65 'episode': 'The Beginning Begins',
66 'duration': 6838,
67 'uploader_id': 'user80538407',
68 'uploader_url': 'https://vimeo.com/user80538407',
69 'uploader': 'OTT Videos',
71 'expected_warnings': ['Ignoring subtitle tracks found in the HLS manifest'],
74 'url': 'https://www.dropout.tv/videos/misfits-magic-holiday-special',
75 'note': 'Episode not in a series',
76 'md5': 'c30fa18999c5880d156339f13c953a26',
77 'info_dict': {
78 'id': '1915774',
79 'display_id': 'misfits-magic-holiday-special',
80 'ext': 'mp4',
81 'title': 'Misfits & Magic Holiday Special',
82 'description': 'The magical misfits spend Christmas break at Gowpenny, with an unwelcome visitor.',
83 'release_date': '20211215',
84 'thumbnail': 'https://vhx.imgix.net/chuncensoredstaging/assets/d91ea8a6-b250-42ed-907e-b30fb1c65176-8e24b8e5.jpg',
85 'duration': 11698,
86 'uploader_id': 'user80538407',
87 'uploader_url': 'https://vimeo.com/user80538407',
88 'uploader': 'OTT Videos',
90 'expected_warnings': ['Ignoring subtitle tracks found in the HLS manifest'],
94 def _get_authenticity_token(self, display_id):
95 signin_page = self._download_webpage(
96 self._LOGIN_URL, display_id, note='Getting authenticity token')
97 return self._html_search_regex(
98 r'name=["\']authenticity_token["\'] value=["\'](.+?)["\']',
99 signin_page, 'authenticity_token')
101 def _login(self, display_id):
102 username, password = self._get_login_info()
103 if not username:
104 return True
106 response = self._download_webpage(
107 self._LOGIN_URL, display_id, note='Logging in', fatal=False,
108 data=urlencode_postdata({
109 'email': username,
110 'password': password,
111 'authenticity_token': self._get_authenticity_token(display_id),
112 'utf8': True,
115 user_has_subscription = self._search_regex(
116 r'user_has_subscription:\s*["\'](.+?)["\']', response, 'subscription status', default='none')
117 if user_has_subscription.lower() == 'true':
118 return
119 elif user_has_subscription.lower() == 'false':
120 return 'Account is not subscribed'
121 else:
122 return 'Incorrect username/password'
124 def _real_extract(self, url):
125 display_id = self._match_id(url)
127 webpage = None
128 if self._get_cookies('https://www.dropout.tv').get('_session'):
129 webpage = self._download_webpage(url, display_id)
130 if not webpage or '<div id="watch-unauthorized"' in webpage:
131 login_err = self._login(display_id)
132 webpage = self._download_webpage(url, display_id)
133 if login_err and '<div id="watch-unauthorized"' in webpage:
134 if login_err is True:
135 self.raise_login_required(method='any')
136 raise ExtractorError(login_err, expected=True)
138 embed_url = self._search_regex(r'embed_url:\s*["\'](.+?)["\']', webpage, 'embed url')
139 thumbnail = self._og_search_thumbnail(webpage)
140 watch_info = get_element_by_id('watch-info', webpage) or ''
142 title = clean_html(get_element_by_class('video-title', watch_info))
143 season_episode = get_element_by_class(
144 'site-font-secondary-color', get_element_by_class('text', watch_info))
145 episode_number = int_or_none(self._search_regex(
146 r'Episode (\d+)', season_episode or '', 'episode', default=None))
148 return {
149 '_type': 'url_transparent',
150 'ie_key': VHXEmbedIE.ie_key(),
151 'url': VHXEmbedIE._smuggle_referrer(embed_url, 'https://www.dropout.tv'),
152 'id': self._search_regex(r'embed\.vhx\.tv/videos/(.+?)\?', embed_url, 'id'),
153 'display_id': display_id,
154 'title': title,
155 'description': self._html_search_meta('description', webpage, fatal=False),
156 'thumbnail': thumbnail.split('?')[0] if thumbnail else None, # Ignore crop/downscale
157 'series': clean_html(get_element_by_class('series-title', watch_info)),
158 'episode_number': episode_number,
159 'episode': title if episode_number else None,
160 'season_number': int_or_none(self._search_regex(
161 r'Season (\d+),', season_episode or '', 'season', default=None)),
162 'release_date': unified_strdate(self._search_regex(
163 r'data-meta-field-name=["\']release_dates["\'] data-meta-field-value=["\'](.+?)["\']',
164 watch_info, 'release date', default=None)),
168 class DropoutSeasonIE(InfoExtractor):
169 _PAGE_SIZE = 24
170 _VALID_URL = r'https?://(?:www\.)?dropout\.tv/(?P<id>[^\/$&?#]+)(?:/?$|/season:(?P<season>[0-9]+)/?$)'
171 _TESTS = [
173 'url': 'https://www.dropout.tv/dimension-20-fantasy-high/season:1',
174 'note': 'Multi-season series with the season in the url',
175 'playlist_count': 24,
176 'info_dict': {
177 'id': 'dimension-20-fantasy-high-season-1',
178 'title': 'Dimension 20 Fantasy High - Season 1',
182 'url': 'https://www.dropout.tv/dimension-20-fantasy-high',
183 'note': 'Multi-season series with the season not in the url',
184 'playlist_count': 24,
185 'info_dict': {
186 'id': 'dimension-20-fantasy-high-season-1',
187 'title': 'Dimension 20 Fantasy High - Season 1',
191 'url': 'https://www.dropout.tv/dimension-20-shriek-week',
192 'note': 'Single-season series',
193 'playlist_count': 4,
194 'info_dict': {
195 'id': 'dimension-20-shriek-week-season-1',
196 'title': 'Dimension 20 Shriek Week - Season 1',
200 'url': 'https://www.dropout.tv/breaking-news-no-laugh-newsroom/season:3',
201 'note': 'Multi-season series with season in the url that requires pagination',
202 'playlist_count': 25,
203 'info_dict': {
204 'id': 'breaking-news-no-laugh-newsroom-season-3',
205 'title': 'Breaking News No Laugh Newsroom - Season 3',
210 def _fetch_page(self, url, season_id, page):
211 page += 1
212 webpage = self._download_webpage(
213 f'{url}?page={page}', season_id, note=f'Downloading page {page}', expected_status={400})
214 yield from [self.url_result(item_url, DropoutIE) for item_url in traverse_obj(
215 get_elements_html_by_class('browse-item-link', webpage), (..., {extract_attributes}, 'href'))]
217 def _real_extract(self, url):
218 season_id = self._match_id(url)
219 season_num = self._match_valid_url(url).group('season') or 1
220 season_title = season_id.replace('-', ' ').title()
222 return self.playlist_result(
223 OnDemandPagedList(functools.partial(self._fetch_page, url, season_id), self._PAGE_SIZE),
224 f'{season_id}-season-{season_num}', f'{season_title} - Season {season_num}')