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