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