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