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