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