2 from __future__ import unicode_literals
8 from .common import InfoExtractor
29 class VimeoBaseInfoExtractor(InfoExtractor):
30 _NETRC_MACHINE = 'vimeo'
31 _LOGIN_REQUIRED = False
32 _LOGIN_URL = 'https://vimeo.com/log_in'
35 (username, password) = self._get_login_info()
37 if self._LOGIN_REQUIRED:
38 raise ExtractorError('No login info available, needed for using %s.' % self.IE_NAME, expected=True)
41 webpage = self._download_webpage(self._LOGIN_URL, None, False)
42 token, vuid = self._extract_xsrft_and_vuid(webpage)
43 data = urlencode_postdata(encode_dict({
50 login_request = sanitized_Request(self._LOGIN_URL, data)
51 login_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
52 login_request.add_header('Referer', self._LOGIN_URL)
53 self._set_vimeo_cookie('vuid', vuid)
54 self._download_webpage(login_request, None, False, 'Wrong login info')
56 def _extract_xsrft_and_vuid(self, webpage):
57 xsrft = self._search_regex(
58 r'xsrft\s*[=:]\s*(?P<q>["\'])(?P<xsrft>.+?)(?P=q)',
59 webpage, 'login token', group='xsrft')
60 vuid = self._search_regex(
61 r'["\']vuid["\']\s*:\s*(["\'])(?P<vuid>.+?)\1',
62 webpage, 'vuid', group='vuid')
65 def _set_vimeo_cookie(self, name, value):
66 self._set_cookie('vimeo.com', name, value)
69 class VimeoIE(VimeoBaseInfoExtractor):
70 """Information extractor for vimeo.com."""
72 # _VALID_URL matches Vimeo URLs
75 (?:(?:www|(?P<player>player))\.)?
76 vimeo(?P<pro>pro)?\.com/
77 (?!channels/[^/?#]+/?(?:$|[?#])|album/)
79 (?:(?:play_redirect_hls|moogaloop\.swf)\?clip_id=)?
82 /?(?:[?&].*)?(?:[#].*)?$'''
86 'url': 'http://vimeo.com/56015672#at=0',
87 'md5': '8879b6cc097e987f02484baf890129e5',
91 'title': "youtube-dl test video - \u2605 \" ' \u5e78 / \\ \u00e4 \u21ad \U0001d550",
92 'description': 'md5:2d3305bad981a06ff79f027f19865021',
93 'upload_date': '20121220',
94 'uploader_id': 'user7108434',
95 'uploader': 'Filippo Valsorda',
100 'url': 'http://vimeopro.com/openstreetmapus/state-of-the-map-us-2013/video/68093876',
101 'md5': '3b5ca6aa22b60dfeeadf50b72e44ed82',
102 'note': 'Vimeo Pro video (#1197)',
106 'uploader_id': 'openstreetmapus',
107 'uploader': 'OpenStreetMap US',
108 'title': 'Andy Allan - Putting the Carto into OpenStreetMap Cartography',
109 'description': 'md5:fd69a7b8d8c34a4e1d2ec2e4afd6ec30',
114 'url': 'http://player.vimeo.com/video/54469442',
115 'md5': '619b811a4417aa4abe78dc653becf511',
116 'note': 'Videos that embed the url in the player page',
120 'title': 'Kathy Sierra: Building the minimum Badass User, Business of Software 2012',
121 'uploader': 'The BLN & Business of Software',
122 'uploader_id': 'theblnbusinessofsoftware',
128 'url': 'http://vimeo.com/68375962',
129 'md5': 'aaf896bdb7ddd6476df50007a0ac0ae7',
130 'note': 'Video protected with password',
134 'title': 'youtube-dl password protected test video',
135 'upload_date': '20130614',
136 'uploader_id': 'user18948128',
137 'uploader': 'Jaime Marquínez Ferrándiz',
139 'description': 'This is "youtube-dl password protected test video" by Jaime Marquínez Ferrándiz on Vimeo, the home for high quality videos and the people\u2026',
142 'videopassword': 'youtube-dl',
146 'url': 'http://vimeo.com/channels/keypeele/75629013',
147 'md5': '2f86a05afe9d7abc0b9126d229bbe15d',
148 'note': 'Video is freely available via original URL '
149 'and protected with password when accessed via http://vimeo.com/75629013',
153 'title': 'Key & Peele: Terrorist Interrogation',
154 'description': 'md5:8678b246399b070816b12313e8b4eb5c',
155 'uploader_id': 'atencio',
156 'uploader': 'Peter Atencio',
157 'upload_date': '20130927',
162 'url': 'http://vimeo.com/76979871',
163 'note': 'Video with subtitles',
167 'title': 'The New Vimeo Player (You Know, For Videos)',
168 'description': 'md5:2ec900bf97c3f389378a96aee11260ea',
169 'upload_date': '20131015',
170 'uploader_id': 'staff',
171 'uploader': 'Vimeo Staff',
176 # from https://www.ouya.tv/game/Pier-Solar-and-the-Great-Architects/
177 'url': 'https://player.vimeo.com/video/98044508',
178 'note': 'The js code contains assignments to the same variable as the config',
182 'title': 'Pier Solar OUYA Official Trailer',
183 'uploader': 'Tulio Gonçalves',
184 'uploader_id': 'user28849593',
188 'url': 'https://vimeo.com/109815029',
189 'note': 'Video not completely processed, "failed" seed status',
190 'only_matching': True,
193 'url': 'https://vimeo.com/groups/travelhd/videos/22439234',
194 'only_matching': True,
199 def _extract_vimeo_url(url, webpage):
200 # Look for embedded (iframe) Vimeo player
202 r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/.+?)\1', webpage)
204 player_url = unescapeHTML(mobj.group('url'))
205 surl = smuggle_url(player_url, {'Referer': url})
207 # Look for embedded (swf embed) Vimeo player
209 r'<embed[^>]+?src="((?:https?:)?//(?:www\.)?vimeo\.com/moogaloop\.swf.+?)"', webpage)
213 def _verify_video_password(self, url, video_id, webpage):
214 password = self._downloader.params.get('videopassword', None)
216 raise ExtractorError('This video is protected by a password, use the --video-password option', expected=True)
217 token, vuid = self._extract_xsrft_and_vuid(webpage)
218 data = urlencode_postdata(encode_dict({
219 'password': password,
222 if url.startswith('http://'):
223 # vimeo only supports https now, but the user can give an http url
224 url = url.replace('http://', 'https://')
225 password_request = sanitized_Request(url + '/password', data)
226 password_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
227 password_request.add_header('Referer', url)
228 self._set_vimeo_cookie('vuid', vuid)
229 return self._download_webpage(
230 password_request, video_id,
231 'Verifying the password', 'Wrong password')
233 def _verify_player_video_password(self, url, video_id):
234 password = self._downloader.params.get('videopassword', None)
236 raise ExtractorError('This video is protected by a password, use the --video-password option')
237 data = urlencode_postdata(encode_dict({'password': password}))
238 pass_url = url + '/check-password'
239 password_request = sanitized_Request(pass_url, data)
240 password_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
241 return self._download_json(
242 password_request, video_id,
243 'Verifying the password',
246 def _real_initialize(self):
249 def _real_extract(self, url):
250 url, data = unsmuggle_url(url)
251 headers = std_headers
253 headers = headers.copy()
255 if 'Referer' not in headers:
256 headers['Referer'] = url
258 # Extract ID from URL
259 mobj = re.match(self._VALID_URL, url)
260 video_id = mobj.group('id')
262 if mobj.group('pro') or mobj.group('player'):
263 url = 'https://player.vimeo.com/video/' + video_id
265 url = 'https://vimeo.com/' + video_id
267 # Retrieve video webpage to extract further information
268 request = sanitized_Request(url, None, headers)
270 webpage = self._download_webpage(request, video_id)
271 except ExtractorError as ee:
272 if isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 403:
273 errmsg = ee.cause.read()
274 if b'Because of its privacy settings, this video cannot be played here' in errmsg:
275 raise ExtractorError(
276 'Cannot download embed-only video without embedding '
277 'URL. Please call youtube-dl with the URL of the page '
278 'that embeds this video.',
282 # Now we begin extracting as much information as we can from what we
283 # retrieved. First we extract the information common to all extractors,
284 # and latter we extract those that are Vimeo specific.
285 self.report_extraction(video_id)
287 vimeo_config = self._search_regex(
288 r'vimeo\.config\s*=\s*(?:({.+?})|_extend\([^,]+,\s+({.+?})\));', webpage,
289 'vimeo config', default=None)
291 seed_status = self._parse_json(vimeo_config, video_id).get('seed_status', {})
292 if seed_status.get('state') == 'failed':
293 raise ExtractorError(
294 '%s said: %s' % (self.IE_NAME, seed_status['title']),
297 # Extract the config JSON
300 config_url = self._html_search_regex(
301 r' data-config-url="(.+?)"', webpage,
302 'config URL', default=None)
304 # Sometimes new react-based page is served instead of old one that require
305 # different config URL extraction approach (see
306 # https://github.com/rg3/youtube-dl/pull/7209)
307 vimeo_clip_page_config = self._search_regex(
308 r'vimeo\.clip_page_config\s*=\s*({.+?});', webpage,
309 'vimeo clip page config')
310 config_url = self._parse_json(
311 vimeo_clip_page_config, video_id)['player']['config_url']
312 config_json = self._download_webpage(config_url, video_id)
313 config = json.loads(config_json)
314 except RegexNotFoundError:
315 # For pro videos or player.vimeo.com urls
316 # We try to find out to which variable is assigned the config dic
317 m_variable_name = re.search('(\w)\.video\.id', webpage)
318 if m_variable_name is not None:
319 config_re = r'%s=({[^}].+?});' % re.escape(m_variable_name.group(1))
321 config_re = [r' = {config:({.+?}),assets:', r'(?:[abc])=({.+?});']
322 config = self._search_regex(config_re, webpage, 'info section',
324 config = json.loads(config)
325 except Exception as e:
326 if re.search('The creator of this video has not given you permission to embed it on this domain.', webpage):
327 raise ExtractorError('The author has restricted the access to this video, try with the "--referer" option')
329 if re.search(r'<form[^>]+?id="pw_form"', webpage) is not None:
330 if data and '_video_password_verified' in data:
331 raise ExtractorError('video password verification failed!')
332 self._verify_video_password(url, video_id, webpage)
333 return self._real_extract(
334 smuggle_url(url, {'_video_password_verified': 'verified'}))
336 raise ExtractorError('Unable to extract info section',
339 if config.get('view') == 4:
340 config = self._verify_player_video_password(url, video_id)
343 video_title = config["video"]["title"]
345 # Extract uploader and uploader_id
346 video_uploader = config["video"]["owner"]["name"]
347 video_uploader_id = config["video"]["owner"]["url"].split('/')[-1] if config["video"]["owner"]["url"] else None
349 # Extract video thumbnail
350 video_thumbnail = config["video"].get("thumbnail")
351 if video_thumbnail is None:
352 video_thumbs = config["video"].get("thumbs")
353 if video_thumbs and isinstance(video_thumbs, dict):
354 _, video_thumbnail = sorted((int(width if width.isdigit() else 0), t_url) for (width, t_url) in video_thumbs.items())[-1]
356 # Extract video description
358 video_description = self._html_search_regex(
359 r'(?s)<div\s+class="[^"]*description[^"]*"[^>]*>(.*?)</div>',
360 webpage, 'description', default=None)
361 if not video_description:
362 video_description = self._html_search_meta(
363 'description', webpage, default=None)
364 if not video_description and mobj.group('pro'):
365 orig_webpage = self._download_webpage(
367 note='Downloading webpage for description',
370 video_description = self._html_search_meta(
371 'description', orig_webpage, default=None)
372 if not video_description and not mobj.group('player'):
373 self._downloader.report_warning('Cannot find video description')
375 # Extract video duration
376 video_duration = int_or_none(config["video"].get("duration"))
378 # Extract upload date
379 video_upload_date = None
380 mobj = re.search(r'<time[^>]+datetime="([^"]+)"', webpage)
382 video_upload_date = unified_strdate(mobj.group(1))
385 view_count = int(self._search_regex(r'UserPlays:(\d+)', webpage, 'view count'))
386 like_count = int(self._search_regex(r'UserLikes:(\d+)', webpage, 'like count'))
387 comment_count = int(self._search_regex(r'UserComments:(\d+)', webpage, 'comment count'))
388 except RegexNotFoundError:
389 # This info is only available in vimeo.com/{id} urls
395 config_files = config['video'].get('files') or config['request'].get('files', {})
396 for f in config_files.get('progressive', []):
397 video_url = f.get('url')
402 'format_id': 'http-%s' % f.get('quality'),
403 'width': int_or_none(f.get('width')),
404 'height': int_or_none(f.get('height')),
405 'fps': int_or_none(f.get('fps')),
406 'tbr': int_or_none(f.get('bitrate')),
408 m3u8_url = config_files.get('hls', {}).get('url')
410 m3u8_formats = self._extract_m3u8_formats(
411 m3u8_url, video_id, 'mp4', 'm3u8_native', 0, 'hls', fatal=False)
413 formats.extend(m3u8_formats)
414 # Bitrates are completely broken. Single m3u8 may contain entries in kbps and bps
415 # at the same time without actual units specified. This lead to wrong sorting.
416 self._sort_formats(formats, field_preference=('height', 'width', 'fps', 'format_id'))
419 text_tracks = config['request'].get('text_tracks')
421 for tt in text_tracks:
422 subtitles[tt['lang']] = [{
424 'url': 'https://vimeo.com' + tt['url'],
429 'uploader': video_uploader,
430 'uploader_id': video_uploader_id,
431 'upload_date': video_upload_date,
432 'title': video_title,
433 'thumbnail': video_thumbnail,
434 'description': video_description,
435 'duration': video_duration,
438 'view_count': view_count,
439 'like_count': like_count,
440 'comment_count': comment_count,
441 'subtitles': subtitles,
445 class VimeoChannelIE(VimeoBaseInfoExtractor):
446 IE_NAME = 'vimeo:channel'
447 _VALID_URL = r'https://vimeo\.com/channels/(?P<id>[^/?#]+)/?(?:$|[?#])'
448 _MORE_PAGES_INDICATOR = r'<a.+?rel="next"'
450 _TITLE_RE = r'<link rel="alternate"[^>]+?title="(.*?)"'
452 'url': 'https://vimeo.com/channels/tributes',
455 'title': 'Vimeo Tributes',
457 'playlist_mincount': 25,
460 def _page_url(self, base_url, pagenum):
461 return '%s/videos/page:%d/' % (base_url, pagenum)
463 def _extract_list_title(self, webpage):
464 return self._TITLE or self._html_search_regex(self._TITLE_RE, webpage, 'list title')
466 def _login_list_password(self, page_url, list_id, webpage):
467 login_form = self._search_regex(
468 r'(?s)<form[^>]+?id="pw_form"(.*?)</form>',
469 webpage, 'login form', default=None)
473 password = self._downloader.params.get('videopassword', None)
475 raise ExtractorError('This album is protected by a password, use the --video-password option', expected=True)
476 fields = self._hidden_inputs(login_form)
477 token, vuid = self._extract_xsrft_and_vuid(webpage)
478 fields['token'] = token
479 fields['password'] = password
480 post = urlencode_postdata(encode_dict(fields))
481 password_path = self._search_regex(
482 r'action="([^"]+)"', login_form, 'password URL')
483 password_url = compat_urlparse.urljoin(page_url, password_path)
484 password_request = sanitized_Request(password_url, post)
485 password_request.add_header('Content-type', 'application/x-www-form-urlencoded')
486 self._set_vimeo_cookie('vuid', vuid)
487 self._set_vimeo_cookie('xsrft', token)
489 return self._download_webpage(
490 password_request, list_id,
491 'Verifying the password', 'Wrong password')
493 def _title_and_entries(self, list_id, base_url):
494 for pagenum in itertools.count(1):
495 page_url = self._page_url(base_url, pagenum)
496 webpage = self._download_webpage(
498 'Downloading page %s' % pagenum)
501 webpage = self._login_list_password(page_url, list_id, webpage)
502 yield self._extract_list_title(webpage)
504 for video_id in re.findall(r'id="clip_(\d+?)"', webpage):
505 yield self.url_result('https://vimeo.com/%s' % video_id, 'Vimeo')
507 if re.search(self._MORE_PAGES_INDICATOR, webpage, re.DOTALL) is None:
510 def _extract_videos(self, list_id, base_url):
511 title_and_entries = self._title_and_entries(list_id, base_url)
512 list_title = next(title_and_entries)
513 return self.playlist_result(title_and_entries, list_id, list_title)
515 def _real_extract(self, url):
516 mobj = re.match(self._VALID_URL, url)
517 channel_id = mobj.group('id')
518 return self._extract_videos(channel_id, 'https://vimeo.com/channels/%s' % channel_id)
521 class VimeoUserIE(VimeoChannelIE):
522 IE_NAME = 'vimeo:user'
523 _VALID_URL = r'https://vimeo\.com/(?!(?:[0-9]+|watchlater)(?:$|[?#/]))(?P<name>[^/]+)(?:/videos|[#?]|$)'
524 _TITLE_RE = r'<a[^>]+?class="user">([^<>]+?)</a>'
526 'url': 'https://vimeo.com/nkistudio/videos',
531 'playlist_mincount': 66,
534 def _real_extract(self, url):
535 mobj = re.match(self._VALID_URL, url)
536 name = mobj.group('name')
537 return self._extract_videos(name, 'https://vimeo.com/%s' % name)
540 class VimeoAlbumIE(VimeoChannelIE):
541 IE_NAME = 'vimeo:album'
542 _VALID_URL = r'https://vimeo\.com/album/(?P<id>\d+)'
543 _TITLE_RE = r'<header id="page_header">\n\s*<h1>(.*?)</h1>'
545 'url': 'https://vimeo.com/album/2632481',
548 'title': 'Staff Favorites: November 2013',
550 'playlist_mincount': 13,
552 'note': 'Password-protected album',
553 'url': 'https://vimeo.com/album/3253534',
560 'videopassword': 'youtube-dl',
564 def _page_url(self, base_url, pagenum):
565 return '%s/page:%d/' % (base_url, pagenum)
567 def _real_extract(self, url):
568 album_id = self._match_id(url)
569 return self._extract_videos(album_id, 'https://vimeo.com/album/%s' % album_id)
572 class VimeoGroupsIE(VimeoAlbumIE):
573 IE_NAME = 'vimeo:group'
574 _VALID_URL = r'https://vimeo\.com/groups/(?P<name>[^/]+)(?:/(?!videos?/\d+)|$)'
576 'url': 'https://vimeo.com/groups/rolexawards',
579 'title': 'Rolex Awards for Enterprise',
581 'playlist_mincount': 73,
584 def _extract_list_title(self, webpage):
585 return self._og_search_title(webpage)
587 def _real_extract(self, url):
588 mobj = re.match(self._VALID_URL, url)
589 name = mobj.group('name')
590 return self._extract_videos(name, 'https://vimeo.com/groups/%s' % name)
593 class VimeoReviewIE(InfoExtractor):
594 IE_NAME = 'vimeo:review'
595 IE_DESC = 'Review pages on vimeo'
596 _VALID_URL = r'https://vimeo\.com/[^/]+/review/(?P<id>[^/]+)'
598 'url': 'https://vimeo.com/user21297594/review/75524534/3c257a1b5d',
599 'md5': 'c507a72f780cacc12b2248bb4006d253',
603 'title': "DICK HARDWICK 'Comedian'",
604 'uploader': 'Richard Hardwick',
607 'note': 'video player needs Referer',
608 'url': 'https://vimeo.com/user22258446/review/91613211/13f927e053',
609 'md5': '6295fdab8f4bf6a002d058b2c6dce276',
613 'title': 're:(?i)^Death by dogma versus assembling agile . Sander Hoogendoorn',
614 'uploader': 'DevWeek Events',
616 'thumbnail': 're:^https?://.*\.jpg$',
620 def _real_extract(self, url):
621 mobj = re.match(self._VALID_URL, url)
622 video_id = mobj.group('id')
623 player_url = 'https://player.vimeo.com/player/' + video_id
624 return self.url_result(player_url, 'Vimeo', video_id)
627 class VimeoWatchLaterIE(VimeoChannelIE):
628 IE_NAME = 'vimeo:watchlater'
629 IE_DESC = 'Vimeo watch later list, "vimeowatchlater" keyword (requires authentication)'
630 _VALID_URL = r'https://vimeo\.com/(?:home/)?watchlater|:vimeowatchlater'
631 _TITLE = 'Watch Later'
632 _LOGIN_REQUIRED = True
634 'url': 'https://vimeo.com/watchlater',
635 'only_matching': True,
638 def _real_initialize(self):
641 def _page_url(self, base_url, pagenum):
642 url = '%s/page:%d/' % (base_url, pagenum)
643 request = sanitized_Request(url)
644 # Set the header to get a partial html page with the ids,
645 # the normal page doesn't contain them.
646 request.add_header('X-Requested-With', 'XMLHttpRequest')
649 def _real_extract(self, url):
650 return self._extract_videos('watchlater', 'https://vimeo.com/watchlater')
653 class VimeoLikesIE(InfoExtractor):
654 _VALID_URL = r'https://(?:www\.)?vimeo\.com/user(?P<id>[0-9]+)/likes/?(?:$|[?#]|sort:)'
655 IE_NAME = 'vimeo:likes'
656 IE_DESC = 'Vimeo user likes'
658 'url': 'https://vimeo.com/user755559/likes/',
659 'playlist_mincount': 293,
661 'id': 'user755559_likes',
662 "description": "See all the videos urza likes",
663 "title": 'Videos urza likes',
667 def _real_extract(self, url):
668 user_id = self._match_id(url)
669 webpage = self._download_webpage(url, user_id)
670 page_count = self._int(
672 r'''(?x)<li><a\s+href="[^"]+"\s+data-page="([0-9]+)">
673 .*?</a></li>\s*<li\s+class="pagination_next">
674 ''', webpage, 'page count'),
675 'page count', fatal=True)
677 title = self._html_search_regex(
678 r'(?s)<h1>(.+?)</h1>', webpage, 'title', fatal=False)
679 description = self._html_search_meta('description', webpage)
682 page_url = 'https://vimeo.com/user%s/likes/page:%d/sort:date' % (
684 webpage = self._download_webpage(
686 note='Downloading page %d/%d' % (idx + 1, page_count))
687 video_list = self._search_regex(
688 r'(?s)<ol class="js-browse_list[^"]+"[^>]*>(.*?)</ol>',
689 webpage, 'video content')
691 r'<li[^>]*>\s*<a\s+href="([^"]+)"', video_list)
695 'url': compat_urlparse.urljoin(page_url, path),
698 pl = InAdvancePagedList(_get_page, page_count, PAGE_SIZE)
702 'id': 'user%s_likes' % user_id,
704 'description': description,