]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/dropout.py
[version] update
[yt-dlp.git] / yt_dlp / extractor / dropout.py
1 # coding: utf-8
2 from .common import InfoExtractor
3 from .vimeo import VHXEmbedIE
4 from ..utils import (
5 clean_html,
6 ExtractorError,
7 get_element_by_class,
8 get_element_by_id,
9 get_elements_by_class,
10 int_or_none,
11 join_nonempty,
12 unified_strdate,
13 urlencode_postdata,
14 )
15
16
17 class DropoutIE(InfoExtractor):
18 _LOGIN_URL = 'https://www.dropout.tv/login'
19 _NETRC_MACHINE = 'dropout'
20
21 _VALID_URL = r'https?://(?:www\.)?dropout\.tv/(?:[^/]+/)*videos/(?P<id>[^/]+)/?$'
22 _TESTS = [
23 {
24 'url': 'https://www.dropout.tv/game-changer/season:2/videos/yes-or-no',
25 'note': 'Episode in a series',
26 'md5': '5e000fdfd8d8fa46ff40456f1c2af04a',
27 'info_dict': {
28 'id': '738153',
29 'display_id': 'yes-or-no',
30 'ext': 'mp4',
31 'title': 'Yes or No',
32 'description': 'Ally, Brennan, and Zac are asked a simple question, but is there a correct answer?',
33 'release_date': '20200508',
34 'thumbnail': 'https://vhx.imgix.net/chuncensoredstaging/assets/351e3f24-c4a3-459a-8b79-dc80f1e5b7fd.jpg',
35 'series': 'Game Changer',
36 'season_number': 2,
37 'season': 'Season 2',
38 'episode_number': 6,
39 'episode': 'Yes or No',
40 'duration': 1180,
41 'uploader_id': 'user80538407',
42 'uploader_url': 'https://vimeo.com/user80538407',
43 'uploader': 'OTT Videos'
44 },
45 'expected_warnings': ['Ignoring subtitle tracks found in the HLS manifest']
46 },
47 {
48 'url': 'https://www.dropout.tv/dimension-20-fantasy-high/season:1/videos/episode-1',
49 'note': 'Episode in a series (missing release_date)',
50 'md5': '712caf7c191f1c47c8f1879520c2fa5c',
51 'info_dict': {
52 'id': '320562',
53 'display_id': 'episode-1',
54 'ext': 'mp4',
55 'title': 'The Beginning Begins',
56 'description': 'The cast introduces their PCs, including a neurotic elf, a goblin PI, and a corn-worshipping cleric.',
57 'thumbnail': 'https://vhx.imgix.net/chuncensoredstaging/assets/4421ed0d-f630-4c88-9004-5251b2b8adfa.jpg',
58 'series': 'Dimension 20: Fantasy High',
59 'season_number': 1,
60 'season': 'Season 1',
61 'episode_number': 1,
62 'episode': 'The Beginning Begins',
63 'duration': 6838,
64 'uploader_id': 'user80538407',
65 'uploader_url': 'https://vimeo.com/user80538407',
66 'uploader': 'OTT Videos'
67 },
68 'expected_warnings': ['Ignoring subtitle tracks found in the HLS manifest']
69 },
70 {
71 'url': 'https://www.dropout.tv/videos/misfits-magic-holiday-special',
72 'note': 'Episode not in a series',
73 'md5': 'c30fa18999c5880d156339f13c953a26',
74 'info_dict': {
75 'id': '1915774',
76 'display_id': 'misfits-magic-holiday-special',
77 'ext': 'mp4',
78 'title': 'Misfits & Magic Holiday Special',
79 'description': 'The magical misfits spend Christmas break at Gowpenny, with an unwelcome visitor.',
80 'release_date': '20211215',
81 'thumbnail': 'https://vhx.imgix.net/chuncensoredstaging/assets/d91ea8a6-b250-42ed-907e-b30fb1c65176-8e24b8e5.jpg',
82 'duration': 11698,
83 'uploader_id': 'user80538407',
84 'uploader_url': 'https://vimeo.com/user80538407',
85 'uploader': 'OTT Videos'
86 },
87 'expected_warnings': ['Ignoring subtitle tracks found in the HLS manifest']
88 }
89 ]
90
91 def _get_authenticity_token(self, display_id):
92 signin_page = self._download_webpage(
93 self._LOGIN_URL, display_id, note='Getting authenticity token')
94 return self._html_search_regex(
95 r'name=["\']authenticity_token["\'] value=["\'](.+?)["\']',
96 signin_page, 'authenticity_token')
97
98 def _login(self, display_id):
99 username, password = self._get_login_info()
100 if not (username and password):
101 self.raise_login_required(method='password')
102
103 response = self._download_webpage(
104 self._LOGIN_URL, display_id, note='Logging in', data=urlencode_postdata({
105 'email': username,
106 'password': password,
107 'authenticity_token': self._get_authenticity_token(display_id),
108 'utf8': True
109 }))
110
111 user_has_subscription = self._search_regex(
112 r'user_has_subscription:\s*["\'](.+?)["\']', response, 'subscription status', default='none')
113 if user_has_subscription.lower() == 'true':
114 return response
115 elif user_has_subscription.lower() == 'false':
116 raise ExtractorError('Account is not subscribed')
117 else:
118 raise ExtractorError('Incorrect username/password')
119
120 def _real_extract(self, url):
121 display_id = self._match_id(url)
122 try:
123 self._login(display_id)
124 webpage = self._download_webpage(url, display_id, note='Downloading video webpage')
125 finally:
126 self._download_webpage('https://www.dropout.tv/logout', display_id, note='Logging out')
127
128 embed_url = self._search_regex(r'embed_url:\s*["\'](.+?)["\']', webpage, 'embed url')
129 thumbnail = self._og_search_thumbnail(webpage)
130 watch_info = get_element_by_id('watch-info', webpage) or ''
131
132 title = clean_html(get_element_by_class('video-title', watch_info))
133 season_episode = get_element_by_class(
134 'site-font-secondary-color', get_element_by_class('text', watch_info))
135 episode_number = int_or_none(self._search_regex(
136 r'Episode (\d+)', season_episode or '', 'episode', default=None))
137
138 return {
139 '_type': 'url_transparent',
140 'ie_key': VHXEmbedIE.ie_key(),
141 'url': embed_url,
142 'id': self._search_regex(r'embed.vhx.tv/videos/(.+?)\?', embed_url, 'id'),
143 'display_id': display_id,
144 'title': title,
145 'description': self._html_search_meta('description', webpage, fatal=False),
146 'thumbnail': thumbnail.split('?')[0] if thumbnail else None, # Ignore crop/downscale
147 'series': clean_html(get_element_by_class('series-title', watch_info)),
148 'episode_number': episode_number,
149 'episode': title if episode_number else None,
150 'season_number': int_or_none(self._search_regex(
151 r'Season (\d+),', season_episode or '', 'season', default=None)),
152 'release_date': unified_strdate(self._search_regex(
153 r'data-meta-field-name=["\']release_dates["\'] data-meta-field-value=["\'](.+?)["\']',
154 watch_info, 'release date', default=None)),
155 }
156
157
158 class DropoutSeasonIE(InfoExtractor):
159 _VALID_URL = r'https?://(?:www\.)?dropout\.tv/(?P<id>[^\/$&?#]+)(?:/?$|/season:[0-9]+/?$)'
160 _TESTS = [
161 {
162 'url': 'https://www.dropout.tv/dimension-20-fantasy-high/season:1',
163 'note': 'Multi-season series with the season in the url',
164 'playlist_count': 17,
165 'info_dict': {
166 'id': 'dimension-20-fantasy-high-season-1',
167 'title': 'Dimension 20 Fantasy High - Season 1'
168 }
169 },
170 {
171 'url': 'https://www.dropout.tv/dimension-20-fantasy-high',
172 'note': 'Multi-season series with the season not in the url',
173 'playlist_count': 17,
174 'info_dict': {
175 'id': 'dimension-20-fantasy-high-season-1',
176 'title': 'Dimension 20 Fantasy High - Season 1'
177 }
178 },
179 {
180 'url': 'https://www.dropout.tv/dimension-20-shriek-week',
181 'note': 'Single-season series',
182 'playlist_count': 4,
183 'info_dict': {
184 'id': 'dimension-20-shriek-week-season-1',
185 'title': 'Dimension 20 Shriek Week - Season 1'
186 }
187 }
188 ]
189
190 def _real_extract(self, url):
191 season_id = self._match_id(url)
192 season_title = season_id.replace('-', ' ').title()
193 webpage = self._download_webpage(url, season_id)
194
195 entries = [
196 self.url_result(
197 url=self._search_regex(r'<a href=["\'](.+?)["\'] class=["\']browse-item-link["\']',
198 item, 'item_url'),
199 ie=DropoutIE.ie_key()
200 ) for item in get_elements_by_class('js-collection-item', webpage)
201 ]
202
203 seasons = (get_element_by_class('select-dropdown-wrapper', webpage) or '').strip().replace('\n', '')
204 current_season = self._search_regex(r'<option[^>]+selected>([^<]+)</option>',
205 seasons, 'current_season', default='').strip()
206
207 return {
208 '_type': 'playlist',
209 'id': join_nonempty(season_id, current_season.lower().replace(' ', '-')),
210 'title': join_nonempty(season_title, current_season, delim=' - '),
211 'entries': entries
212 }