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