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