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