2 from __future__ import unicode_literals
8 from .common import InfoExtractor
30 class VimeoBaseInfoExtractor(InfoExtractor):
31 _NETRC_MACHINE = 'vimeo'
32 _LOGIN_REQUIRED = False
33 _LOGIN_URL = 'https://vimeo.com/log_in'
36 (username, password) = self._get_login_info()
38 if self._LOGIN_REQUIRED:
39 raise ExtractorError('No login info available, needed for using %s.' % self.IE_NAME, expected=True)
42 webpage = self._download_webpage(self._LOGIN_URL, None, False)
43 token, vuid = self._extract_xsrft_and_vuid(webpage)
44 data = urlencode_postdata(encode_dict({
51 login_request = sanitized_Request(self._LOGIN_URL, data)
52 login_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
53 login_request.add_header('Referer', self._LOGIN_URL)
54 self._set_vimeo_cookie('vuid', vuid)
55 self._download_webpage(login_request, None, False, 'Wrong login info')
57 def _extract_xsrft_and_vuid(self, webpage):
58 xsrft = self._search_regex(
59 r'xsrft\s*[=:]\s*(?P<q>["\'])(?P<xsrft>.+?)(?P=q)',
60 webpage, 'login token', group='xsrft')
61 vuid = self._search_regex(
62 r'["\']vuid["\']\s*:\s*(["\'])(?P<vuid>.+?)\1',
63 webpage, 'vuid', group='vuid')
66 def _set_vimeo_cookie(self, name, value):
67 self._set_cookie('vimeo.com', name, value)
70 class VimeoIE(VimeoBaseInfoExtractor):
71 """Information extractor for vimeo.com."""
73 # _VALID_URL matches Vimeo URLs
76 (?:(?:www|(?P<player>player))\.)?
77 vimeo(?P<pro>pro)?\.com/
78 (?!channels/[^/?#]+/?(?:$|[?#])|album/)
80 (?:(?:play_redirect_hls|moogaloop\.swf)\?clip_id=)?
83 /?(?:[?&].*)?(?:[#].*)?$'''
87 'url': 'http://vimeo.com/56015672#at=0',
88 'md5': '8879b6cc097e987f02484baf890129e5',
92 'title': "youtube-dl test video - \u2605 \" ' \u5e78 / \\ \u00e4 \u21ad \U0001d550",
93 'description': 'md5:2d3305bad981a06ff79f027f19865021',
94 'upload_date': '20121220',
95 'uploader_id': 'user7108434',
96 'uploader': 'Filippo Valsorda',
101 'url': 'http://vimeopro.com/openstreetmapus/state-of-the-map-us-2013/video/68093876',
102 'md5': '3b5ca6aa22b60dfeeadf50b72e44ed82',
103 'note': 'Vimeo Pro video (#1197)',
107 'uploader_id': 'openstreetmapus',
108 'uploader': 'OpenStreetMap US',
109 'title': 'Andy Allan - Putting the Carto into OpenStreetMap Cartography',
110 'description': 'md5:fd69a7b8d8c34a4e1d2ec2e4afd6ec30',
115 'url': 'http://player.vimeo.com/video/54469442',
116 'md5': '619b811a4417aa4abe78dc653becf511',
117 'note': 'Videos that embed the url in the player page',
121 'title': 'Kathy Sierra: Building the minimum Badass User, Business of Software 2012',
122 'uploader': 'The BLN & Business of Software',
123 'uploader_id': 'theblnbusinessofsoftware',
129 'url': 'http://vimeo.com/68375962',
130 'md5': 'aaf896bdb7ddd6476df50007a0ac0ae7',
131 'note': 'Video protected with password',
135 'title': 'youtube-dl password protected test video',
136 'upload_date': '20130614',
137 'uploader_id': 'user18948128',
138 'uploader': 'Jaime Marquínez Ferrándiz',
140 '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',
143 'videopassword': 'youtube-dl',
147 'url': 'http://vimeo.com/channels/keypeele/75629013',
148 'md5': '2f86a05afe9d7abc0b9126d229bbe15d',
149 'note': 'Video is freely available via original URL '
150 'and protected with password when accessed via http://vimeo.com/75629013',
154 'title': 'Key & Peele: Terrorist Interrogation',
155 'description': 'md5:8678b246399b070816b12313e8b4eb5c',
156 'uploader_id': 'atencio',
157 'uploader': 'Peter Atencio',
158 'upload_date': '20130927',
163 'url': 'http://vimeo.com/76979871',
164 'note': 'Video with subtitles',
168 'title': 'The New Vimeo Player (You Know, For Videos)',
169 'description': 'md5:2ec900bf97c3f389378a96aee11260ea',
170 'upload_date': '20131015',
171 'uploader_id': 'staff',
172 'uploader': 'Vimeo Staff',
177 # from https://www.ouya.tv/game/Pier-Solar-and-the-Great-Architects/
178 'url': 'https://player.vimeo.com/video/98044508',
179 'note': 'The js code contains assignments to the same variable as the config',
183 'title': 'Pier Solar OUYA Official Trailer',
184 'uploader': 'Tulio Gonçalves',
185 'uploader_id': 'user28849593',
189 # contains original format
190 'url': 'https://vimeo.com/33951933',
191 'md5': '53c688fa95a55bf4b7293d37a89c5c53',
195 'title': 'FOX CLASSICS - Forever Classic ID - A Full Minute',
196 'uploader': 'The DMCI',
197 'uploader_id': 'dmci',
198 'upload_date': '20111220',
199 'description': 'md5:ae23671e82d05415868f7ad1aec21147',
203 'url': 'https://vimeo.com/109815029',
204 'note': 'Video not completely processed, "failed" seed status',
205 'only_matching': True,
208 'url': 'https://vimeo.com/groups/travelhd/videos/22439234',
209 'only_matching': True,
214 def _extract_vimeo_url(url, webpage):
215 # Look for embedded (iframe) Vimeo player
217 r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/.+?)\1', webpage)
219 player_url = unescapeHTML(mobj.group('url'))
220 surl = smuggle_url(player_url, {'Referer': url})
222 # Look for embedded (swf embed) Vimeo player
224 r'<embed[^>]+?src="((?:https?:)?//(?:www\.)?vimeo\.com/moogaloop\.swf.+?)"', webpage)
228 def _verify_video_password(self, url, video_id, webpage):
229 password = self._downloader.params.get('videopassword', None)
231 raise ExtractorError('This video is protected by a password, use the --video-password option', expected=True)
232 token, vuid = self._extract_xsrft_and_vuid(webpage)
233 data = urlencode_postdata(encode_dict({
234 'password': password,
237 if url.startswith('http://'):
238 # vimeo only supports https now, but the user can give an http url
239 url = url.replace('http://', 'https://')
240 password_request = sanitized_Request(url + '/password', data)
241 password_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
242 password_request.add_header('Referer', url)
243 self._set_vimeo_cookie('vuid', vuid)
244 return self._download_webpage(
245 password_request, video_id,
246 'Verifying the password', 'Wrong password')
248 def _verify_player_video_password(self, url, video_id):
249 password = self._downloader.params.get('videopassword', None)
251 raise ExtractorError('This video is protected by a password, use the --video-password option')
252 data = urlencode_postdata(encode_dict({'password': password}))
253 pass_url = url + '/check-password'
254 password_request = sanitized_Request(pass_url, data)
255 password_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
256 return self._download_json(
257 password_request, video_id,
258 'Verifying the password',
261 def _real_initialize(self):
264 def _real_extract(self, url):
265 url, data = unsmuggle_url(url)
266 headers = std_headers
268 headers = headers.copy()
270 if 'Referer' not in headers:
271 headers['Referer'] = url
273 # Extract ID from URL
274 mobj = re.match(self._VALID_URL, url)
275 video_id = mobj.group('id')
277 if mobj.group('pro') or mobj.group('player'):
278 url = 'https://player.vimeo.com/video/' + video_id
280 url = 'https://vimeo.com/' + video_id
282 # Retrieve video webpage to extract further information
283 request = sanitized_Request(url, None, headers)
285 webpage = self._download_webpage(request, video_id)
286 except ExtractorError as ee:
287 if isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 403:
288 errmsg = ee.cause.read()
289 if b'Because of its privacy settings, this video cannot be played here' in errmsg:
290 raise ExtractorError(
291 'Cannot download embed-only video without embedding '
292 'URL. Please call youtube-dl with the URL of the page '
293 'that embeds this video.',
297 # Now we begin extracting as much information as we can from what we
298 # retrieved. First we extract the information common to all extractors,
299 # and latter we extract those that are Vimeo specific.
300 self.report_extraction(video_id)
302 vimeo_config = self._search_regex(
303 r'vimeo\.config\s*=\s*(?:({.+?})|_extend\([^,]+,\s+({.+?})\));', webpage,
304 'vimeo config', default=None)
306 seed_status = self._parse_json(vimeo_config, video_id).get('seed_status', {})
307 if seed_status.get('state') == 'failed':
308 raise ExtractorError(
309 '%s said: %s' % (self.IE_NAME, seed_status['title']),
312 # Extract the config JSON
315 config_url = self._html_search_regex(
316 r' data-config-url="(.+?)"', webpage,
317 'config URL', default=None)
319 # Sometimes new react-based page is served instead of old one that require
320 # different config URL extraction approach (see
321 # https://github.com/rg3/youtube-dl/pull/7209)
322 vimeo_clip_page_config = self._search_regex(
323 r'vimeo\.clip_page_config\s*=\s*({.+?});', webpage,
324 'vimeo clip page config')
325 config_url = self._parse_json(
326 vimeo_clip_page_config, video_id)['player']['config_url']
327 config_json = self._download_webpage(config_url, video_id)
328 config = json.loads(config_json)
329 except RegexNotFoundError:
330 # For pro videos or player.vimeo.com urls
331 # We try to find out to which variable is assigned the config dic
332 m_variable_name = re.search('(\w)\.video\.id', webpage)
333 if m_variable_name is not None:
334 config_re = r'%s=({[^}].+?});' % re.escape(m_variable_name.group(1))
336 config_re = [r' = {config:({.+?}),assets:', r'(?:[abc])=({.+?});']
337 config = self._search_regex(config_re, webpage, 'info section',
339 config = json.loads(config)
340 except Exception as e:
341 if re.search('The creator of this video has not given you permission to embed it on this domain.', webpage):
342 raise ExtractorError('The author has restricted the access to this video, try with the "--referer" option')
344 if re.search(r'<form[^>]+?id="pw_form"', webpage) is not None:
345 if data and '_video_password_verified' in data:
346 raise ExtractorError('video password verification failed!')
347 self._verify_video_password(url, video_id, webpage)
348 return self._real_extract(
349 smuggle_url(url, {'_video_password_verified': 'verified'}))
351 raise ExtractorError('Unable to extract info section',
354 if config.get('view') == 4:
355 config = self._verify_player_video_password(url, video_id)
358 video_title = config["video"]["title"]
360 # Extract uploader and uploader_id
361 video_uploader = config["video"]["owner"]["name"]
362 video_uploader_id = config["video"]["owner"]["url"].split('/')[-1] if config["video"]["owner"]["url"] else None
364 # Extract video thumbnail
365 video_thumbnail = config["video"].get("thumbnail")
366 if video_thumbnail is None:
367 video_thumbs = config["video"].get("thumbs")
368 if video_thumbs and isinstance(video_thumbs, dict):
369 _, video_thumbnail = sorted((int(width if width.isdigit() else 0), t_url) for (width, t_url) in video_thumbs.items())[-1]
371 # Extract video description
373 video_description = self._html_search_regex(
374 r'(?s)<div\s+class="[^"]*description[^"]*"[^>]*>(.*?)</div>',
375 webpage, 'description', default=None)
376 if not video_description:
377 video_description = self._html_search_meta(
378 'description', webpage, default=None)
379 if not video_description and mobj.group('pro'):
380 orig_webpage = self._download_webpage(
382 note='Downloading webpage for description',
385 video_description = self._html_search_meta(
386 'description', orig_webpage, default=None)
387 if not video_description and not mobj.group('player'):
388 self._downloader.report_warning('Cannot find video description')
390 # Extract video duration
391 video_duration = int_or_none(config["video"].get("duration"))
393 # Extract upload date
394 video_upload_date = None
395 mobj = re.search(r'<time[^>]+datetime="([^"]+)"', webpage)
397 video_upload_date = unified_strdate(mobj.group(1))
400 view_count = int(self._search_regex(r'UserPlays:(\d+)', webpage, 'view count'))
401 like_count = int(self._search_regex(r'UserLikes:(\d+)', webpage, 'like count'))
402 comment_count = int(self._search_regex(r'UserComments:(\d+)', webpage, 'comment count'))
403 except RegexNotFoundError:
404 # This info is only available in vimeo.com/{id} urls
410 download_request = sanitized_Request('https://vimeo.com/%s?action=load_download_config' % video_id, headers={
411 'X-Requested-With': 'XMLHttpRequest'})
412 download_data = self._download_json(download_request, video_id, fatal=False)
414 source_file = download_data.get('source_file')
415 if source_file and not source_file.get('is_cold') and not source_file.get('is_defrosting'):
417 'url': source_file['download_url'],
418 'ext': source_file['extension'].lower(),
419 'width': int_or_none(source_file.get('width')),
420 'height': int_or_none(source_file.get('height')),
421 'filesize': parse_filesize(source_file.get('size')),
422 'format_id': source_file.get('public_name', 'Original'),
425 config_files = config['video'].get('files') or config['request'].get('files', {})
426 for f in config_files.get('progressive', []):
427 video_url = f.get('url')
432 'format_id': 'http-%s' % f.get('quality'),
433 'width': int_or_none(f.get('width')),
434 'height': int_or_none(f.get('height')),
435 'fps': int_or_none(f.get('fps')),
436 'tbr': int_or_none(f.get('bitrate')),
438 m3u8_url = config_files.get('hls', {}).get('url')
440 formats.extend(self._extract_m3u8_formats(
441 m3u8_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
442 # Bitrates are completely broken. Single m3u8 may contain entries in kbps and bps
443 # at the same time without actual units specified. This lead to wrong sorting.
444 self._sort_formats(formats, field_preference=('preference', 'height', 'width', 'fps', 'format_id'))
447 text_tracks = config['request'].get('text_tracks')
449 for tt in text_tracks:
450 subtitles[tt['lang']] = [{
452 'url': 'https://vimeo.com' + tt['url'],
457 'uploader': video_uploader,
458 'uploader_id': video_uploader_id,
459 'upload_date': video_upload_date,
460 'title': video_title,
461 'thumbnail': video_thumbnail,
462 'description': video_description,
463 'duration': video_duration,
466 'view_count': view_count,
467 'like_count': like_count,
468 'comment_count': comment_count,
469 'subtitles': subtitles,
473 class VimeoChannelIE(VimeoBaseInfoExtractor):
474 IE_NAME = 'vimeo:channel'
475 _VALID_URL = r'https://vimeo\.com/channels/(?P<id>[^/?#]+)/?(?:$|[?#])'
476 _MORE_PAGES_INDICATOR = r'<a.+?rel="next"'
478 _TITLE_RE = r'<link rel="alternate"[^>]+?title="(.*?)"'
480 'url': 'https://vimeo.com/channels/tributes',
483 'title': 'Vimeo Tributes',
485 'playlist_mincount': 25,
488 def _page_url(self, base_url, pagenum):
489 return '%s/videos/page:%d/' % (base_url, pagenum)
491 def _extract_list_title(self, webpage):
492 return self._TITLE or self._html_search_regex(self._TITLE_RE, webpage, 'list title')
494 def _login_list_password(self, page_url, list_id, webpage):
495 login_form = self._search_regex(
496 r'(?s)<form[^>]+?id="pw_form"(.*?)</form>',
497 webpage, 'login form', default=None)
501 password = self._downloader.params.get('videopassword', None)
503 raise ExtractorError('This album is protected by a password, use the --video-password option', expected=True)
504 fields = self._hidden_inputs(login_form)
505 token, vuid = self._extract_xsrft_and_vuid(webpage)
506 fields['token'] = token
507 fields['password'] = password
508 post = urlencode_postdata(encode_dict(fields))
509 password_path = self._search_regex(
510 r'action="([^"]+)"', login_form, 'password URL')
511 password_url = compat_urlparse.urljoin(page_url, password_path)
512 password_request = sanitized_Request(password_url, post)
513 password_request.add_header('Content-type', 'application/x-www-form-urlencoded')
514 self._set_vimeo_cookie('vuid', vuid)
515 self._set_vimeo_cookie('xsrft', token)
517 return self._download_webpage(
518 password_request, list_id,
519 'Verifying the password', 'Wrong password')
521 def _title_and_entries(self, list_id, base_url):
522 for pagenum in itertools.count(1):
523 page_url = self._page_url(base_url, pagenum)
524 webpage = self._download_webpage(
526 'Downloading page %s' % pagenum)
529 webpage = self._login_list_password(page_url, list_id, webpage)
530 yield self._extract_list_title(webpage)
532 for video_id in re.findall(r'id="clip_(\d+?)"', webpage):
533 yield self.url_result('https://vimeo.com/%s' % video_id, 'Vimeo')
535 if re.search(self._MORE_PAGES_INDICATOR, webpage, re.DOTALL) is None:
538 def _extract_videos(self, list_id, base_url):
539 title_and_entries = self._title_and_entries(list_id, base_url)
540 list_title = next(title_and_entries)
541 return self.playlist_result(title_and_entries, list_id, list_title)
543 def _real_extract(self, url):
544 mobj = re.match(self._VALID_URL, url)
545 channel_id = mobj.group('id')
546 return self._extract_videos(channel_id, 'https://vimeo.com/channels/%s' % channel_id)
549 class VimeoUserIE(VimeoChannelIE):
550 IE_NAME = 'vimeo:user'
551 _VALID_URL = r'https://vimeo\.com/(?!(?:[0-9]+|watchlater)(?:$|[?#/]))(?P<name>[^/]+)(?:/videos|[#?]|$)'
552 _TITLE_RE = r'<a[^>]+?class="user">([^<>]+?)</a>'
554 'url': 'https://vimeo.com/nkistudio/videos',
559 'playlist_mincount': 66,
562 def _real_extract(self, url):
563 mobj = re.match(self._VALID_URL, url)
564 name = mobj.group('name')
565 return self._extract_videos(name, 'https://vimeo.com/%s' % name)
568 class VimeoAlbumIE(VimeoChannelIE):
569 IE_NAME = 'vimeo:album'
570 _VALID_URL = r'https://vimeo\.com/album/(?P<id>\d+)'
571 _TITLE_RE = r'<header id="page_header">\n\s*<h1>(.*?)</h1>'
573 'url': 'https://vimeo.com/album/2632481',
576 'title': 'Staff Favorites: November 2013',
578 'playlist_mincount': 13,
580 'note': 'Password-protected album',
581 'url': 'https://vimeo.com/album/3253534',
588 'videopassword': 'youtube-dl',
592 def _page_url(self, base_url, pagenum):
593 return '%s/page:%d/' % (base_url, pagenum)
595 def _real_extract(self, url):
596 album_id = self._match_id(url)
597 return self._extract_videos(album_id, 'https://vimeo.com/album/%s' % album_id)
600 class VimeoGroupsIE(VimeoAlbumIE):
601 IE_NAME = 'vimeo:group'
602 _VALID_URL = r'https://vimeo\.com/groups/(?P<name>[^/]+)(?:/(?!videos?/\d+)|$)'
604 'url': 'https://vimeo.com/groups/rolexawards',
607 'title': 'Rolex Awards for Enterprise',
609 'playlist_mincount': 73,
612 def _extract_list_title(self, webpage):
613 return self._og_search_title(webpage)
615 def _real_extract(self, url):
616 mobj = re.match(self._VALID_URL, url)
617 name = mobj.group('name')
618 return self._extract_videos(name, 'https://vimeo.com/groups/%s' % name)
621 class VimeoReviewIE(InfoExtractor):
622 IE_NAME = 'vimeo:review'
623 IE_DESC = 'Review pages on vimeo'
624 _VALID_URL = r'https://vimeo\.com/[^/]+/review/(?P<id>[^/]+)'
626 'url': 'https://vimeo.com/user21297594/review/75524534/3c257a1b5d',
627 'md5': 'c507a72f780cacc12b2248bb4006d253',
631 'title': "DICK HARDWICK 'Comedian'",
632 'uploader': 'Richard Hardwick',
635 'note': 'video player needs Referer',
636 'url': 'https://vimeo.com/user22258446/review/91613211/13f927e053',
637 'md5': '6295fdab8f4bf6a002d058b2c6dce276',
641 'title': 're:(?i)^Death by dogma versus assembling agile . Sander Hoogendoorn',
642 'uploader': 'DevWeek Events',
644 'thumbnail': 're:^https?://.*\.jpg$',
648 def _real_extract(self, url):
649 mobj = re.match(self._VALID_URL, url)
650 video_id = mobj.group('id')
651 player_url = 'https://player.vimeo.com/player/' + video_id
652 return self.url_result(player_url, 'Vimeo', video_id)
655 class VimeoWatchLaterIE(VimeoChannelIE):
656 IE_NAME = 'vimeo:watchlater'
657 IE_DESC = 'Vimeo watch later list, "vimeowatchlater" keyword (requires authentication)'
658 _VALID_URL = r'https://vimeo\.com/(?:home/)?watchlater|:vimeowatchlater'
659 _TITLE = 'Watch Later'
660 _LOGIN_REQUIRED = True
662 'url': 'https://vimeo.com/watchlater',
663 'only_matching': True,
666 def _real_initialize(self):
669 def _page_url(self, base_url, pagenum):
670 url = '%s/page:%d/' % (base_url, pagenum)
671 request = sanitized_Request(url)
672 # Set the header to get a partial html page with the ids,
673 # the normal page doesn't contain them.
674 request.add_header('X-Requested-With', 'XMLHttpRequest')
677 def _real_extract(self, url):
678 return self._extract_videos('watchlater', 'https://vimeo.com/watchlater')
681 class VimeoLikesIE(InfoExtractor):
682 _VALID_URL = r'https://(?:www\.)?vimeo\.com/user(?P<id>[0-9]+)/likes/?(?:$|[?#]|sort:)'
683 IE_NAME = 'vimeo:likes'
684 IE_DESC = 'Vimeo user likes'
686 'url': 'https://vimeo.com/user755559/likes/',
687 'playlist_mincount': 293,
689 'id': 'user755559_likes',
690 "description": "See all the videos urza likes",
691 "title": 'Videos urza likes',
695 def _real_extract(self, url):
696 user_id = self._match_id(url)
697 webpage = self._download_webpage(url, user_id)
698 page_count = self._int(
700 r'''(?x)<li><a\s+href="[^"]+"\s+data-page="([0-9]+)">
701 .*?</a></li>\s*<li\s+class="pagination_next">
702 ''', webpage, 'page count'),
703 'page count', fatal=True)
705 title = self._html_search_regex(
706 r'(?s)<h1>(.+?)</h1>', webpage, 'title', fatal=False)
707 description = self._html_search_meta('description', webpage)
710 page_url = 'https://vimeo.com/user%s/likes/page:%d/sort:date' % (
712 webpage = self._download_webpage(
714 note='Downloading page %d/%d' % (idx + 1, page_count))
715 video_list = self._search_regex(
716 r'(?s)<ol class="js-browse_list[^"]+"[^>]*>(.*?)</ol>',
717 webpage, 'video content')
719 r'<li[^>]*>\s*<a\s+href="([^"]+)"', video_list)
723 'url': compat_urlparse.urljoin(page_url, path),
726 pl = InAdvancePagedList(_get_page, page_count, PAGE_SIZE)
730 'id': 'user%s_likes' % user_id,
732 'description': description,