]>
Commit | Line | Data |
---|---|---|
dcdb292f | 1 | # coding: utf-8 |
9148eb00 PH |
2 | from __future__ import unicode_literals |
3 | ||
b3d14cbf PH |
4 | import json |
5 | import re | |
caeefc29 | 6 | import itertools |
b3d14cbf PH |
7 | |
8 | from .common import InfoExtractor | |
8c25f81b | 9 | from ..compat import ( |
1060425c | 10 | compat_HTTPError, |
6a55bb66 | 11 | compat_str, |
9c44d242 | 12 | compat_urlparse, |
8c25f81b PH |
13 | ) |
14 | from ..utils import ( | |
d5f071af | 15 | determine_ext, |
b3d14cbf | 16 | ExtractorError, |
9c44d242 PH |
17 | InAdvancePagedList, |
18 | int_or_none, | |
ae1c585c | 19 | merge_dicts, |
c1ff6e1a | 20 | NO_DEFAULT, |
55b3e45b | 21 | RegexNotFoundError, |
67dda517 | 22 | sanitized_Request, |
30965ac6 | 23 | smuggle_url, |
b3d14cbf | 24 | std_headers, |
c15cd296 | 25 | try_get, |
c15cd296 | 26 | unified_timestamp, |
9d4660ca | 27 | unsmuggle_url, |
a980bc43 | 28 | urlencode_postdata, |
b407e173 | 29 | unescapeHTML, |
eb4f2740 | 30 | parse_filesize, |
b3d14cbf PH |
31 | ) |
32 | ||
bbafbe20 | 33 | |
efb7e119 JMF |
34 | class VimeoBaseInfoExtractor(InfoExtractor): |
35 | _NETRC_MACHINE = 'vimeo' | |
36 | _LOGIN_REQUIRED = False | |
f6c3664d | 37 | _LOGIN_URL = 'https://vimeo.com/log_in' |
efb7e119 JMF |
38 | |
39 | def _login(self): | |
68217024 | 40 | username, password = self._get_login_info() |
efb7e119 JMF |
41 | if username is None: |
42 | if self._LOGIN_REQUIRED: | |
4f3e9430 | 43 | raise ExtractorError('No login info available, needed for using %s.' % self.IE_NAME, expected=True) |
efb7e119 | 44 | return |
26ad6bcd S |
45 | webpage = self._download_webpage( |
46 | self._LOGIN_URL, None, 'Downloading login page') | |
7c845629 | 47 | token, vuid = self._extract_xsrft_and_vuid(webpage) |
26ad6bcd | 48 | data = { |
f6c3664d | 49 | 'action': 'login', |
efb7e119 JMF |
50 | 'email': username, |
51 | 'password': password, | |
efb7e119 JMF |
52 | 'service': 'vimeo', |
53 | 'token': token, | |
26ad6bcd | 54 | } |
9eab37dc | 55 | self._set_vimeo_cookie('vuid', vuid) |
26ad6bcd S |
56 | try: |
57 | self._download_webpage( | |
58 | self._LOGIN_URL, None, 'Logging in', | |
59 | data=urlencode_postdata(data), headers={ | |
60 | 'Content-Type': 'application/x-www-form-urlencoded', | |
61 | 'Referer': self._LOGIN_URL, | |
62 | }) | |
63 | except ExtractorError as e: | |
64 | if isinstance(e.cause, compat_HTTPError) and e.cause.code == 418: | |
65 | raise ExtractorError( | |
66 | 'Unable to log in: bad username or password', | |
67 | expected=True) | |
68 | raise ExtractorError('Unable to log in') | |
efb7e119 | 69 | |
c1ff6e1a YCH |
70 | def _verify_video_password(self, url, video_id, webpage): |
71 | password = self._downloader.params.get('videopassword') | |
72 | if password is None: | |
73 | raise ExtractorError('This video is protected by a password, use the --video-password option', expected=True) | |
74 | token, vuid = self._extract_xsrft_and_vuid(webpage) | |
75 | data = urlencode_postdata({ | |
76 | 'password': password, | |
77 | 'token': token, | |
78 | }) | |
79 | if url.startswith('http://'): | |
80 | # vimeo only supports https now, but the user can give an http url | |
81 | url = url.replace('http://', 'https://') | |
82 | password_request = sanitized_Request(url + '/password', data) | |
83 | password_request.add_header('Content-Type', 'application/x-www-form-urlencoded') | |
84 | password_request.add_header('Referer', url) | |
85 | self._set_vimeo_cookie('vuid', vuid) | |
86 | return self._download_webpage( | |
87 | password_request, video_id, | |
88 | 'Verifying the password', 'Wrong password') | |
89 | ||
7c845629 S |
90 | def _extract_xsrft_and_vuid(self, webpage): |
91 | xsrft = self._search_regex( | |
b826035d | 92 | r'(?:(?P<q1>["\'])xsrft(?P=q1)\s*:|xsrft\s*[=:])\s*(?P<q>["\'])(?P<xsrft>.+?)(?P=q)', |
f6c3664d | 93 | webpage, 'login token', group='xsrft') |
7c845629 S |
94 | vuid = self._search_regex( |
95 | r'["\']vuid["\']\s*:\s*(["\'])(?P<vuid>.+?)\1', | |
96 | webpage, 'vuid', group='vuid') | |
97 | return xsrft, vuid | |
f6c3664d | 98 | |
9eab37dc S |
99 | def _set_vimeo_cookie(self, name, value): |
100 | self._set_cookie('vimeo.com', name, value) | |
101 | ||
531a7496 YCH |
102 | def _vimeo_sort_formats(self, formats): |
103 | # Bitrates are completely broken. Single m3u8 may contain entries in kbps and bps | |
104 | # at the same time without actual units specified. This lead to wrong sorting. | |
d8c507c9 | 105 | self._sort_formats(formats, field_preference=('preference', 'height', 'width', 'fps', 'tbr', 'format_id')) |
531a7496 YCH |
106 | |
107 | def _parse_config(self, config, video_id): | |
d8c507c9 | 108 | video_data = config['video'] |
531a7496 | 109 | # Extract title |
d8c507c9 | 110 | video_title = video_data['title'] |
531a7496 YCH |
111 | |
112 | # Extract uploader, uploader_url and uploader_id | |
d8c507c9 RA |
113 | video_uploader = video_data.get('owner', {}).get('name') |
114 | video_uploader_url = video_data.get('owner', {}).get('url') | |
531a7496 YCH |
115 | video_uploader_id = video_uploader_url.split('/')[-1] if video_uploader_url else None |
116 | ||
117 | # Extract video thumbnail | |
d8c507c9 | 118 | video_thumbnail = video_data.get('thumbnail') |
531a7496 | 119 | if video_thumbnail is None: |
d8c507c9 | 120 | video_thumbs = video_data.get('thumbs') |
531a7496 YCH |
121 | if video_thumbs and isinstance(video_thumbs, dict): |
122 | _, video_thumbnail = sorted((int(width if width.isdigit() else 0), t_url) for (width, t_url) in video_thumbs.items())[-1] | |
123 | ||
124 | # Extract video duration | |
d8c507c9 | 125 | video_duration = int_or_none(video_data.get('duration')) |
531a7496 YCH |
126 | |
127 | formats = [] | |
d8c507c9 | 128 | config_files = video_data.get('files') or config['request'].get('files', {}) |
531a7496 YCH |
129 | for f in config_files.get('progressive', []): |
130 | video_url = f.get('url') | |
131 | if not video_url: | |
132 | continue | |
133 | formats.append({ | |
134 | 'url': video_url, | |
135 | 'format_id': 'http-%s' % f.get('quality'), | |
136 | 'width': int_or_none(f.get('width')), | |
137 | 'height': int_or_none(f.get('height')), | |
138 | 'fps': int_or_none(f.get('fps')), | |
139 | 'tbr': int_or_none(f.get('bitrate')), | |
140 | }) | |
d8c507c9 RA |
141 | |
142 | for files_type in ('hls', 'dash'): | |
143 | for cdn_name, cdn_data in config_files.get(files_type, {}).get('cdns', {}).items(): | |
144 | manifest_url = cdn_data.get('url') | |
145 | if not manifest_url: | |
146 | continue | |
147 | format_id = '%s-%s' % (files_type, cdn_name) | |
148 | if files_type == 'hls': | |
149 | formats.extend(self._extract_m3u8_formats( | |
150 | manifest_url, video_id, 'mp4', | |
151 | 'm3u8_native', m3u8_id=format_id, | |
152 | note='Downloading %s m3u8 information' % cdn_name, | |
153 | fatal=False)) | |
154 | elif files_type == 'dash': | |
ae9a173b RA |
155 | mpd_pattern = r'/%s/(?:sep/)?video/' % video_id |
156 | mpd_manifest_urls = [] | |
157 | if re.search(mpd_pattern, manifest_url): | |
158 | for suffix, repl in (('', 'video'), ('_sep', 'sep/video')): | |
159 | mpd_manifest_urls.append((format_id + suffix, re.sub( | |
160 | mpd_pattern, '/%s/%s/' % (video_id, repl), manifest_url))) | |
161 | else: | |
162 | mpd_manifest_urls = [(format_id, manifest_url)] | |
163 | for f_id, m_url in mpd_manifest_urls: | |
e834f044 | 164 | mpd_formats = self._extract_mpd_formats( |
ae9a173b RA |
165 | m_url.replace('/master.json', '/master.mpd'), video_id, f_id, |
166 | 'Downloading %s MPD information' % cdn_name, | |
e834f044 S |
167 | fatal=False) |
168 | for f in mpd_formats: | |
169 | if f.get('vcodec') == 'none': | |
170 | f['preference'] = -50 | |
171 | elif f.get('acodec') == 'none': | |
172 | f['preference'] = -40 | |
173 | formats.extend(mpd_formats) | |
531a7496 YCH |
174 | |
175 | subtitles = {} | |
176 | text_tracks = config['request'].get('text_tracks') | |
177 | if text_tracks: | |
178 | for tt in text_tracks: | |
179 | subtitles[tt['lang']] = [{ | |
180 | 'ext': 'vtt', | |
181 | 'url': 'https://vimeo.com' + tt['url'], | |
182 | }] | |
183 | ||
184 | return { | |
185 | 'title': video_title, | |
186 | 'uploader': video_uploader, | |
187 | 'uploader_id': video_uploader_id, | |
188 | 'uploader_url': video_uploader_url, | |
189 | 'thumbnail': video_thumbnail, | |
190 | 'duration': video_duration, | |
191 | 'formats': formats, | |
192 | 'subtitles': subtitles, | |
193 | } | |
194 | ||
efb7e119 | 195 | |
65469a7f | 196 | class VimeoIE(VimeoBaseInfoExtractor): |
b3d14cbf PH |
197 | """Information extractor for vimeo.com.""" |
198 | ||
199 | # _VALID_URL matches Vimeo URLs | |
bbafbe20 | 200 | _VALID_URL = r'''(?x) |
74278def S |
201 | https?:// |
202 | (?: | |
203 | (?: | |
204 | www| | |
205 | (?P<player>player) | |
206 | ) | |
207 | \. | |
208 | )? | |
209 | vimeo(?P<pro>pro)?\.com/ | |
c8e3e097 | 210 | (?!(?:channels|album)/[^/?#]+/?(?:$|[?#])|[^/]+/review/|ondemand/) |
74278def S |
211 | (?:.*?/)? |
212 | (?: | |
213 | (?: | |
214 | play_redirect_hls| | |
215 | moogaloop\.swf)\?clip_id= | |
216 | )? | |
217 | (?:videos?/)? | |
218 | (?P<id>[0-9]+) | |
241a318f | 219 | (?:/[\da-f]+)? |
74278def S |
220 | /?(?:[?&].*)?(?:[#].*)?$ |
221 | ''' | |
9148eb00 | 222 | IE_NAME = 'vimeo' |
a91b954b JMF |
223 | _TESTS = [ |
224 | { | |
9148eb00 | 225 | 'url': 'http://vimeo.com/56015672#at=0', |
9148eb00 PH |
226 | 'md5': '8879b6cc097e987f02484baf890129e5', |
227 | 'info_dict': { | |
ad5976b4 PH |
228 | 'id': '56015672', |
229 | 'ext': 'mp4', | |
68f3b61f | 230 | 'title': "youtube-dl test video - \u2605 \" ' \u5e78 / \\ \u00e4 \u21ad \U0001d550", |
73af6e22 | 231 | 'description': 'md5:509a9ad5c9bf97c60faee9203aca4479', |
c15cd296 | 232 | 'timestamp': 1355990239, |
68f3b61f | 233 | 'upload_date': '20121220', |
ec85ded8 | 234 | 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/user7108434', |
68f3b61f S |
235 | 'uploader_id': 'user7108434', |
236 | 'uploader': 'Filippo Valsorda', | |
237 | 'duration': 10, | |
c38a67bc | 238 | 'license': 'by-sa', |
a91b954b JMF |
239 | }, |
240 | }, | |
241 | { | |
9148eb00 | 242 | 'url': 'http://vimeopro.com/openstreetmapus/state-of-the-map-us-2013/video/68093876', |
9148eb00 PH |
243 | 'md5': '3b5ca6aa22b60dfeeadf50b72e44ed82', |
244 | 'note': 'Vimeo Pro video (#1197)', | |
245 | 'info_dict': { | |
4f3e9430 JMF |
246 | 'id': '68093876', |
247 | 'ext': 'mp4', | |
ec85ded8 | 248 | 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/openstreetmapus', |
9148eb00 PH |
249 | 'uploader_id': 'openstreetmapus', |
250 | 'uploader': 'OpenStreetMap US', | |
251 | 'title': 'Andy Allan - Putting the Carto into OpenStreetMap Cartography', | |
68f3b61f | 252 | 'description': 'md5:fd69a7b8d8c34a4e1d2ec2e4afd6ec30', |
69c8fb9e | 253 | 'duration': 1595, |
a91b954b JMF |
254 | }, |
255 | }, | |
aa32314d | 256 | { |
9148eb00 | 257 | 'url': 'http://player.vimeo.com/video/54469442', |
9148eb00 PH |
258 | 'md5': '619b811a4417aa4abe78dc653becf511', |
259 | 'note': 'Videos that embed the url in the player page', | |
260 | 'info_dict': { | |
4f3e9430 JMF |
261 | 'id': '54469442', |
262 | 'ext': 'mp4', | |
0e6ebc13 | 263 | 'title': 'Kathy Sierra: Building the minimum Badass User, Business of Software 2012', |
9148eb00 | 264 | 'uploader': 'The BLN & Business of Software', |
ec85ded8 | 265 | 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/theblnbusinessofsoftware', |
9148eb00 | 266 | 'uploader_id': 'theblnbusinessofsoftware', |
69c8fb9e | 267 | 'duration': 3610, |
58ea7ec8 | 268 | 'description': None, |
aa32314d | 269 | }, |
93b22c78 JMF |
270 | }, |
271 | { | |
9148eb00 | 272 | 'url': 'http://vimeo.com/68375962', |
9148eb00 PH |
273 | 'md5': 'aaf896bdb7ddd6476df50007a0ac0ae7', |
274 | 'note': 'Video protected with password', | |
275 | 'info_dict': { | |
4f3e9430 JMF |
276 | 'id': '68375962', |
277 | 'ext': 'mp4', | |
9148eb00 | 278 | 'title': 'youtube-dl password protected test video', |
c15cd296 | 279 | 'timestamp': 1371200155, |
9148eb00 | 280 | 'upload_date': '20130614', |
ec85ded8 | 281 | 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/user18948128', |
9148eb00 PH |
282 | 'uploader_id': 'user18948128', |
283 | 'uploader': 'Jaime Marquínez Ferrándiz', | |
69c8fb9e | 284 | 'duration': 10, |
365d136b | 285 | 'description': 'md5:dca3ea23adb29ee387127bc4ddfce63f', |
93b22c78 | 286 | }, |
9148eb00 PH |
287 | 'params': { |
288 | 'videopassword': 'youtube-dl', | |
93b22c78 JMF |
289 | }, |
290 | }, | |
548f31d9 S |
291 | { |
292 | 'url': 'http://vimeo.com/channels/keypeele/75629013', | |
293 | 'md5': '2f86a05afe9d7abc0b9126d229bbe15d', | |
548f31d9 S |
294 | 'info_dict': { |
295 | 'id': '75629013', | |
296 | 'ext': 'mp4', | |
297 | 'title': 'Key & Peele: Terrorist Interrogation', | |
298 | 'description': 'md5:8678b246399b070816b12313e8b4eb5c', | |
ec85ded8 | 299 | 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/atencio', |
548f31d9 S |
300 | 'uploader_id': 'atencio', |
301 | 'uploader': 'Peter Atencio', | |
c15cd296 S |
302 | 'timestamp': 1380339469, |
303 | 'upload_date': '20130928', | |
548f31d9 S |
304 | 'duration': 187, |
305 | }, | |
306 | }, | |
1eac553e S |
307 | { |
308 | 'url': 'http://vimeo.com/76979871', | |
1eac553e S |
309 | 'note': 'Video with subtitles', |
310 | 'info_dict': { | |
311 | 'id': '76979871', | |
312 | 'ext': 'mp4', | |
313 | 'title': 'The New Vimeo Player (You Know, For Videos)', | |
314 | 'description': 'md5:2ec900bf97c3f389378a96aee11260ea', | |
c15cd296 | 315 | 'timestamp': 1381846109, |
1eac553e | 316 | 'upload_date': '20131015', |
ec85ded8 | 317 | 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/staff', |
1eac553e S |
318 | 'uploader_id': 'staff', |
319 | 'uploader': 'Vimeo Staff', | |
69c8fb9e | 320 | 'duration': 62, |
1eac553e S |
321 | } |
322 | }, | |
4698f0d8 JMF |
323 | { |
324 | # from https://www.ouya.tv/game/Pier-Solar-and-the-Great-Architects/ | |
325 | 'url': 'https://player.vimeo.com/video/98044508', | |
326 | 'note': 'The js code contains assignments to the same variable as the config', | |
327 | 'info_dict': { | |
328 | 'id': '98044508', | |
329 | 'ext': 'mp4', | |
330 | 'title': 'Pier Solar OUYA Official Trailer', | |
331 | 'uploader': 'Tulio Gonçalves', | |
ec85ded8 | 332 | 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/user28849593', |
4698f0d8 JMF |
333 | 'uploader_id': 'user28849593', |
334 | }, | |
335 | }, | |
323f82a7 | 336 | { |
337 | # contains original format | |
338 | 'url': 'https://vimeo.com/33951933', | |
365d136b | 339 | 'md5': '53c688fa95a55bf4b7293d37a89c5c53', |
323f82a7 | 340 | 'info_dict': { |
341 | 'id': '33951933', | |
342 | 'ext': 'mp4', | |
343 | 'title': 'FOX CLASSICS - Forever Classic ID - A Full Minute', | |
344 | 'uploader': 'The DMCI', | |
ec85ded8 | 345 | 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/dmci', |
323f82a7 | 346 | 'uploader_id': 'dmci', |
c15cd296 | 347 | 'timestamp': 1324343742, |
323f82a7 | 348 | 'upload_date': '20111220', |
349 | 'description': 'md5:ae23671e82d05415868f7ad1aec21147', | |
350 | }, | |
351 | }, | |
c143ddce S |
352 | { |
353 | # only available via https://vimeo.com/channels/tributes/6213729 and | |
354 | # not via https://vimeo.com/6213729 | |
355 | 'url': 'https://vimeo.com/channels/tributes/6213729', | |
356 | 'info_dict': { | |
357 | 'id': '6213729', | |
365d136b | 358 | 'ext': 'mov', |
c143ddce S |
359 | 'title': 'Vimeo Tribute: The Shining', |
360 | 'uploader': 'Casey Donahue', | |
ec85ded8 | 361 | 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/caseydonahue', |
c143ddce | 362 | 'uploader_id': 'caseydonahue', |
c15cd296 | 363 | 'timestamp': 1250886430, |
c143ddce S |
364 | 'upload_date': '20090821', |
365 | 'description': 'md5:bdbf314014e58713e6e5b66eb252f4a6', | |
366 | }, | |
367 | 'params': { | |
368 | 'skip_download': True, | |
369 | }, | |
370 | 'expected_warnings': ['Unable to download JSON metadata'], | |
371 | }, | |
f16f8505 | 372 | { |
cccd70a2 | 373 | # redirects to ondemand extractor and should be passed through it |
f16f8505 S |
374 | # for successful extraction |
375 | 'url': 'https://vimeo.com/73445910', | |
376 | 'info_dict': { | |
377 | 'id': '73445910', | |
378 | 'ext': 'mp4', | |
379 | 'title': 'The Reluctant Revolutionary', | |
380 | 'uploader': '10Ft Films', | |
ec85ded8 | 381 | 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/tenfootfilms', |
f16f8505 S |
382 | 'uploader_id': 'tenfootfilms', |
383 | }, | |
384 | 'params': { | |
385 | 'skip_download': True, | |
386 | }, | |
387 | }, | |
c143ddce S |
388 | { |
389 | 'url': 'http://vimeo.com/moogaloop.swf?clip_id=2539741', | |
390 | 'only_matching': True, | |
391 | }, | |
8bea039b LL |
392 | { |
393 | 'url': 'https://vimeo.com/109815029', | |
394 | 'note': 'Video not completely processed, "failed" seed status', | |
395 | 'only_matching': True, | |
396 | }, | |
6b7ceee1 S |
397 | { |
398 | 'url': 'https://vimeo.com/groups/travelhd/videos/22439234', | |
399 | 'only_matching': True, | |
400 | }, | |
c8e3e097 S |
401 | { |
402 | 'url': 'https://vimeo.com/album/2632481/video/79010983', | |
403 | 'only_matching': True, | |
404 | }, | |
16f1131a S |
405 | { |
406 | # source file returns 403: Forbidden | |
407 | 'url': 'https://vimeo.com/7809605', | |
408 | 'only_matching': True, | |
409 | }, | |
241a318f S |
410 | { |
411 | 'url': 'https://vimeo.com/160743502/abd0e13fb4', | |
412 | 'only_matching': True, | |
413 | } | |
a91b954b | 414 | ] |
b3d14cbf | 415 | |
d002e919 S |
416 | @staticmethod |
417 | def _smuggle_referrer(url, referrer_url): | |
418 | return smuggle_url(url, {'http_headers': {'Referer': referrer_url}}) | |
419 | ||
b407e173 | 420 | @staticmethod |
09b9c45e S |
421 | def _extract_urls(url, webpage): |
422 | urls = [] | |
b407e173 | 423 | # Look for embedded (iframe) Vimeo player |
09b9c45e | 424 | for mobj in re.finditer( |
7c1f4193 | 425 | r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/\d+.*?)\1', |
f475e881 | 426 | webpage): |
09b9c45e S |
427 | urls.append(VimeoIE._smuggle_referrer(unescapeHTML(mobj.group('url')), url)) |
428 | PLAIN_EMBED_RE = ( | |
429 | # Look for embedded (swf embed) Vimeo player | |
430 | r'<embed[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?vimeo\.com/moogaloop\.swf.+?)\1', | |
431 | # Look more for non-standard embedded Vimeo player | |
432 | r'<video[^>]+src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?vimeo\.com/[0-9]+)\1', | |
433 | ) | |
434 | for embed_re in PLAIN_EMBED_RE: | |
435 | for mobj in re.finditer(embed_re, webpage): | |
436 | urls.append(mobj.group('url')) | |
437 | return urls | |
438 | ||
439 | @staticmethod | |
440 | def _extract_url(url, webpage): | |
441 | urls = VimeoIE._extract_urls(url, webpage) | |
442 | return urls[0] if urls else None | |
b407e173 | 443 | |
0eecc6a4 | 444 | def _verify_player_video_password(self, url, video_id): |
d800609c | 445 | password = self._downloader.params.get('videopassword') |
0eecc6a4 PH |
446 | if password is None: |
447 | raise ExtractorError('This video is protected by a password, use the --video-password option') | |
15707c7e | 448 | data = urlencode_postdata({'password': password}) |
0eecc6a4 | 449 | pass_url = url + '/check-password' |
67dda517 | 450 | password_request = sanitized_Request(pass_url, data) |
0eecc6a4 | 451 | password_request.add_header('Content-Type', 'application/x-www-form-urlencoded') |
bdbb8530 | 452 | password_request.add_header('Referer', url) |
0eecc6a4 PH |
453 | return self._download_json( |
454 | password_request, video_id, | |
bdbb8530 | 455 | 'Verifying the password', 'Wrong password') |
0eecc6a4 | 456 | |
fc79158d JMF |
457 | def _real_initialize(self): |
458 | self._login() | |
459 | ||
a0088bdf | 460 | def _real_extract(self, url): |
5dbe81a1 | 461 | url, data = unsmuggle_url(url, {}) |
0f56a4b4 | 462 | headers = std_headers.copy() |
5dbe81a1 | 463 | if 'http_headers' in data: |
5dbe81a1 | 464 | headers.update(data['http_headers']) |
ba5d51b3 PH |
465 | if 'Referer' not in headers: |
466 | headers['Referer'] = url | |
9d4660ca | 467 | |
b3d14cbf PH |
468 | # Extract ID from URL |
469 | mobj = re.match(self._VALID_URL, url) | |
b3d14cbf | 470 | video_id = mobj.group('id') |
58ea7ec8 | 471 | orig_url = url |
9103bbc5 | 472 | if mobj.group('pro') or mobj.group('player'): |
61e00a97 | 473 | url = 'https://player.vimeo.com/video/' + video_id |
c143ddce | 474 | elif any(p in url for p in ('play_redirect_hls', 'moogaloop.swf')): |
10831b5e | 475 | url = 'https://vimeo.com/' + video_id |
b3d14cbf PH |
476 | |
477 | # Retrieve video webpage to extract further information | |
0f56a4b4 | 478 | request = sanitized_Request(url, headers=headers) |
1060425c | 479 | try: |
f16f8505 | 480 | webpage, urlh = self._download_webpage_handle(request, video_id) |
580f3c79 | 481 | redirect_url = compat_str(urlh.geturl()) |
f16f8505 S |
482 | # Some URLs redirect to ondemand can't be extracted with |
483 | # this extractor right away thus should be passed through | |
484 | # ondemand extractor (e.g. https://vimeo.com/73445910) | |
580f3c79 S |
485 | if VimeoOndemandIE.suitable(redirect_url): |
486 | return self.url_result(redirect_url, VimeoOndemandIE.ie_key()) | |
1060425c PH |
487 | except ExtractorError as ee: |
488 | if isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 403: | |
489 | errmsg = ee.cause.read() | |
490 | if b'Because of its privacy settings, this video cannot be played here' in errmsg: | |
491 | raise ExtractorError( | |
492 | 'Cannot download embed-only video without embedding ' | |
493 | 'URL. Please call youtube-dl with the URL of the page ' | |
494 | 'that embeds this video.', | |
495 | expected=True) | |
496 | raise | |
b3d14cbf PH |
497 | |
498 | # Now we begin extracting as much information as we can from what we | |
499 | # retrieved. First we extract the information common to all extractors, | |
500 | # and latter we extract those that are Vimeo specific. | |
501 | self.report_extraction(video_id) | |
502 | ||
998e6cdb | 503 | vimeo_config = self._search_regex( |
b6aa99af | 504 | r'vimeo\.config\s*=\s*(?:({.+?})|_extend\([^,]+,\s+({.+?})\));', webpage, |
998e6cdb S |
505 | 'vimeo config', default=None) |
506 | if vimeo_config: | |
507 | seed_status = self._parse_json(vimeo_config, video_id).get('seed_status', {}) | |
508 | if seed_status.get('state') == 'failed': | |
509 | raise ExtractorError( | |
b6aa99af | 510 | '%s said: %s' % (self.IE_NAME, seed_status['title']), |
998e6cdb S |
511 | expected=True) |
512 | ||
c38a67bc | 513 | cc_license = None |
c15cd296 | 514 | timestamp = None |
c38a67bc | 515 | |
b3d14cbf PH |
516 | # Extract the config JSON |
517 | try: | |
93b22c78 JMF |
518 | try: |
519 | config_url = self._html_search_regex( | |
41a7b00f LL |
520 | r' data-config-url="(.+?)"', webpage, |
521 | 'config URL', default=None) | |
522 | if not config_url: | |
dd841752 S |
523 | # Sometimes new react-based page is served instead of old one that require |
524 | # different config URL extraction approach (see | |
525 | # https://github.com/rg3/youtube-dl/pull/7209) | |
41a7b00f LL |
526 | vimeo_clip_page_config = self._search_regex( |
527 | r'vimeo\.clip_page_config\s*=\s*({.+?});', webpage, | |
528 | 'vimeo clip page config') | |
c38a67bc S |
529 | page_config = self._parse_json(vimeo_clip_page_config, video_id) |
530 | config_url = page_config['player']['config_url'] | |
531 | cc_license = page_config.get('cc_license') | |
c15cd296 S |
532 | timestamp = try_get( |
533 | page_config, lambda x: x['clip']['uploaded_on'], | |
534 | compat_str) | |
93b22c78 JMF |
535 | config_json = self._download_webpage(config_url, video_id) |
536 | config = json.loads(config_json) | |
537 | except RegexNotFoundError: | |
538 | # For pro videos or player.vimeo.com urls | |
48ad51b2 | 539 | # We try to find out to which variable is assigned the config dic |
ec85ded8 | 540 | m_variable_name = re.search(r'(\w)\.video\.id', webpage) |
48ad51b2 | 541 | if m_variable_name is not None: |
6fc09f01 | 542 | config_re = [r'%s=({[^}].+?});' % re.escape(m_variable_name.group(1))] |
48ad51b2 JMF |
543 | else: |
544 | config_re = [r' = {config:({.+?}),assets:', r'(?:[abc])=({.+?});'] | |
6fc09f01 | 545 | config_re.append(r'\bvar\s+r\s*=\s*({.+?})\s*;') |
9148eb00 | 546 | config = self._search_regex(config_re, webpage, 'info section', |
9e1a5b84 | 547 | flags=re.DOTALL) |
93b22c78 | 548 | config = json.loads(config) |
71907db3 | 549 | except Exception as e: |
b3d14cbf | 550 | if re.search('The creator of this video has not given you permission to embed it on this domain.', webpage): |
9148eb00 | 551 | raise ExtractorError('The author has restricted the access to this video, try with the "--referer" option') |
b3d14cbf | 552 | |
bf8f082a | 553 | if re.search(r'<form[^>]+?id="pw_form"', webpage) is not None: |
5dbe81a1 | 554 | if '_video_password_verified' in data: |
30965ac6 | 555 | raise ExtractorError('video password verification failed!') |
580f3c79 | 556 | self._verify_video_password(redirect_url, video_id, webpage) |
30965ac6 | 557 | return self._real_extract( |
580f3c79 | 558 | smuggle_url(redirect_url, {'_video_password_verified': 'verified'})) |
b3d14cbf | 559 | else: |
9148eb00 | 560 | raise ExtractorError('Unable to extract info section', |
71907db3 | 561 | cause=e) |
559e370f PH |
562 | else: |
563 | if config.get('view') == 4: | |
580f3c79 | 564 | config = self._verify_player_video_password(redirect_url, video_id) |
b3d14cbf | 565 | |
6a55bb66 S |
566 | def is_rented(): |
567 | if '>You rented this title.<' in webpage: | |
568 | return True | |
569 | if config.get('user', {}).get('purchased'): | |
570 | return True | |
571 | label = try_get( | |
572 | config, lambda x: x['video']['vod']['purchase_options'][0]['label_string'], compat_str) | |
573 | if label and label.startswith('You rented this'): | |
574 | return True | |
575 | return False | |
576 | ||
577 | if is_rented(): | |
5dbe81a1 S |
578 | feature_id = config.get('video', {}).get('vod', {}).get('feature_id') |
579 | if feature_id and not data.get('force_feature_id', False): | |
580 | return self.url_result(smuggle_url( | |
581 | 'https://player.vimeo.com/player/%s' % feature_id, | |
582 | {'force_feature_id': True}), 'Vimeo') | |
583 | ||
b3d14cbf | 584 | # Extract video description |
58ea7ec8 | 585 | |
25930395 | 586 | video_description = self._html_search_regex( |
58ea7ec8 PH |
587 | r'(?s)<div\s+class="[^"]*description[^"]*"[^>]*>(.*?)</div>', |
588 | webpage, 'description', default=None) | |
589 | if not video_description: | |
590 | video_description = self._html_search_meta( | |
591 | 'description', webpage, default=None) | |
592 | if not video_description and mobj.group('pro'): | |
593 | orig_webpage = self._download_webpage( | |
594 | orig_url, video_id, | |
595 | note='Downloading webpage for description', | |
596 | fatal=False) | |
597 | if orig_webpage: | |
598 | video_description = self._html_search_meta( | |
599 | 'description', orig_webpage, default=None) | |
600 | if not video_description and not mobj.group('player'): | |
601 | self._downloader.report_warning('Cannot find video description') | |
b3d14cbf PH |
602 | |
603 | # Extract upload date | |
c15cd296 S |
604 | if not timestamp: |
605 | timestamp = self._search_regex( | |
606 | r'<time[^>]+datetime="([^"]+)"', webpage, | |
607 | 'timestamp', default=None) | |
b3d14cbf | 608 | |
4e761794 | 609 | try: |
9148eb00 PH |
610 | view_count = int(self._search_regex(r'UserPlays:(\d+)', webpage, 'view count')) |
611 | like_count = int(self._search_regex(r'UserLikes:(\d+)', webpage, 'like count')) | |
612 | comment_count = int(self._search_regex(r'UserComments:(\d+)', webpage, 'comment count')) | |
4e761794 JMF |
613 | except RegexNotFoundError: |
614 | # This info is only available in vimeo.com/{id} urls | |
615 | view_count = None | |
616 | like_count = None | |
617 | comment_count = None | |
618 | ||
a6387bfd | 619 | formats = [] |
eb4f2740 | 620 | download_request = sanitized_Request('https://vimeo.com/%s?action=load_download_config' % video_id, headers={ |
621 | 'X-Requested-With': 'XMLHttpRequest'}) | |
622 | download_data = self._download_json(download_request, video_id, fatal=False) | |
623 | if download_data: | |
624 | source_file = download_data.get('source_file') | |
d5f071af S |
625 | if isinstance(source_file, dict): |
626 | download_url = source_file.get('download_url') | |
627 | if download_url and not source_file.get('is_cold') and not source_file.get('is_defrosting'): | |
628 | source_name = source_file.get('public_name', 'Original') | |
629 | if self._is_valid_url(download_url, video_id, '%s video' % source_name): | |
1641ca40 S |
630 | ext = (try_get( |
631 | source_file, lambda x: x['extension'], | |
632 | compat_str) or determine_ext( | |
633 | download_url, None) or 'mp4').lower() | |
d5f071af S |
634 | formats.append({ |
635 | 'url': download_url, | |
636 | 'ext': ext, | |
637 | 'width': int_or_none(source_file.get('width')), | |
638 | 'height': int_or_none(source_file.get('height')), | |
639 | 'filesize': parse_filesize(source_file.get('size')), | |
640 | 'format_id': source_name, | |
641 | 'preference': 1, | |
642 | }) | |
1eac553e | 643 | |
ae1c585c S |
644 | info_dict_config = self._parse_config(config, video_id) |
645 | formats.extend(info_dict_config['formats']) | |
531a7496 | 646 | self._vimeo_sort_formats(formats) |
c38a67bc | 647 | |
ae1c585c S |
648 | json_ld = self._search_json_ld(webpage, video_id, default={}) |
649 | ||
c38a67bc S |
650 | if not cc_license: |
651 | cc_license = self._search_regex( | |
652 | r'<link[^>]+rel=["\']license["\'][^>]+href=(["\'])(?P<license>(?:(?!\1).)+)\1', | |
653 | webpage, 'license', default=None, group='license') | |
654 | ||
ae1c585c | 655 | info_dict = { |
b0268cb6 | 656 | 'id': video_id, |
531a7496 | 657 | 'formats': formats, |
c15cd296 | 658 | 'timestamp': unified_timestamp(timestamp), |
b0268cb6 | 659 | 'description': video_description, |
9103bbc5 | 660 | 'webpage_url': url, |
4e761794 JMF |
661 | 'view_count': view_count, |
662 | 'like_count': like_count, | |
663 | 'comment_count': comment_count, | |
c38a67bc | 664 | 'license': cc_license, |
ae1c585c S |
665 | } |
666 | ||
667 | info_dict = merge_dicts(info_dict, info_dict_config, json_ld) | |
531a7496 YCH |
668 | |
669 | return info_dict | |
caeefc29 JMF |
670 | |
671 | ||
74278def | 672 | class VimeoOndemandIE(VimeoBaseInfoExtractor): |
1e501364 | 673 | IE_NAME = 'vimeo:ondemand' |
74278def S |
674 | _VALID_URL = r'https?://(?:www\.)?vimeo\.com/ondemand/(?P<id>[^/?#&]+)' |
675 | _TESTS = [{ | |
676 | # ondemand video not available via https://vimeo.com/id | |
677 | 'url': 'https://vimeo.com/ondemand/20704', | |
678 | 'md5': 'c424deda8c7f73c1dfb3edd7630e2f35', | |
679 | 'info_dict': { | |
680 | 'id': '105442900', | |
681 | 'ext': 'mp4', | |
682 | 'title': 'המעבדה - במאי יותם פלדמן', | |
683 | 'uploader': 'גם סרטים', | |
ec85ded8 | 684 | 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/gumfilms', |
74278def S |
685 | 'uploader_id': 'gumfilms', |
686 | }, | |
1fd0fc42 S |
687 | 'params': { |
688 | 'format': 'best[protocol=https]', | |
689 | }, | |
d002e919 S |
690 | }, { |
691 | # requires Referer to be passed along with og:video:url | |
692 | 'url': 'https://vimeo.com/ondemand/36938/126682985', | |
693 | 'info_dict': { | |
694 | 'id': '126682985', | |
695 | 'ext': 'mp4', | |
696 | 'title': 'Rävlock, rätt läte på rätt plats', | |
697 | 'uploader': 'Lindroth & Norin', | |
ec85ded8 | 698 | 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/user14430847', |
d002e919 S |
699 | 'uploader_id': 'user14430847', |
700 | }, | |
701 | 'params': { | |
702 | 'skip_download': True, | |
703 | }, | |
74278def S |
704 | }, { |
705 | 'url': 'https://vimeo.com/ondemand/nazmaalik', | |
706 | 'only_matching': True, | |
707 | }, { | |
708 | 'url': 'https://vimeo.com/ondemand/141692381', | |
709 | 'only_matching': True, | |
710 | }, { | |
711 | 'url': 'https://vimeo.com/ondemand/thelastcolony/150274832', | |
712 | 'only_matching': True, | |
713 | }] | |
714 | ||
715 | def _real_extract(self, url): | |
716 | video_id = self._match_id(url) | |
717 | webpage = self._download_webpage(url, video_id) | |
d002e919 S |
718 | return self.url_result( |
719 | # Some videos require Referer to be passed along with og:video:url | |
720 | # similarly to generic vimeo embeds (e.g. | |
721 | # https://vimeo.com/ondemand/36938/126682985). | |
722 | VimeoIE._smuggle_referrer(self._og_search_video_url(webpage), url), | |
723 | VimeoIE.ie_key()) | |
74278def S |
724 | |
725 | ||
f6c3664d | 726 | class VimeoChannelIE(VimeoBaseInfoExtractor): |
9148eb00 | 727 | IE_NAME = 'vimeo:channel' |
3946864c | 728 | _VALID_URL = r'https://vimeo\.com/channels/(?P<id>[^/?#]+)/?(?:$|[?#])' |
caeefc29 | 729 | _MORE_PAGES_INDICATOR = r'<a.+?rel="next"' |
84458766 | 730 | _TITLE = None |
55a10eab | 731 | _TITLE_RE = r'<link rel="alternate"[^>]+?title="(.*?)"' |
2929b3e7 | 732 | _TESTS = [{ |
3946864c | 733 | 'url': 'https://vimeo.com/channels/tributes', |
2929b3e7 | 734 | 'info_dict': { |
a3fa5da4 | 735 | 'id': 'tributes', |
2929b3e7 PH |
736 | 'title': 'Vimeo Tributes', |
737 | }, | |
738 | 'playlist_mincount': 25, | |
739 | }] | |
caeefc29 | 740 | |
5cc14c2f JMF |
741 | def _page_url(self, base_url, pagenum): |
742 | return '%s/videos/page:%d/' % (base_url, pagenum) | |
743 | ||
fb30ec22 | 744 | def _extract_list_title(self, webpage): |
84458766 | 745 | return self._TITLE or self._html_search_regex(self._TITLE_RE, webpage, 'list title') |
fb30ec22 | 746 | |
bf8f082a PH |
747 | def _login_list_password(self, page_url, list_id, webpage): |
748 | login_form = self._search_regex( | |
749 | r'(?s)<form[^>]+?id="pw_form"(.*?)</form>', | |
750 | webpage, 'login form', default=None) | |
751 | if not login_form: | |
752 | return webpage | |
753 | ||
d800609c | 754 | password = self._downloader.params.get('videopassword') |
bf8f082a PH |
755 | if password is None: |
756 | raise ExtractorError('This album is protected by a password, use the --video-password option', expected=True) | |
f8da79f8 | 757 | fields = self._hidden_inputs(login_form) |
7c845629 | 758 | token, vuid = self._extract_xsrft_and_vuid(webpage) |
bf8f082a PH |
759 | fields['token'] = token |
760 | fields['password'] = password | |
15707c7e | 761 | post = urlencode_postdata(fields) |
bf8f082a PH |
762 | password_path = self._search_regex( |
763 | r'action="([^"]+)"', login_form, 'password URL') | |
764 | password_url = compat_urlparse.urljoin(page_url, password_path) | |
67dda517 | 765 | password_request = sanitized_Request(password_url, post) |
bf8f082a | 766 | password_request.add_header('Content-type', 'application/x-www-form-urlencoded') |
9eab37dc S |
767 | self._set_vimeo_cookie('vuid', vuid) |
768 | self._set_vimeo_cookie('xsrft', token) | |
bf8f082a PH |
769 | |
770 | return self._download_webpage( | |
771 | password_request, list_id, | |
772 | 'Verifying the password', 'Wrong password') | |
773 | ||
2c94198e | 774 | def _title_and_entries(self, list_id, base_url): |
caeefc29 | 775 | for pagenum in itertools.count(1): |
bf8f082a | 776 | page_url = self._page_url(base_url, pagenum) |
55a10eab | 777 | webpage = self._download_webpage( |
bf8f082a | 778 | page_url, list_id, |
9148eb00 | 779 | 'Downloading page %s' % pagenum) |
bf8f082a PH |
780 | |
781 | if pagenum == 1: | |
782 | webpage = self._login_list_password(page_url, list_id, webpage) | |
2c94198e S |
783 | yield self._extract_list_title(webpage) |
784 | ||
c8e3e097 S |
785 | # Try extracting href first since not all videos are available via |
786 | # short https://vimeo.com/id URL (e.g. https://vimeo.com/channels/tributes/6213729) | |
787 | clips = re.findall( | |
04a3d4d2 | 788 | r'id="clip_(\d+)"[^>]*>\s*<a[^>]+href="(/(?:[^/]+/)*\1)(?:[^>]+\btitle="([^"]+)")?', webpage) |
c8e3e097 | 789 | if clips: |
04a3d4d2 | 790 | for video_id, video_url, video_title in clips: |
c8e3e097 S |
791 | yield self.url_result( |
792 | compat_urlparse.urljoin(base_url, video_url), | |
04a3d4d2 | 793 | VimeoIE.ie_key(), video_id=video_id, video_title=video_title) |
c8e3e097 S |
794 | # More relaxed fallback |
795 | else: | |
796 | for video_id in re.findall(r'id=["\']clip_(\d+)', webpage): | |
797 | yield self.url_result( | |
798 | 'https://vimeo.com/%s' % video_id, | |
799 | VimeoIE.ie_key(), video_id=video_id) | |
bf8f082a | 800 | |
caeefc29 JMF |
801 | if re.search(self._MORE_PAGES_INDICATOR, webpage, re.DOTALL) is None: |
802 | break | |
803 | ||
2c94198e S |
804 | def _extract_videos(self, list_id, base_url): |
805 | title_and_entries = self._title_and_entries(list_id, base_url) | |
806 | list_title = next(title_and_entries) | |
807 | return self.playlist_result(title_and_entries, list_id, list_title) | |
55a10eab JMF |
808 | |
809 | def _real_extract(self, url): | |
810 | mobj = re.match(self._VALID_URL, url) | |
4f3e9430 | 811 | channel_id = mobj.group('id') |
3946864c | 812 | return self._extract_videos(channel_id, 'https://vimeo.com/channels/%s' % channel_id) |
55a10eab JMF |
813 | |
814 | ||
815 | class VimeoUserIE(VimeoChannelIE): | |
9148eb00 | 816 | IE_NAME = 'vimeo:user' |
b29440ae | 817 | _VALID_URL = r'https://vimeo\.com/(?!(?:[0-9]+|watchlater)(?:$|[?#/]))(?P<name>[^/]+)(?:/videos|[#?]|$)' |
55a10eab | 818 | _TITLE_RE = r'<a[^>]+?class="user">([^<>]+?)</a>' |
2929b3e7 | 819 | _TESTS = [{ |
3946864c | 820 | 'url': 'https://vimeo.com/nkistudio/videos', |
2929b3e7 PH |
821 | 'info_dict': { |
822 | 'title': 'Nki', | |
a3fa5da4 | 823 | 'id': 'nkistudio', |
2929b3e7 PH |
824 | }, |
825 | 'playlist_mincount': 66, | |
826 | }] | |
55a10eab JMF |
827 | |
828 | def _real_extract(self, url): | |
829 | mobj = re.match(self._VALID_URL, url) | |
830 | name = mobj.group('name') | |
3946864c | 831 | return self._extract_videos(name, 'https://vimeo.com/%s' % name) |
5cc14c2f JMF |
832 | |
833 | ||
834 | class VimeoAlbumIE(VimeoChannelIE): | |
9148eb00 | 835 | IE_NAME = 'vimeo:album' |
b5eab86c | 836 | _VALID_URL = r'https://vimeo\.com/album/(?P<id>\d+)(?:$|[?#]|/(?!video))' |
5cc14c2f | 837 | _TITLE_RE = r'<header id="page_header">\n\s*<h1>(.*?)</h1>' |
2929b3e7 | 838 | _TESTS = [{ |
d1508cd6 | 839 | 'url': 'https://vimeo.com/album/2632481', |
2929b3e7 | 840 | 'info_dict': { |
a3fa5da4 | 841 | 'id': '2632481', |
2929b3e7 PH |
842 | 'title': 'Staff Favorites: November 2013', |
843 | }, | |
844 | 'playlist_mincount': 13, | |
bf8f082a PH |
845 | }, { |
846 | 'note': 'Password-protected album', | |
847 | 'url': 'https://vimeo.com/album/3253534', | |
848 | 'info_dict': { | |
849 | 'title': 'test', | |
850 | 'id': '3253534', | |
851 | }, | |
852 | 'playlist_count': 1, | |
853 | 'params': { | |
854 | 'videopassword': 'youtube-dl', | |
855 | } | |
b5eab86c S |
856 | }, { |
857 | 'url': 'https://vimeo.com/album/2632481/sort:plays/format:thumbnail', | |
858 | 'only_matching': True, | |
089657ed S |
859 | }, { |
860 | # TODO: respect page number | |
861 | 'url': 'https://vimeo.com/album/2632481/page:2/sort:plays/format:thumbnail', | |
862 | 'only_matching': True, | |
2929b3e7 | 863 | }] |
5cc14c2f JMF |
864 | |
865 | def _page_url(self, base_url, pagenum): | |
866 | return '%s/page:%d/' % (base_url, pagenum) | |
867 | ||
868 | def _real_extract(self, url): | |
bf8f082a | 869 | album_id = self._match_id(url) |
d1508cd6 | 870 | return self._extract_videos(album_id, 'https://vimeo.com/album/%s' % album_id) |
fb30ec22 JMF |
871 | |
872 | ||
873 | class VimeoGroupsIE(VimeoAlbumIE): | |
9148eb00 | 874 | IE_NAME = 'vimeo:group' |
fdb20a27 | 875 | _VALID_URL = r'https://vimeo\.com/groups/(?P<name>[^/]+)(?:/(?!videos?/\d+)|$)' |
2929b3e7 | 876 | _TESTS = [{ |
3946864c | 877 | 'url': 'https://vimeo.com/groups/rolexawards', |
2929b3e7 | 878 | 'info_dict': { |
a3fa5da4 | 879 | 'id': 'rolexawards', |
2929b3e7 PH |
880 | 'title': 'Rolex Awards for Enterprise', |
881 | }, | |
882 | 'playlist_mincount': 73, | |
883 | }] | |
fb30ec22 JMF |
884 | |
885 | def _extract_list_title(self, webpage): | |
886 | return self._og_search_title(webpage) | |
887 | ||
888 | def _real_extract(self, url): | |
889 | mobj = re.match(self._VALID_URL, url) | |
890 | name = mobj.group('name') | |
3946864c | 891 | return self._extract_videos(name, 'https://vimeo.com/groups/%s' % name) |
fcea44c6 PH |
892 | |
893 | ||
531a7496 | 894 | class VimeoReviewIE(VimeoBaseInfoExtractor): |
9148eb00 PH |
895 | IE_NAME = 'vimeo:review' |
896 | IE_DESC = 'Review pages on vimeo' | |
3946864c | 897 | _VALID_URL = r'https://vimeo\.com/[^/]+/review/(?P<id>[^/]+)' |
d36d3f42 | 898 | _TESTS = [{ |
fcea44c6 | 899 | 'url': 'https://vimeo.com/user21297594/review/75524534/3c257a1b5d', |
fcea44c6 PH |
900 | 'md5': 'c507a72f780cacc12b2248bb4006d253', |
901 | 'info_dict': { | |
fc09240e PH |
902 | 'id': '75524534', |
903 | 'ext': 'mp4', | |
fcea44c6 PH |
904 | 'title': "DICK HARDWICK 'Comedian'", |
905 | 'uploader': 'Richard Hardwick', | |
531a7496 | 906 | 'uploader_id': 'user21297594', |
fcea44c6 | 907 | } |
d36d3f42 PH |
908 | }, { |
909 | 'note': 'video player needs Referer', | |
3946864c | 910 | 'url': 'https://vimeo.com/user22258446/review/91613211/13f927e053', |
d36d3f42 PH |
911 | 'md5': '6295fdab8f4bf6a002d058b2c6dce276', |
912 | 'info_dict': { | |
913 | 'id': '91613211', | |
914 | 'ext': 'mp4', | |
9dec9930 | 915 | 'title': 're:(?i)^Death by dogma versus assembling agile . Sander Hoogendoorn', |
d36d3f42 PH |
916 | 'uploader': 'DevWeek Events', |
917 | 'duration': 2773, | |
ec85ded8 | 918 | 'thumbnail': r're:^https?://.*\.jpg$', |
531a7496 | 919 | 'uploader_id': 'user22258446', |
d36d3f42 | 920 | } |
c1ff6e1a YCH |
921 | }, { |
922 | 'note': 'Password protected', | |
923 | 'url': 'https://vimeo.com/user37284429/review/138823582/c4d865efde', | |
924 | 'info_dict': { | |
925 | 'id': '138823582', | |
926 | 'ext': 'mp4', | |
927 | 'title': 'EFFICIENT PICKUP MASTERCLASS MODULE 1', | |
928 | 'uploader': 'TMB', | |
929 | 'uploader_id': 'user37284429', | |
930 | }, | |
931 | 'params': { | |
932 | 'videopassword': 'holygrail', | |
933 | }, | |
a093cfc7 | 934 | 'skip': 'video gone', |
d36d3f42 | 935 | }] |
fcea44c6 | 936 | |
c1ff6e1a YCH |
937 | def _real_initialize(self): |
938 | self._login() | |
939 | ||
940 | def _get_config_url(self, webpage_url, video_id, video_password_verified=False): | |
941 | webpage = self._download_webpage(webpage_url, video_id) | |
d61aa5eb S |
942 | config_url = self._html_search_regex( |
943 | r'data-config-url=(["\'])(?P<url>(?:(?!\1).)+)\1', webpage, | |
944 | 'config URL', default=None, group='url') | |
945 | if not config_url: | |
946 | data = self._parse_json(self._search_regex( | |
947 | r'window\s*=\s*_extend\(window,\s*({.+?})\);', webpage, 'data', | |
948 | default=NO_DEFAULT if video_password_verified else '{}'), video_id) | |
949 | config_url = data.get('vimeo_esi', {}).get('config', {}).get('configUrl') | |
c1ff6e1a YCH |
950 | if config_url is None: |
951 | self._verify_video_password(webpage_url, video_id, webpage) | |
952 | config_url = self._get_config_url( | |
953 | webpage_url, video_id, video_password_verified=True) | |
954 | return config_url | |
955 | ||
fcea44c6 | 956 | def _real_extract(self, url): |
531a7496 | 957 | video_id = self._match_id(url) |
c1ff6e1a YCH |
958 | config_url = self._get_config_url(url, video_id) |
959 | config = self._download_json(config_url, video_id) | |
531a7496 YCH |
960 | info_dict = self._parse_config(config, video_id) |
961 | self._vimeo_sort_formats(info_dict['formats']) | |
962 | info_dict['id'] = video_id | |
963 | return info_dict | |
efb7e119 JMF |
964 | |
965 | ||
f6c3664d | 966 | class VimeoWatchLaterIE(VimeoChannelIE): |
efb7e119 JMF |
967 | IE_NAME = 'vimeo:watchlater' |
968 | IE_DESC = 'Vimeo watch later list, "vimeowatchlater" keyword (requires authentication)' | |
84458766 S |
969 | _VALID_URL = r'https://vimeo\.com/(?:home/)?watchlater|:vimeowatchlater' |
970 | _TITLE = 'Watch Later' | |
efb7e119 | 971 | _LOGIN_REQUIRED = True |
2929b3e7 | 972 | _TESTS = [{ |
84458766 | 973 | 'url': 'https://vimeo.com/watchlater', |
2929b3e7 PH |
974 | 'only_matching': True, |
975 | }] | |
efb7e119 JMF |
976 | |
977 | def _real_initialize(self): | |
978 | self._login() | |
979 | ||
980 | def _page_url(self, base_url, pagenum): | |
981 | url = '%s/page:%d/' % (base_url, pagenum) | |
67dda517 | 982 | request = sanitized_Request(url) |
efb7e119 JMF |
983 | # Set the header to get a partial html page with the ids, |
984 | # the normal page doesn't contain them. | |
985 | request.add_header('X-Requested-With', 'XMLHttpRequest') | |
986 | return request | |
987 | ||
988 | def _real_extract(self, url): | |
84458766 | 989 | return self._extract_videos('watchlater', 'https://vimeo.com/watchlater') |
d6e6a422 PH |
990 | |
991 | ||
992 | class VimeoLikesIE(InfoExtractor): | |
361a965b | 993 | _VALID_URL = r'https://(?:www\.)?vimeo\.com/(?P<id>[^/]+)/likes/?(?:$|[?#]|sort:)' |
d6e6a422 PH |
994 | IE_NAME = 'vimeo:likes' |
995 | IE_DESC = 'Vimeo user likes' | |
361a965b | 996 | _TESTS = [{ |
9c44d242 PH |
997 | 'url': 'https://vimeo.com/user755559/likes/', |
998 | 'playlist_mincount': 293, | |
611c1dd9 | 999 | 'info_dict': { |
a3fa5da4 | 1000 | 'id': 'user755559_likes', |
611c1dd9 S |
1001 | 'description': 'See all the videos urza likes', |
1002 | 'title': 'Videos urza likes', | |
d6e6a422 | 1003 | }, |
361a965b S |
1004 | }, { |
1005 | 'url': 'https://vimeo.com/stormlapse/likes', | |
1006 | 'only_matching': True, | |
1007 | }] | |
d6e6a422 PH |
1008 | |
1009 | def _real_extract(self, url): | |
1010 | user_id = self._match_id(url) | |
9c44d242 PH |
1011 | webpage = self._download_webpage(url, user_id) |
1012 | page_count = self._int( | |
1013 | self._search_regex( | |
1014 | r'''(?x)<li><a\s+href="[^"]+"\s+data-page="([0-9]+)"> | |
1015 | .*?</a></li>\s*<li\s+class="pagination_next"> | |
361a965b | 1016 | ''', webpage, 'page count', default=1), |
9c44d242 PH |
1017 | 'page count', fatal=True) |
1018 | PAGE_SIZE = 12 | |
1019 | title = self._html_search_regex( | |
1020 | r'(?s)<h1>(.+?)</h1>', webpage, 'title', fatal=False) | |
1021 | description = self._html_search_meta('description', webpage) | |
1022 | ||
1023 | def _get_page(idx): | |
361a965b | 1024 | page_url = 'https://vimeo.com/%s/likes/page:%d/sort:date' % ( |
3946864c | 1025 | user_id, idx + 1) |
9c44d242 PH |
1026 | webpage = self._download_webpage( |
1027 | page_url, user_id, | |
1028 | note='Downloading page %d/%d' % (idx + 1, page_count)) | |
1029 | video_list = self._search_regex( | |
1030 | r'(?s)<ol class="js-browse_list[^"]+"[^>]*>(.*?)</ol>', | |
1031 | webpage, 'video content') | |
1032 | paths = re.findall( | |
1033 | r'<li[^>]*>\s*<a\s+href="([^"]+)"', video_list) | |
1034 | for path in paths: | |
1035 | yield { | |
1036 | '_type': 'url', | |
1037 | 'url': compat_urlparse.urljoin(page_url, path), | |
1038 | } | |
1039 | ||
1040 | pl = InAdvancePagedList(_get_page, page_count, PAGE_SIZE) | |
d6e6a422 PH |
1041 | |
1042 | return { | |
9c44d242 | 1043 | '_type': 'playlist', |
361a965b | 1044 | 'id': '%s_likes' % user_id, |
9c44d242 PH |
1045 | 'title': title, |
1046 | 'description': description, | |
1047 | 'entries': pl, | |
d6e6a422 | 1048 | } |