]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/vimeo.py
de4fc61cc3e94e853fff8173283ee8428927a7aa
[yt-dlp.git] / yt_dlp / extractor / vimeo.py
1 import base64
2 import functools
3 import re
4 import itertools
5
6 from .common import InfoExtractor
7 from ..compat import (
8 compat_HTTPError,
9 compat_str,
10 compat_urlparse,
11 )
12 from ..utils import (
13 clean_html,
14 determine_ext,
15 ExtractorError,
16 get_element_by_class,
17 HEADRequest,
18 js_to_json,
19 int_or_none,
20 merge_dicts,
21 OnDemandPagedList,
22 parse_filesize,
23 parse_iso8601,
24 parse_qs,
25 sanitized_Request,
26 smuggle_url,
27 str_or_none,
28 try_get,
29 unified_timestamp,
30 unsmuggle_url,
31 urlencode_postdata,
32 urljoin,
33 unescapeHTML,
34 urlhandle_detect_ext,
35 )
36
37
38 class VimeoBaseInfoExtractor(InfoExtractor):
39 _NETRC_MACHINE = 'vimeo'
40 _LOGIN_REQUIRED = False
41 _LOGIN_URL = 'https://vimeo.com/log_in'
42
43 def _perform_login(self, username, password):
44 webpage = self._download_webpage(
45 self._LOGIN_URL, None, 'Downloading login page')
46 token, vuid = self._extract_xsrft_and_vuid(webpage)
47 data = {
48 'action': 'login',
49 'email': username,
50 'password': password,
51 'service': 'vimeo',
52 'token': token,
53 }
54 self._set_vimeo_cookie('vuid', vuid)
55 try:
56 self._download_webpage(
57 self._LOGIN_URL, None, 'Logging in',
58 data=urlencode_postdata(data), headers={
59 'Content-Type': 'application/x-www-form-urlencoded',
60 'Referer': self._LOGIN_URL,
61 })
62 except ExtractorError as e:
63 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 418:
64 raise ExtractorError(
65 'Unable to log in: bad username or password',
66 expected=True)
67 raise ExtractorError('Unable to log in')
68
69 def _real_initialize(self):
70 if self._LOGIN_REQUIRED and not self._get_cookies('https://vimeo.com').get('vuid'):
71 self._raise_login_required()
72
73 def _get_video_password(self):
74 password = self.get_param('videopassword')
75 if password is None:
76 raise ExtractorError(
77 'This video is protected by a password, use the --video-password option',
78 expected=True)
79 return password
80
81 def _verify_video_password(self, url, video_id, password, token, vuid):
82 if url.startswith('http://'):
83 # vimeo only supports https now, but the user can give an http url
84 url = url.replace('http://', 'https://')
85 self._set_vimeo_cookie('vuid', vuid)
86 return self._download_webpage(
87 url + '/password', video_id, 'Verifying the password',
88 'Wrong password', data=urlencode_postdata({
89 'password': password,
90 'token': token,
91 }), headers={
92 'Content-Type': 'application/x-www-form-urlencoded',
93 'Referer': url,
94 })
95
96 def _extract_xsrft_and_vuid(self, webpage):
97 xsrft = self._search_regex(
98 r'(?:(?P<q1>["\'])xsrft(?P=q1)\s*:|xsrft\s*[=:])\s*(?P<q>["\'])(?P<xsrft>.+?)(?P=q)',
99 webpage, 'login token', group='xsrft')
100 vuid = self._search_regex(
101 r'["\']vuid["\']\s*:\s*(["\'])(?P<vuid>.+?)\1',
102 webpage, 'vuid', group='vuid')
103 return xsrft, vuid
104
105 def _extract_vimeo_config(self, webpage, video_id, *args, **kwargs):
106 vimeo_config = self._search_regex(
107 r'vimeo\.config\s*=\s*(?:({.+?})|_extend\([^,]+,\s+({.+?})\));',
108 webpage, 'vimeo config', *args, **kwargs)
109 if vimeo_config:
110 return self._parse_json(vimeo_config, video_id)
111
112 def _set_vimeo_cookie(self, name, value):
113 self._set_cookie('vimeo.com', name, value)
114
115 def _vimeo_sort_formats(self, formats):
116 # Note: Bitrates are completely broken. Single m3u8 may contain entries in kbps and bps
117 # at the same time without actual units specified.
118 self._sort_formats(formats, ('quality', 'res', 'fps', 'hdr:12', 'source'))
119
120 def _parse_config(self, config, video_id):
121 video_data = config['video']
122 video_title = video_data['title']
123 live_event = video_data.get('live_event') or {}
124 is_live = live_event.get('status') == 'started'
125 request = config.get('request') or {}
126
127 formats = []
128 subtitles = {}
129
130 config_files = video_data.get('files') or request.get('files') or {}
131 for f in (config_files.get('progressive') or []):
132 video_url = f.get('url')
133 if not video_url:
134 continue
135 formats.append({
136 'url': video_url,
137 'format_id': 'http-%s' % f.get('quality'),
138 'source_preference': 10,
139 'width': int_or_none(f.get('width')),
140 'height': int_or_none(f.get('height')),
141 'fps': int_or_none(f.get('fps')),
142 'tbr': int_or_none(f.get('bitrate')),
143 })
144
145 # TODO: fix handling of 308 status code returned for live archive manifest requests
146 sep_pattern = r'/sep/video/'
147 for files_type in ('hls', 'dash'):
148 for cdn_name, cdn_data in (try_get(config_files, lambda x: x[files_type]['cdns']) or {}).items():
149 manifest_url = cdn_data.get('url')
150 if not manifest_url:
151 continue
152 format_id = '%s-%s' % (files_type, cdn_name)
153 sep_manifest_urls = []
154 if re.search(sep_pattern, manifest_url):
155 for suffix, repl in (('', 'video'), ('_sep', 'sep/video')):
156 sep_manifest_urls.append((format_id + suffix, re.sub(
157 sep_pattern, '/%s/' % repl, manifest_url)))
158 else:
159 sep_manifest_urls = [(format_id, manifest_url)]
160 for f_id, m_url in sep_manifest_urls:
161 if files_type == 'hls':
162 fmts, subs = self._extract_m3u8_formats_and_subtitles(
163 m_url, video_id, 'mp4', live=is_live, m3u8_id=f_id,
164 note='Downloading %s m3u8 information' % cdn_name,
165 fatal=False)
166 formats.extend(fmts)
167 self._merge_subtitles(subs, target=subtitles)
168 elif files_type == 'dash':
169 if 'json=1' in m_url:
170 real_m_url = (self._download_json(m_url, video_id, fatal=False) or {}).get('url')
171 if real_m_url:
172 m_url = real_m_url
173 fmts, subs = self._extract_mpd_formats_and_subtitles(
174 m_url.replace('/master.json', '/master.mpd'), video_id, f_id,
175 'Downloading %s MPD information' % cdn_name,
176 fatal=False)
177 formats.extend(fmts)
178 self._merge_subtitles(subs, target=subtitles)
179
180 live_archive = live_event.get('archive') or {}
181 live_archive_source_url = live_archive.get('source_url')
182 if live_archive_source_url and live_archive.get('status') == 'done':
183 formats.append({
184 'format_id': 'live-archive-source',
185 'url': live_archive_source_url,
186 'quality': 10,
187 })
188
189 for tt in (request.get('text_tracks') or []):
190 subtitles.setdefault(tt['lang'], []).append({
191 'ext': 'vtt',
192 'url': urljoin('https://vimeo.com', tt['url']),
193 })
194
195 thumbnails = []
196 if not is_live:
197 for key, thumb in (video_data.get('thumbs') or {}).items():
198 thumbnails.append({
199 'id': key,
200 'width': int_or_none(key),
201 'url': thumb,
202 })
203 thumbnail = video_data.get('thumbnail')
204 if thumbnail:
205 thumbnails.append({
206 'url': thumbnail,
207 })
208
209 owner = video_data.get('owner') or {}
210 video_uploader_url = owner.get('url')
211
212 duration = int_or_none(video_data.get('duration'))
213 chapter_data = try_get(config, lambda x: x['embed']['chapters']) or []
214 chapters = [{
215 'title': current_chapter.get('title'),
216 'start_time': current_chapter.get('timecode'),
217 'end_time': next_chapter.get('timecode'),
218 } for current_chapter, next_chapter in zip(chapter_data, chapter_data[1:] + [{'timecode': duration}])]
219 if chapters and chapters[0]['start_time']: # Chapters may not start from 0
220 chapters[:0] = [{'title': '<Untitled>', 'start_time': 0, 'end_time': chapters[0]['start_time']}]
221
222 return {
223 'id': str_or_none(video_data.get('id')) or video_id,
224 'title': video_title,
225 'uploader': owner.get('name'),
226 'uploader_id': video_uploader_url.split('/')[-1] if video_uploader_url else None,
227 'uploader_url': video_uploader_url,
228 'thumbnails': thumbnails,
229 'duration': duration,
230 'chapters': chapters or None,
231 'formats': formats,
232 'subtitles': subtitles,
233 'is_live': is_live,
234 }
235
236 def _extract_original_format(self, url, video_id, unlisted_hash=None):
237 query = {'action': 'load_download_config'}
238 if unlisted_hash:
239 query['unlisted_hash'] = unlisted_hash
240 download_data = self._download_json(
241 url, video_id, fatal=False, query=query,
242 headers={'X-Requested-With': 'XMLHttpRequest'},
243 expected_status=(403, 404)) or {}
244 source_file = download_data.get('source_file')
245 download_url = try_get(source_file, lambda x: x['download_url'])
246 if download_url and not source_file.get('is_cold') and not source_file.get('is_defrosting'):
247 source_name = source_file.get('public_name', 'Original')
248 if self._is_valid_url(download_url, video_id, '%s video' % source_name):
249 ext = (try_get(
250 source_file, lambda x: x['extension'],
251 compat_str) or determine_ext(
252 download_url, None) or 'mp4').lower()
253 return {
254 'url': download_url,
255 'ext': ext,
256 'width': int_or_none(source_file.get('width')),
257 'height': int_or_none(source_file.get('height')),
258 'filesize': parse_filesize(source_file.get('size')),
259 'format_id': source_name,
260 'quality': 1,
261 }
262
263 jwt_response = self._download_json(
264 'https://vimeo.com/_rv/viewer', video_id, note='Downloading jwt token', fatal=False) or {}
265 if not jwt_response.get('jwt'):
266 return
267 headers = {'Authorization': 'jwt %s' % jwt_response['jwt']}
268 original_response = self._download_json(
269 f'https://api.vimeo.com/videos/{video_id}', video_id,
270 headers=headers, fatal=False, expected_status=(403, 404)) or {}
271 for download_data in original_response.get('download') or []:
272 download_url = download_data.get('link')
273 if not download_url or download_data.get('quality') != 'source':
274 continue
275 ext = determine_ext(parse_qs(download_url).get('filename', [''])[0].lower(), default_ext=None)
276 if not ext:
277 urlh = self._request_webpage(
278 HEADRequest(download_url), video_id, fatal=False, note='Determining source extension')
279 ext = urlh and urlhandle_detect_ext(urlh)
280 return {
281 'url': download_url,
282 'ext': ext or 'unknown_video',
283 'format_id': download_data.get('public_name', 'Original'),
284 'width': int_or_none(download_data.get('width')),
285 'height': int_or_none(download_data.get('height')),
286 'fps': int_or_none(download_data.get('fps')),
287 'filesize': int_or_none(download_data.get('size')),
288 'quality': 1,
289 }
290
291
292 class VimeoIE(VimeoBaseInfoExtractor):
293 """Information extractor for vimeo.com."""
294
295 # _VALID_URL matches Vimeo URLs
296 _VALID_URL = r'''(?x)
297 https?://
298 (?:
299 (?:
300 www|
301 player
302 )
303 \.
304 )?
305 vimeo(?:pro)?\.com/
306 (?!(?:channels|album|showcase)/[^/?#]+/?(?:$|[?#])|[^/]+/review/|ondemand/)
307 (?:[^/]+/)*?
308 (?:
309 (?:
310 play_redirect_hls|
311 moogaloop\.swf)\?clip_id=
312 )?
313 (?:videos?/)?
314 (?P<id>[0-9]+)
315 (?:/(?P<unlisted_hash>[\da-f]{10}))?
316 /?(?:[?&].*)?(?:[#].*)?$
317 '''
318 IE_NAME = 'vimeo'
319 _TESTS = [
320 {
321 'url': 'http://vimeo.com/56015672#at=0',
322 'md5': '8879b6cc097e987f02484baf890129e5',
323 'info_dict': {
324 'id': '56015672',
325 'ext': 'mp4',
326 'title': "youtube-dl test video '' ä↭𝕐-BaW jenozKc",
327 'description': 'md5:2d3305bad981a06ff79f027f19865021',
328 'timestamp': 1355990239,
329 'upload_date': '20121220',
330 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/user7108434',
331 'uploader_id': 'user7108434',
332 'uploader': 'Filippo Valsorda',
333 'duration': 10,
334 'license': 'by-sa',
335 },
336 'params': {
337 'format': 'best[protocol=https]',
338 },
339 'skip': 'No longer available'
340 },
341 {
342 'url': 'http://vimeopro.com/openstreetmapus/state-of-the-map-us-2013/video/68093876',
343 'md5': '3b5ca6aa22b60dfeeadf50b72e44ed82',
344 'note': 'Vimeo Pro video (#1197)',
345 'info_dict': {
346 'id': '68093876',
347 'ext': 'mp4',
348 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/openstreetmapus',
349 'uploader_id': 'openstreetmapus',
350 'uploader': 'OpenStreetMap US',
351 'title': 'Andy Allan - Putting the Carto into OpenStreetMap Cartography',
352 'description': 'md5:2c362968038d4499f4d79f88458590c1',
353 'duration': 1595,
354 'upload_date': '20130610',
355 'timestamp': 1370893156,
356 'license': 'by',
357 'thumbnail': 'https://i.vimeocdn.com/video/440260469-19b0d92fca3bd84066623b53f1eb8aaa3980c6c809e2d67b6b39ab7b4a77a344-d_960',
358 'view_count': int,
359 'comment_count': int,
360 'like_count': int,
361 },
362 'params': {
363 'format': 'best[protocol=https]',
364 },
365 },
366 {
367 'url': 'http://player.vimeo.com/video/54469442',
368 'md5': 'b3e7f4d2cbb53bd7dc3bb6ff4ed5cfbd',
369 'note': 'Videos that embed the url in the player page',
370 'info_dict': {
371 'id': '54469442',
372 'ext': 'mp4',
373 'title': 'Kathy Sierra: Building the minimum Badass User, Business of Software 2012',
374 'uploader': 'Business of Software',
375 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/businessofsoftware',
376 'uploader_id': 'businessofsoftware',
377 'duration': 3610,
378 'description': None,
379 'thumbnail': 'https://i.vimeocdn.com/video/376682406-f34043e7b766af6bef2af81366eacd6724f3fc3173179a11a97a1e26587c9529-d_1280',
380 },
381 'params': {
382 'format': 'best[protocol=https]',
383 },
384 },
385 {
386 'url': 'http://vimeo.com/68375962',
387 'md5': 'aaf896bdb7ddd6476df50007a0ac0ae7',
388 'note': 'Video protected with password',
389 'info_dict': {
390 'id': '68375962',
391 'ext': 'mp4',
392 'title': 'youtube-dl password protected test video',
393 'timestamp': 1371200155,
394 'upload_date': '20130614',
395 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/user18948128',
396 'uploader_id': 'user18948128',
397 'uploader': 'Jaime Marquínez Ferrándiz',
398 'duration': 10,
399 'description': 'md5:dca3ea23adb29ee387127bc4ddfce63f',
400 'thumbnail': 'https://i.vimeocdn.com/video/440665496-b2c5aee2b61089442c794f64113a8e8f7d5763c3e6b3ebfaf696ae6413f8b1f4-d_960',
401 'view_count': int,
402 'comment_count': int,
403 'like_count': int,
404 },
405 'params': {
406 'format': 'best[protocol=https]',
407 'videopassword': 'youtube-dl',
408 },
409 },
410 {
411 'url': 'http://vimeo.com/channels/keypeele/75629013',
412 'md5': '2f86a05afe9d7abc0b9126d229bbe15d',
413 'info_dict': {
414 'id': '75629013',
415 'ext': 'mp4',
416 'title': 'Key & Peele: Terrorist Interrogation',
417 'description': 'md5:8678b246399b070816b12313e8b4eb5c',
418 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/atencio',
419 'uploader_id': 'atencio',
420 'uploader': 'Peter Atencio',
421 'channel_id': 'keypeele',
422 'channel_url': r're:https?://(?:www\.)?vimeo\.com/channels/keypeele',
423 'timestamp': 1380339469,
424 'upload_date': '20130928',
425 'duration': 187,
426 'thumbnail': 'https://i.vimeocdn.com/video/450239872-a05512d9b1e55d707a7c04365c10980f327b06d966351bc403a5d5d65c95e572-d_1280',
427 'view_count': int,
428 'comment_count': int,
429 'like_count': int,
430 },
431 'params': {'format': 'http-1080p'},
432 },
433 {
434 'url': 'http://vimeo.com/76979871',
435 'note': 'Video with subtitles',
436 'info_dict': {
437 'id': '76979871',
438 'ext': 'mov',
439 'title': 'The New Vimeo Player (You Know, For Videos)',
440 'description': 'md5:2ec900bf97c3f389378a96aee11260ea',
441 'timestamp': 1381846109,
442 'upload_date': '20131015',
443 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/staff',
444 'uploader_id': 'staff',
445 'uploader': 'Vimeo Staff',
446 'duration': 62,
447 'subtitles': {
448 'de': [{'ext': 'vtt'}],
449 'en': [{'ext': 'vtt'}],
450 'es': [{'ext': 'vtt'}],
451 'fr': [{'ext': 'vtt'}],
452 },
453 },
454 'expected_warnings': ['Ignoring subtitle tracks found in the HLS manifest'],
455 },
456 {
457 # from https://www.ouya.tv/game/Pier-Solar-and-the-Great-Architects/
458 'url': 'https://player.vimeo.com/video/98044508',
459 'note': 'The js code contains assignments to the same variable as the config',
460 'info_dict': {
461 'id': '98044508',
462 'ext': 'mp4',
463 'title': 'Pier Solar OUYA Official Trailer',
464 'uploader': 'Tulio Gonçalves',
465 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/user28849593',
466 'uploader_id': 'user28849593',
467 'duration': 118,
468 'thumbnail': 'https://i.vimeocdn.com/video/478636036-c18440305ef3df9decfb6bf207a61fe39d2d17fa462a96f6f2d93d30492b037d-d_1280',
469 },
470 },
471 {
472 # contains original format
473 'url': 'https://vimeo.com/33951933',
474 'md5': '53c688fa95a55bf4b7293d37a89c5c53',
475 'info_dict': {
476 'id': '33951933',
477 'ext': 'mp4',
478 'title': 'FOX CLASSICS - Forever Classic ID - A Full Minute',
479 'uploader': 'The DMCI',
480 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/dmci',
481 'uploader_id': 'dmci',
482 'timestamp': 1324343742,
483 'upload_date': '20111220',
484 'description': 'md5:ae23671e82d05415868f7ad1aec21147',
485 'duration': 60,
486 'comment_count': int,
487 'view_count': int,
488 'thumbnail': 'https://i.vimeocdn.com/video/231174622-dd07f015e9221ff529d451e1cc31c982b5d87bfafa48c4189b1da72824ee289a-d_1280',
489 'like_count': int,
490 },
491 },
492 {
493 'note': 'Contains original format not accessible in webpage',
494 'url': 'https://vimeo.com/393756517',
495 'md5': 'c464af248b592190a5ffbb5d33f382b0',
496 'info_dict': {
497 'id': '393756517',
498 'ext': 'mov',
499 'timestamp': 1582642091,
500 'uploader_id': 'frameworkla',
501 'title': 'Straight To Hell - Sabrina: Netflix',
502 'uploader': 'Framework Studio',
503 'description': 'md5:f2edc61af3ea7a5592681ddbb683db73',
504 'upload_date': '20200225',
505 'duration': 176,
506 'thumbnail': 'https://i.vimeocdn.com/video/859377297-836494a4ef775e9d4edbace83937d9ad34dc846c688c0c419c0e87f7ab06c4b3-d_1280',
507 'uploader_url': 'https://vimeo.com/frameworkla',
508 },
509 },
510 {
511 # only available via https://vimeo.com/channels/tributes/6213729 and
512 # not via https://vimeo.com/6213729
513 'url': 'https://vimeo.com/channels/tributes/6213729',
514 'info_dict': {
515 'id': '6213729',
516 'ext': 'mp4',
517 'title': 'Vimeo Tribute: The Shining',
518 'uploader': 'Casey Donahue',
519 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/caseydonahue',
520 'uploader_id': 'caseydonahue',
521 'channel_url': r're:https?://(?:www\.)?vimeo\.com/channels/tributes',
522 'channel_id': 'tributes',
523 'timestamp': 1250886430,
524 'upload_date': '20090821',
525 'description': 'md5:bdbf314014e58713e6e5b66eb252f4a6',
526 'duration': 321,
527 'comment_count': int,
528 'view_count': int,
529 'thumbnail': 'https://i.vimeocdn.com/video/22728298-bfc22146f930de7cf497821c7b0b9f168099201ecca39b00b6bd31fcedfca7a6-d_1280',
530 'like_count': int,
531 },
532 'params': {
533 'skip_download': True,
534 },
535 },
536 {
537 # redirects to ondemand extractor and should be passed through it
538 # for successful extraction
539 'url': 'https://vimeo.com/73445910',
540 'info_dict': {
541 'id': '73445910',
542 'ext': 'mp4',
543 'title': 'The Reluctant Revolutionary',
544 'uploader': '10Ft Films',
545 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/tenfootfilms',
546 'uploader_id': 'tenfootfilms',
547 'description': 'md5:0fa704e05b04f91f40b7f3ca2e801384',
548 'upload_date': '20130830',
549 'timestamp': 1377853339,
550 },
551 'params': {
552 'skip_download': True,
553 },
554 'skip': 'this page is no longer available.',
555 },
556 {
557 'url': 'http://player.vimeo.com/video/68375962',
558 'md5': 'aaf896bdb7ddd6476df50007a0ac0ae7',
559 'info_dict': {
560 'id': '68375962',
561 'ext': 'mp4',
562 'title': 'youtube-dl password protected test video',
563 'timestamp': 1371200155,
564 'upload_date': '20130614',
565 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/user18948128',
566 'uploader_id': 'user18948128',
567 'uploader': 'Jaime Marquínez Ferrándiz',
568 'duration': 10,
569 'description': 'md5:dca3ea23adb29ee387127bc4ddfce63f',
570 'thumbnail': 'https://i.vimeocdn.com/video/440665496-b2c5aee2b61089442c794f64113a8e8f7d5763c3e6b3ebfaf696ae6413f8b1f4-d_960',
571 'view_count': int,
572 'comment_count': int,
573 'like_count': int,
574 },
575 'params': {
576 'format': 'best[protocol=https]',
577 'videopassword': 'youtube-dl',
578 },
579 },
580 {
581 'url': 'http://vimeo.com/moogaloop.swf?clip_id=2539741',
582 'only_matching': True,
583 },
584 {
585 'url': 'https://vimeo.com/109815029',
586 'note': 'Video not completely processed, "failed" seed status',
587 'only_matching': True,
588 },
589 {
590 'url': 'https://vimeo.com/groups/travelhd/videos/22439234',
591 'only_matching': True,
592 },
593 {
594 'url': 'https://vimeo.com/album/2632481/video/79010983',
595 'only_matching': True,
596 },
597 {
598 'url': 'https://vimeo.com/showcase/3253534/video/119195465',
599 'note': 'A video in a password protected album (showcase)',
600 'info_dict': {
601 'id': '119195465',
602 'ext': 'mp4',
603 'title': "youtube-dl test video '' ä↭𝕐-BaW jenozKc",
604 'uploader': 'Philipp Hagemeister',
605 'uploader_id': 'user20132939',
606 'description': 'md5:fa7b6c6d8db0bdc353893df2f111855b',
607 'upload_date': '20150209',
608 'timestamp': 1423518307,
609 'thumbnail': 'https://i.vimeocdn.com/video/default_1280',
610 'duration': 10,
611 'like_count': int,
612 'uploader_url': 'https://vimeo.com/user20132939',
613 'view_count': int,
614 'comment_count': int,
615 },
616 'params': {
617 'format': 'best[protocol=https]',
618 'videopassword': 'youtube-dl',
619 },
620 },
621 {
622 # source file returns 403: Forbidden
623 'url': 'https://vimeo.com/7809605',
624 'only_matching': True,
625 },
626 {
627 'note': 'Direct URL with hash',
628 'url': 'https://vimeo.com/160743502/abd0e13fb4',
629 'info_dict': {
630 'id': '160743502',
631 'ext': 'mp4',
632 'uploader': 'Julian Tryba',
633 'uploader_id': 'aliniamedia',
634 'title': 'Harrisville New Hampshire',
635 'timestamp': 1459259666,
636 'upload_date': '20160329',
637 'release_timestamp': 1459259666,
638 'license': 'by-nc',
639 'duration': 159,
640 'comment_count': int,
641 'thumbnail': 'https://i.vimeocdn.com/video/562802436-585eeb13b5020c6ac0f171a2234067938098f84737787df05ff0d767f6d54ee9-d_1280',
642 'like_count': int,
643 'uploader_url': 'https://vimeo.com/aliniamedia',
644 'release_date': '20160329',
645 },
646 'params': {'skip_download': True},
647 },
648 {
649 'url': 'https://vimeo.com/138909882',
650 'info_dict': {
651 'id': '138909882',
652 'ext': 'mp4',
653 'title': 'Eastnor Castle 2015 Firework Champions - The Promo!',
654 'description': 'md5:5967e090768a831488f6e74b7821b3c1',
655 'uploader_id': 'fireworkchampions',
656 'uploader': 'Firework Champions',
657 'upload_date': '20150910',
658 'timestamp': 1441901895,
659 },
660 'params': {
661 'skip_download': True,
662 'format': 'Original',
663 },
664 },
665 {
666 'url': 'https://vimeo.com/channels/staffpicks/143603739',
667 'info_dict': {
668 'id': '143603739',
669 'ext': 'mp4',
670 'uploader': 'Karim Huu Do',
671 'timestamp': 1445846953,
672 'upload_date': '20151026',
673 'title': 'The Shoes - Submarine Feat. Blaine Harrison',
674 'uploader_id': 'karimhd',
675 'description': 'md5:8e2eea76de4504c2e8020a9bcfa1e843',
676 'channel_id': 'staffpicks',
677 'duration': 336,
678 'comment_count': int,
679 'view_count': int,
680 'thumbnail': 'https://i.vimeocdn.com/video/541243181-b593db36a16db2f0096f655da3f5a4dc46b8766d77b0f440df937ecb0c418347-d_1280',
681 'like_count': int,
682 'uploader_url': 'https://vimeo.com/karimhd',
683 'channel_url': 'https://vimeo.com/channels/staffpicks',
684 },
685 'params': {'skip_download': 'm3u8'},
686 },
687 {
688 # requires passing unlisted_hash(a52724358e) to load_download_config request
689 'url': 'https://vimeo.com/392479337/a52724358e',
690 'only_matching': True,
691 },
692 {
693 # similar, but all numeric: ID must be 581039021, not 9603038895
694 # issue #29690
695 'url': 'https://vimeo.com/581039021/9603038895',
696 'info_dict': {
697 'id': '581039021',
698 'ext': 'mp4',
699 'timestamp': 1627621014,
700 'release_timestamp': 1627621014,
701 'duration': 976,
702 'comment_count': int,
703 'thumbnail': 'https://i.vimeocdn.com/video/1202249320-4ddb2c30398c0dc0ee059172d1bd5ea481ad12f0e0e3ad01d2266f56c744b015-d_1280',
704 'like_count': int,
705 'uploader_url': 'https://vimeo.com/txwestcapital',
706 'release_date': '20210730',
707 'uploader': 'Christopher Inks',
708 'title': 'Thursday, July 29, 2021 BMA Evening Video Update',
709 'uploader_id': 'txwestcapital',
710 'upload_date': '20210730',
711 },
712 'params': {
713 'skip_download': True,
714 },
715 }
716 # https://gettingthingsdone.com/workflowmap/
717 # vimeo embed with check-password page protected by Referer header
718 ]
719
720 @staticmethod
721 def _smuggle_referrer(url, referrer_url):
722 return smuggle_url(url, {'http_headers': {'Referer': referrer_url}})
723
724 @staticmethod
725 def _extract_urls(url, webpage):
726 urls = []
727 # Look for embedded (iframe) Vimeo player
728 for mobj in re.finditer(
729 r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/\d+.*?)\1',
730 webpage):
731 urls.append(VimeoIE._smuggle_referrer(unescapeHTML(mobj.group('url')), url))
732 PLAIN_EMBED_RE = (
733 # Look for embedded (swf embed) Vimeo player
734 r'<embed[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?vimeo\.com/moogaloop\.swf.+?)\1',
735 # Look more for non-standard embedded Vimeo player
736 r'<video[^>]+src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?vimeo\.com/[0-9]+)\1',
737 )
738 for embed_re in PLAIN_EMBED_RE:
739 for mobj in re.finditer(embed_re, webpage):
740 urls.append(mobj.group('url'))
741 return urls
742
743 @staticmethod
744 def _extract_url(url, webpage):
745 urls = VimeoIE._extract_urls(url, webpage)
746 return urls[0] if urls else None
747
748 def _verify_player_video_password(self, url, video_id, headers):
749 password = self._get_video_password()
750 data = urlencode_postdata({
751 'password': base64.b64encode(password.encode()),
752 })
753 headers = merge_dicts(headers, {
754 'Content-Type': 'application/x-www-form-urlencoded',
755 })
756 checked = self._download_json(
757 url + '/check-password', video_id,
758 'Verifying the password', data=data, headers=headers)
759 if checked is False:
760 raise ExtractorError('Wrong video password', expected=True)
761 return checked
762
763 def _extract_from_api(self, video_id, unlisted_hash=None):
764 token = self._download_json(
765 'https://vimeo.com/_rv/jwt', video_id, headers={
766 'X-Requested-With': 'XMLHttpRequest'
767 })['token']
768 api_url = 'https://api.vimeo.com/videos/' + video_id
769 if unlisted_hash:
770 api_url += ':' + unlisted_hash
771 video = self._download_json(
772 api_url, video_id, headers={
773 'Authorization': 'jwt ' + token,
774 }, query={
775 'fields': 'config_url,created_time,description,license,metadata.connections.comments.total,metadata.connections.likes.total,release_time,stats.plays',
776 })
777 info = self._parse_config(self._download_json(
778 video['config_url'], video_id), video_id)
779 self._vimeo_sort_formats(info['formats'])
780 get_timestamp = lambda x: parse_iso8601(video.get(x + '_time'))
781 info.update({
782 'description': video.get('description'),
783 'license': video.get('license'),
784 'release_timestamp': get_timestamp('release'),
785 'timestamp': get_timestamp('created'),
786 'view_count': int_or_none(try_get(video, lambda x: x['stats']['plays'])),
787 })
788 connections = try_get(
789 video, lambda x: x['metadata']['connections'], dict) or {}
790 for k in ('comment', 'like'):
791 info[k + '_count'] = int_or_none(try_get(connections, lambda x: x[k + 's']['total']))
792 return info
793
794 def _try_album_password(self, url):
795 album_id = self._search_regex(
796 r'vimeo\.com/(?:album|showcase)/([^/]+)', url, 'album id', default=None)
797 if not album_id:
798 return
799 viewer = self._download_json(
800 'https://vimeo.com/_rv/viewer', album_id, fatal=False)
801 if not viewer:
802 webpage = self._download_webpage(url, album_id)
803 viewer = self._parse_json(self._search_regex(
804 r'bootstrap_data\s*=\s*({.+?})</script>',
805 webpage, 'bootstrap data'), album_id)['viewer']
806 jwt = viewer['jwt']
807 album = self._download_json(
808 'https://api.vimeo.com/albums/' + album_id,
809 album_id, headers={'Authorization': 'jwt ' + jwt},
810 query={'fields': 'description,name,privacy'})
811 if try_get(album, lambda x: x['privacy']['view']) == 'password':
812 password = self.get_param('videopassword')
813 if not password:
814 raise ExtractorError(
815 'This album is protected by a password, use the --video-password option',
816 expected=True)
817 self._set_vimeo_cookie('vuid', viewer['vuid'])
818 try:
819 self._download_json(
820 'https://vimeo.com/showcase/%s/auth' % album_id,
821 album_id, 'Verifying the password', data=urlencode_postdata({
822 'password': password,
823 'token': viewer['xsrft'],
824 }), headers={
825 'X-Requested-With': 'XMLHttpRequest',
826 })
827 except ExtractorError as e:
828 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 401:
829 raise ExtractorError('Wrong password', expected=True)
830 raise
831
832 def _real_extract(self, url):
833 url, data = unsmuggle_url(url, {})
834 headers = self.get_param('http_headers').copy()
835 if 'http_headers' in data:
836 headers.update(data['http_headers'])
837 if 'Referer' not in headers:
838 headers['Referer'] = url
839
840 # Extract ID from URL
841 mobj = self._match_valid_url(url).groupdict()
842 video_id, unlisted_hash = mobj['id'], mobj.get('unlisted_hash')
843 if unlisted_hash:
844 return self._extract_from_api(video_id, unlisted_hash)
845
846 orig_url = url
847 is_pro = 'vimeopro.com/' in url
848 if is_pro:
849 # some videos require portfolio_id to be present in player url
850 # https://github.com/ytdl-org/youtube-dl/issues/20070
851 url = self._extract_url(url, self._download_webpage(url, video_id))
852 if not url:
853 url = 'https://vimeo.com/' + video_id
854 elif any(p in url for p in ('play_redirect_hls', 'moogaloop.swf')):
855 url = 'https://vimeo.com/' + video_id
856
857 self._try_album_password(url)
858 try:
859 # Retrieve video webpage to extract further information
860 webpage, urlh = self._download_webpage_handle(
861 url, video_id, headers=headers)
862 redirect_url = urlh.geturl()
863 except ExtractorError as ee:
864 if isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 403:
865 errmsg = ee.cause.read()
866 if b'Because of its privacy settings, this video cannot be played here' in errmsg:
867 raise ExtractorError(
868 'Cannot download embed-only video without embedding '
869 'URL. Please call yt-dlp with the URL of the page '
870 'that embeds this video.',
871 expected=True)
872 raise
873
874 if '://player.vimeo.com/video/' in url:
875 config = self._parse_json(self._search_regex(
876 r'\bconfig\s*=\s*({.+?})\s*;', webpage, 'info section'), video_id)
877 if config.get('view') == 4:
878 config = self._verify_player_video_password(
879 redirect_url, video_id, headers)
880 info = self._parse_config(config, video_id)
881 self._vimeo_sort_formats(info['formats'])
882 return info
883
884 if re.search(r'<form[^>]+?id="pw_form"', webpage):
885 video_password = self._get_video_password()
886 token, vuid = self._extract_xsrft_and_vuid(webpage)
887 webpage = self._verify_video_password(
888 redirect_url, video_id, video_password, token, vuid)
889
890 vimeo_config = self._extract_vimeo_config(webpage, video_id, default=None)
891 if vimeo_config:
892 seed_status = vimeo_config.get('seed_status') or {}
893 if seed_status.get('state') == 'failed':
894 raise ExtractorError(
895 '%s said: %s' % (self.IE_NAME, seed_status['title']),
896 expected=True)
897
898 cc_license = None
899 timestamp = None
900 video_description = None
901 info_dict = {}
902 config_url = None
903
904 channel_id = self._search_regex(
905 r'vimeo\.com/channels/([^/]+)', url, 'channel id', default=None)
906 if channel_id:
907 config_url = self._html_search_regex(
908 r'\bdata-config-url="([^"]+)"', webpage, 'config URL', default=None)
909 video_description = clean_html(get_element_by_class('description', webpage))
910 info_dict.update({
911 'channel_id': channel_id,
912 'channel_url': 'https://vimeo.com/channels/' + channel_id,
913 })
914 if not config_url:
915 page_config = self._parse_json(self._search_regex(
916 r'vimeo\.(?:clip|vod_title)_page_config\s*=\s*({.+?});',
917 webpage, 'page config', default='{}'), video_id, fatal=False)
918 if not page_config:
919 return self._extract_from_api(video_id)
920 config_url = page_config['player']['config_url']
921 cc_license = page_config.get('cc_license')
922 clip = page_config.get('clip') or {}
923 timestamp = clip.get('uploaded_on')
924 video_description = clean_html(
925 clip.get('description') or page_config.get('description_html_escaped'))
926 config = self._download_json(config_url, video_id)
927 video = config.get('video') or {}
928 vod = video.get('vod') or {}
929
930 def is_rented():
931 if '>You rented this title.<' in webpage:
932 return True
933 if try_get(config, lambda x: x['user']['purchased']):
934 return True
935 for purchase_option in (vod.get('purchase_options') or []):
936 if purchase_option.get('purchased'):
937 return True
938 label = purchase_option.get('label_string')
939 if label and (label.startswith('You rented this') or label.endswith(' remaining')):
940 return True
941 return False
942
943 if is_rented() and vod.get('is_trailer'):
944 feature_id = vod.get('feature_id')
945 if feature_id and not data.get('force_feature_id', False):
946 return self.url_result(smuggle_url(
947 'https://player.vimeo.com/player/%s' % feature_id,
948 {'force_feature_id': True}), 'Vimeo')
949
950 if not video_description:
951 video_description = self._html_search_regex(
952 r'(?s)<div\s+class="[^"]*description[^"]*"[^>]*>(.*?)</div>',
953 webpage, 'description', default=None)
954 if not video_description:
955 video_description = self._html_search_meta(
956 ['description', 'og:description', 'twitter:description'],
957 webpage, default=None)
958 if not video_description and is_pro:
959 orig_webpage = self._download_webpage(
960 orig_url, video_id,
961 note='Downloading webpage for description',
962 fatal=False)
963 if orig_webpage:
964 video_description = self._html_search_meta(
965 'description', orig_webpage, default=None)
966 if not video_description:
967 self.report_warning('Cannot find video description')
968
969 if not timestamp:
970 timestamp = self._search_regex(
971 r'<time[^>]+datetime="([^"]+)"', webpage,
972 'timestamp', default=None)
973
974 view_count = int_or_none(self._search_regex(r'UserPlays:(\d+)', webpage, 'view count', default=None))
975 like_count = int_or_none(self._search_regex(r'UserLikes:(\d+)', webpage, 'like count', default=None))
976 comment_count = int_or_none(self._search_regex(r'UserComments:(\d+)', webpage, 'comment count', default=None))
977
978 formats = []
979
980 source_format = self._extract_original_format(
981 'https://vimeo.com/' + video_id, video_id, video.get('unlisted_hash'))
982 if source_format:
983 formats.append(source_format)
984
985 info_dict_config = self._parse_config(config, video_id)
986 formats.extend(info_dict_config['formats'])
987 self._vimeo_sort_formats(formats)
988
989 json_ld = self._search_json_ld(webpage, video_id, default={})
990
991 if not cc_license:
992 cc_license = self._search_regex(
993 r'<link[^>]+rel=["\']license["\'][^>]+href=(["\'])(?P<license>(?:(?!\1).)+)\1',
994 webpage, 'license', default=None, group='license')
995
996 info_dict.update({
997 'formats': formats,
998 'timestamp': unified_timestamp(timestamp),
999 'description': video_description,
1000 'webpage_url': url,
1001 'view_count': view_count,
1002 'like_count': like_count,
1003 'comment_count': comment_count,
1004 'license': cc_license,
1005 })
1006
1007 return merge_dicts(info_dict, info_dict_config, json_ld)
1008
1009
1010 class VimeoOndemandIE(VimeoIE):
1011 IE_NAME = 'vimeo:ondemand'
1012 _VALID_URL = r'https?://(?:www\.)?vimeo\.com/ondemand/(?:[^/]+/)?(?P<id>[^/?#&]+)'
1013 _TESTS = [{
1014 # ondemand video not available via https://vimeo.com/id
1015 'url': 'https://vimeo.com/ondemand/20704',
1016 'md5': 'c424deda8c7f73c1dfb3edd7630e2f35',
1017 'info_dict': {
1018 'id': '105442900',
1019 'ext': 'mp4',
1020 'title': 'המעבדה - במאי יותם פלדמן',
1021 'uploader': 'גם סרטים',
1022 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/gumfilms',
1023 'uploader_id': 'gumfilms',
1024 'description': 'md5:aeeba3dbd4d04b0fa98a4fdc9c639998',
1025 'upload_date': '20140906',
1026 'timestamp': 1410032453,
1027 'thumbnail': 'https://i.vimeocdn.com/video/488238335-d7bf151c364cff8d467f1b73784668fe60aae28a54573a35d53a1210ae283bd8-d_1280',
1028 'comment_count': int,
1029 'license': 'https://creativecommons.org/licenses/by-nc-nd/3.0/',
1030 'duration': 53,
1031 'view_count': int,
1032 'like_count': int,
1033 },
1034 'params': {
1035 'format': 'best[protocol=https]',
1036 },
1037 'expected_warnings': ['Unable to download JSON metadata'],
1038 }, {
1039 # requires Referer to be passed along with og:video:url
1040 'url': 'https://vimeo.com/ondemand/36938/126682985',
1041 'info_dict': {
1042 'id': '126584684',
1043 'ext': 'mp4',
1044 'title': 'Rävlock, rätt läte på rätt plats',
1045 'uploader': 'Lindroth & Norin',
1046 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/lindrothnorin',
1047 'uploader_id': 'lindrothnorin',
1048 'description': 'md5:c3c46a90529612c8279fb6af803fc0df',
1049 'upload_date': '20150502',
1050 'timestamp': 1430586422,
1051 'duration': 121,
1052 'comment_count': int,
1053 'view_count': int,
1054 'thumbnail': 'https://i.vimeocdn.com/video/517077723-7066ae1d9a79d3eb361334fb5d58ec13c8f04b52f8dd5eadfbd6fb0bcf11f613-d_1280',
1055 'like_count': int,
1056 },
1057 'params': {
1058 'skip_download': True,
1059 },
1060 'expected_warnings': ['Unable to download JSON metadata'],
1061 }, {
1062 'url': 'https://vimeo.com/ondemand/nazmaalik',
1063 'only_matching': True,
1064 }, {
1065 'url': 'https://vimeo.com/ondemand/141692381',
1066 'only_matching': True,
1067 }, {
1068 'url': 'https://vimeo.com/ondemand/thelastcolony/150274832',
1069 'only_matching': True,
1070 }]
1071
1072
1073 class VimeoChannelIE(VimeoBaseInfoExtractor):
1074 IE_NAME = 'vimeo:channel'
1075 _VALID_URL = r'https://vimeo\.com/channels/(?P<id>[^/?#]+)/?(?:$|[?#])'
1076 _MORE_PAGES_INDICATOR = r'<a.+?rel="next"'
1077 _TITLE = None
1078 _TITLE_RE = r'<link rel="alternate"[^>]+?title="(.*?)"'
1079 _TESTS = [{
1080 'url': 'https://vimeo.com/channels/tributes',
1081 'info_dict': {
1082 'id': 'tributes',
1083 'title': 'Vimeo Tributes',
1084 },
1085 'playlist_mincount': 22,
1086 }]
1087 _BASE_URL_TEMPL = 'https://vimeo.com/channels/%s'
1088
1089 def _page_url(self, base_url, pagenum):
1090 return '%s/videos/page:%d/' % (base_url, pagenum)
1091
1092 def _extract_list_title(self, webpage):
1093 return self._TITLE or self._html_search_regex(
1094 self._TITLE_RE, webpage, 'list title', fatal=False)
1095
1096 def _title_and_entries(self, list_id, base_url):
1097 for pagenum in itertools.count(1):
1098 page_url = self._page_url(base_url, pagenum)
1099 webpage = self._download_webpage(
1100 page_url, list_id,
1101 'Downloading page %s' % pagenum)
1102
1103 if pagenum == 1:
1104 yield self._extract_list_title(webpage)
1105
1106 # Try extracting href first since not all videos are available via
1107 # short https://vimeo.com/id URL (e.g. https://vimeo.com/channels/tributes/6213729)
1108 clips = re.findall(
1109 r'id="clip_(\d+)"[^>]*>\s*<a[^>]+href="(/(?:[^/]+/)*\1)(?:[^>]+\btitle="([^"]+)")?', webpage)
1110 if clips:
1111 for video_id, video_url, video_title in clips:
1112 yield self.url_result(
1113 compat_urlparse.urljoin(base_url, video_url),
1114 VimeoIE.ie_key(), video_id=video_id, video_title=video_title)
1115 # More relaxed fallback
1116 else:
1117 for video_id in re.findall(r'id=["\']clip_(\d+)', webpage):
1118 yield self.url_result(
1119 'https://vimeo.com/%s' % video_id,
1120 VimeoIE.ie_key(), video_id=video_id)
1121
1122 if re.search(self._MORE_PAGES_INDICATOR, webpage, re.DOTALL) is None:
1123 break
1124
1125 def _extract_videos(self, list_id, base_url):
1126 title_and_entries = self._title_and_entries(list_id, base_url)
1127 list_title = next(title_and_entries)
1128 return self.playlist_result(title_and_entries, list_id, list_title)
1129
1130 def _real_extract(self, url):
1131 channel_id = self._match_id(url)
1132 return self._extract_videos(channel_id, self._BASE_URL_TEMPL % channel_id)
1133
1134
1135 class VimeoUserIE(VimeoChannelIE):
1136 IE_NAME = 'vimeo:user'
1137 _VALID_URL = r'https://vimeo\.com/(?!(?:[0-9]+|watchlater)(?:$|[?#/]))(?P<id>[^/]+)(?:/videos|[#?]|$)'
1138 _TITLE_RE = r'<a[^>]+?class="user">([^<>]+?)</a>'
1139 _TESTS = [{
1140 'url': 'https://vimeo.com/nkistudio/videos',
1141 'info_dict': {
1142 'title': 'Nki',
1143 'id': 'nkistudio',
1144 },
1145 'playlist_mincount': 66,
1146 }]
1147 _BASE_URL_TEMPL = 'https://vimeo.com/%s'
1148
1149
1150 class VimeoAlbumIE(VimeoBaseInfoExtractor):
1151 IE_NAME = 'vimeo:album'
1152 _VALID_URL = r'https://vimeo\.com/(?:album|showcase)/(?P<id>\d+)(?:$|[?#]|/(?!video))'
1153 _TITLE_RE = r'<header id="page_header">\n\s*<h1>(.*?)</h1>'
1154 _TESTS = [{
1155 'url': 'https://vimeo.com/album/2632481',
1156 'info_dict': {
1157 'id': '2632481',
1158 'title': 'Staff Favorites: November 2013',
1159 },
1160 'playlist_mincount': 13,
1161 }, {
1162 'note': 'Password-protected album',
1163 'url': 'https://vimeo.com/album/3253534',
1164 'info_dict': {
1165 'title': 'test',
1166 'id': '3253534',
1167 },
1168 'playlist_count': 1,
1169 'params': {
1170 'videopassword': 'youtube-dl',
1171 }
1172 }]
1173 _PAGE_SIZE = 100
1174
1175 def _fetch_page(self, album_id, authorization, hashed_pass, page):
1176 api_page = page + 1
1177 query = {
1178 'fields': 'link,uri',
1179 'page': api_page,
1180 'per_page': self._PAGE_SIZE,
1181 }
1182 if hashed_pass:
1183 query['_hashed_pass'] = hashed_pass
1184 try:
1185 videos = self._download_json(
1186 'https://api.vimeo.com/albums/%s/videos' % album_id,
1187 album_id, 'Downloading page %d' % api_page, query=query, headers={
1188 'Authorization': 'jwt ' + authorization,
1189 })['data']
1190 except ExtractorError as e:
1191 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 400:
1192 return
1193 for video in videos:
1194 link = video.get('link')
1195 if not link:
1196 continue
1197 uri = video.get('uri')
1198 video_id = self._search_regex(r'/videos/(\d+)', uri, 'video_id', default=None) if uri else None
1199 yield self.url_result(link, VimeoIE.ie_key(), video_id)
1200
1201 def _real_extract(self, url):
1202 album_id = self._match_id(url)
1203 viewer = self._download_json(
1204 'https://vimeo.com/_rv/viewer', album_id, fatal=False)
1205 if not viewer:
1206 webpage = self._download_webpage(url, album_id)
1207 viewer = self._parse_json(self._search_regex(
1208 r'bootstrap_data\s*=\s*({.+?})</script>',
1209 webpage, 'bootstrap data'), album_id)['viewer']
1210 jwt = viewer['jwt']
1211 album = self._download_json(
1212 'https://api.vimeo.com/albums/' + album_id,
1213 album_id, headers={'Authorization': 'jwt ' + jwt},
1214 query={'fields': 'description,name,privacy'})
1215 hashed_pass = None
1216 if try_get(album, lambda x: x['privacy']['view']) == 'password':
1217 password = self.get_param('videopassword')
1218 if not password:
1219 raise ExtractorError(
1220 'This album is protected by a password, use the --video-password option',
1221 expected=True)
1222 self._set_vimeo_cookie('vuid', viewer['vuid'])
1223 try:
1224 hashed_pass = self._download_json(
1225 'https://vimeo.com/showcase/%s/auth' % album_id,
1226 album_id, 'Verifying the password', data=urlencode_postdata({
1227 'password': password,
1228 'token': viewer['xsrft'],
1229 }), headers={
1230 'X-Requested-With': 'XMLHttpRequest',
1231 })['hashed_pass']
1232 except ExtractorError as e:
1233 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 401:
1234 raise ExtractorError('Wrong password', expected=True)
1235 raise
1236 entries = OnDemandPagedList(functools.partial(
1237 self._fetch_page, album_id, jwt, hashed_pass), self._PAGE_SIZE)
1238 return self.playlist_result(
1239 entries, album_id, album.get('name'), album.get('description'))
1240
1241
1242 class VimeoGroupsIE(VimeoChannelIE):
1243 IE_NAME = 'vimeo:group'
1244 _VALID_URL = r'https://vimeo\.com/groups/(?P<id>[^/]+)(?:/(?!videos?/\d+)|$)'
1245 _TESTS = [{
1246 'url': 'https://vimeo.com/groups/meetup',
1247 'info_dict': {
1248 'id': 'meetup',
1249 'title': 'Vimeo Meetup!',
1250 },
1251 'playlist_mincount': 27,
1252 }]
1253 _BASE_URL_TEMPL = 'https://vimeo.com/groups/%s'
1254
1255
1256 class VimeoReviewIE(VimeoBaseInfoExtractor):
1257 IE_NAME = 'vimeo:review'
1258 IE_DESC = 'Review pages on vimeo'
1259 _VALID_URL = r'(?P<url>https://vimeo\.com/[^/]+/review/(?P<id>[^/]+)/[0-9a-f]{10})'
1260 _TESTS = [{
1261 'url': 'https://vimeo.com/user21297594/review/75524534/3c257a1b5d',
1262 'md5': 'c507a72f780cacc12b2248bb4006d253',
1263 'info_dict': {
1264 'id': '75524534',
1265 'ext': 'mp4',
1266 'title': "DICK HARDWICK 'Comedian'",
1267 'uploader': 'Richard Hardwick',
1268 'uploader_id': 'user21297594',
1269 'description': "Comedian Dick Hardwick's five minute demo filmed in front of a live theater audience.\nEdit by Doug Mattocks",
1270 'duration': 304,
1271 'thumbnail': 'https://i.vimeocdn.com/video/450115033-43303819d9ebe24c2630352e18b7056d25197d09b3ae901abdac4c4f1d68de71-d_1280',
1272 'uploader_url': 'https://vimeo.com/user21297594',
1273 },
1274 }, {
1275 'note': 'video player needs Referer',
1276 'url': 'https://vimeo.com/user22258446/review/91613211/13f927e053',
1277 'md5': '6295fdab8f4bf6a002d058b2c6dce276',
1278 'info_dict': {
1279 'id': '91613211',
1280 'ext': 'mp4',
1281 'title': 're:(?i)^Death by dogma versus assembling agile . Sander Hoogendoorn',
1282 'uploader': 'DevWeek Events',
1283 'duration': 2773,
1284 'thumbnail': r're:^https?://.*\.jpg$',
1285 'uploader_id': 'user22258446',
1286 },
1287 'skip': 'video gone',
1288 }, {
1289 'note': 'Password protected',
1290 'url': 'https://vimeo.com/user37284429/review/138823582/c4d865efde',
1291 'info_dict': {
1292 'id': '138823582',
1293 'ext': 'mp4',
1294 'title': 'EFFICIENT PICKUP MASTERCLASS MODULE 1',
1295 'uploader': 'TMB',
1296 'uploader_id': 'user37284429',
1297 },
1298 'params': {
1299 'videopassword': 'holygrail',
1300 },
1301 'skip': 'video gone',
1302 }]
1303
1304 def _real_extract(self, url):
1305 page_url, video_id = self._match_valid_url(url).groups()
1306 data = self._download_json(
1307 page_url.replace('/review/', '/review/data/'), video_id)
1308 if data.get('isLocked') is True:
1309 video_password = self._get_video_password()
1310 viewer = self._download_json(
1311 'https://vimeo.com/_rv/viewer', video_id)
1312 webpage = self._verify_video_password(
1313 'https://vimeo.com/' + video_id, video_id,
1314 video_password, viewer['xsrft'], viewer['vuid'])
1315 clip_page_config = self._parse_json(self._search_regex(
1316 r'window\.vimeo\.clip_page_config\s*=\s*({.+?});',
1317 webpage, 'clip page config'), video_id)
1318 config_url = clip_page_config['player']['config_url']
1319 clip_data = clip_page_config.get('clip') or {}
1320 else:
1321 clip_data = data['clipData']
1322 config_url = clip_data['configUrl']
1323 config = self._download_json(config_url, video_id)
1324 info_dict = self._parse_config(config, video_id)
1325 source_format = self._extract_original_format(
1326 page_url + '/action', video_id)
1327 if source_format:
1328 info_dict['formats'].append(source_format)
1329 self._vimeo_sort_formats(info_dict['formats'])
1330 info_dict['description'] = clean_html(clip_data.get('description'))
1331 return info_dict
1332
1333
1334 class VimeoWatchLaterIE(VimeoChannelIE):
1335 IE_NAME = 'vimeo:watchlater'
1336 IE_DESC = 'Vimeo watch later list, ":vimeowatchlater" keyword (requires authentication)'
1337 _VALID_URL = r'https://vimeo\.com/(?:home/)?watchlater|:vimeowatchlater'
1338 _TITLE = 'Watch Later'
1339 _LOGIN_REQUIRED = True
1340 _TESTS = [{
1341 'url': 'https://vimeo.com/watchlater',
1342 'only_matching': True,
1343 }]
1344
1345 def _page_url(self, base_url, pagenum):
1346 url = '%s/page:%d/' % (base_url, pagenum)
1347 request = sanitized_Request(url)
1348 # Set the header to get a partial html page with the ids,
1349 # the normal page doesn't contain them.
1350 request.add_header('X-Requested-With', 'XMLHttpRequest')
1351 return request
1352
1353 def _real_extract(self, url):
1354 return self._extract_videos('watchlater', 'https://vimeo.com/watchlater')
1355
1356
1357 class VimeoLikesIE(VimeoChannelIE):
1358 _VALID_URL = r'https://(?:www\.)?vimeo\.com/(?P<id>[^/]+)/likes/?(?:$|[?#]|sort:)'
1359 IE_NAME = 'vimeo:likes'
1360 IE_DESC = 'Vimeo user likes'
1361 _TESTS = [{
1362 'url': 'https://vimeo.com/user755559/likes/',
1363 'playlist_mincount': 293,
1364 'info_dict': {
1365 'id': 'user755559',
1366 'title': 'urza’s Likes',
1367 },
1368 }, {
1369 'url': 'https://vimeo.com/stormlapse/likes',
1370 'only_matching': True,
1371 }]
1372
1373 def _page_url(self, base_url, pagenum):
1374 return '%s/page:%d/' % (base_url, pagenum)
1375
1376 def _real_extract(self, url):
1377 user_id = self._match_id(url)
1378 return self._extract_videos(user_id, 'https://vimeo.com/%s/likes' % user_id)
1379
1380
1381 class VHXEmbedIE(VimeoBaseInfoExtractor):
1382 IE_NAME = 'vhx:embed'
1383 _VALID_URL = r'https?://embed\.vhx\.tv/videos/(?P<id>\d+)'
1384
1385 @staticmethod
1386 def _extract_url(webpage):
1387 mobj = re.search(
1388 r'<iframe[^>]+src="(https?://embed\.vhx\.tv/videos/\d+[^"]*)"', webpage)
1389 return unescapeHTML(mobj.group(1)) if mobj else None
1390
1391 def _real_extract(self, url):
1392 video_id = self._match_id(url)
1393 webpage = self._download_webpage(url, video_id)
1394 config_url = self._parse_json(self._search_regex(
1395 r'window\.OTTData\s*=\s*({.+})', webpage,
1396 'ott data'), video_id, js_to_json)['config_url']
1397 config = self._download_json(config_url, video_id)
1398 info = self._parse_config(config, video_id)
1399 info['id'] = video_id
1400 self._vimeo_sort_formats(info['formats'])
1401 return info