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