2 from __future__ import unicode_literals
8 from .common import InfoExtractor
12 compat_urllib_request,
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({
50 login_request = compat_urllib_request.Request(self._LOGIN_URL, data)
51 login_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
52 login_request.add_header('Cookie', 'vuid=%s' % vuid)
53 login_request.add_header('Referer', self._LOGIN_URL)
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')
66 class VimeoIE(VimeoBaseInfoExtractor):
67 """Information extractor for vimeo.com."""
69 # _VALID_URL matches Vimeo URLs
72 (?:(?:www|(?P<player>player))\.)?
73 vimeo(?P<pro>pro)?\.com/
74 (?!channels/[^/?#]+/?(?:$|[?#])|album/)
76 (?:(?:play_redirect_hls|moogaloop\.swf)\?clip_id=)?
79 /?(?:[?&].*)?(?:[#].*)?$'''
83 'url': 'http://vimeo.com/56015672#at=0',
84 'md5': '8879b6cc097e987f02484baf890129e5',
88 'title': "youtube-dl test video - \u2605 \" ' \u5e78 / \\ \u00e4 \u21ad \U0001d550",
89 'description': 'md5:2d3305bad981a06ff79f027f19865021',
90 'upload_date': '20121220',
91 'uploader_id': 'user7108434',
92 'uploader': 'Filippo Valsorda',
97 'url': 'http://vimeopro.com/openstreetmapus/state-of-the-map-us-2013/video/68093876',
98 'md5': '3b5ca6aa22b60dfeeadf50b72e44ed82',
99 'note': 'Vimeo Pro video (#1197)',
103 'uploader_id': 'openstreetmapus',
104 'uploader': 'OpenStreetMap US',
105 'title': 'Andy Allan - Putting the Carto into OpenStreetMap Cartography',
106 'description': 'md5:fd69a7b8d8c34a4e1d2ec2e4afd6ec30',
111 'url': 'http://player.vimeo.com/video/54469442',
112 'md5': '619b811a4417aa4abe78dc653becf511',
113 'note': 'Videos that embed the url in the player page',
117 'title': 'Kathy Sierra: Building the minimum Badass User, Business of Software 2012',
118 'uploader': 'The BLN & Business of Software',
119 'uploader_id': 'theblnbusinessofsoftware',
125 'url': 'http://vimeo.com/68375962',
126 'md5': 'aaf896bdb7ddd6476df50007a0ac0ae7',
127 'note': 'Video protected with password',
131 'title': 'youtube-dl password protected test video',
132 'upload_date': '20130614',
133 'uploader_id': 'user18948128',
134 'uploader': 'Jaime Marquínez Ferrándiz',
136 '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 who love them.',
139 'videopassword': 'youtube-dl',
143 'url': 'http://vimeo.com/channels/keypeele/75629013',
144 'md5': '2f86a05afe9d7abc0b9126d229bbe15d',
145 'note': 'Video is freely available via original URL '
146 'and protected with password when accessed via http://vimeo.com/75629013',
150 'title': 'Key & Peele: Terrorist Interrogation',
151 'description': 'md5:8678b246399b070816b12313e8b4eb5c',
152 'uploader_id': 'atencio',
153 'uploader': 'Peter Atencio',
154 'upload_date': '20130927',
159 'url': 'http://vimeo.com/76979871',
160 'note': 'Video with subtitles',
164 'title': 'The New Vimeo Player (You Know, For Videos)',
165 'description': 'md5:2ec900bf97c3f389378a96aee11260ea',
166 'upload_date': '20131015',
167 'uploader_id': 'staff',
168 'uploader': 'Vimeo Staff',
173 # from https://www.ouya.tv/game/Pier-Solar-and-the-Great-Architects/
174 'url': 'https://player.vimeo.com/video/98044508',
175 'note': 'The js code contains assignments to the same variable as the config',
179 'title': 'Pier Solar OUYA Official Trailer',
180 'uploader': 'Tulio Gonçalves',
181 'uploader_id': 'user28849593',
187 def _extract_vimeo_url(url, webpage):
188 # Look for embedded (iframe) Vimeo player
190 r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/.+?)\1', webpage)
192 player_url = unescapeHTML(mobj.group('url'))
193 surl = smuggle_url(player_url, {'Referer': url})
195 # Look for embedded (swf embed) Vimeo player
197 r'<embed[^>]+?src="((?:https?:)?//(?:www\.)?vimeo\.com/moogaloop\.swf.+?)"', webpage)
201 def _verify_video_password(self, url, video_id, webpage):
202 password = self._downloader.params.get('videopassword', None)
204 raise ExtractorError('This video is protected by a password, use the --video-password option', expected=True)
205 token, vuid = self._extract_xsrft_and_vuid(webpage)
206 data = urlencode_postdata({
207 'password': password,
210 if url.startswith('http://'):
211 # vimeo only supports https now, but the user can give an http url
212 url = url.replace('http://', 'https://')
213 password_request = compat_urllib_request.Request(url + '/password', data)
214 password_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
215 password_request.add_header('Cookie', 'clip_test2=1; vuid=%s' % vuid)
216 password_request.add_header('Referer', url)
217 return self._download_webpage(
218 password_request, video_id,
219 'Verifying the password', 'Wrong password')
221 def _verify_player_video_password(self, url, video_id):
222 password = self._downloader.params.get('videopassword', None)
224 raise ExtractorError('This video is protected by a password, use the --video-password option')
225 data = compat_urllib_parse.urlencode({'password': password})
226 pass_url = url + '/check-password'
227 password_request = compat_urllib_request.Request(pass_url, data)
228 password_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
229 return self._download_json(
230 password_request, video_id,
231 'Verifying the password',
234 def _real_initialize(self):
237 def _real_extract(self, url):
238 url, data = unsmuggle_url(url)
239 headers = std_headers
241 headers = headers.copy()
243 if 'Referer' not in headers:
244 headers['Referer'] = url
246 # Extract ID from URL
247 mobj = re.match(self._VALID_URL, url)
248 video_id = mobj.group('id')
250 if mobj.group('pro') or mobj.group('player'):
251 url = 'https://player.vimeo.com/video/' + video_id
253 url = 'https://vimeo.com/' + video_id
255 # Retrieve video webpage to extract further information
256 request = compat_urllib_request.Request(url, None, headers)
258 webpage = self._download_webpage(request, video_id)
259 except ExtractorError as ee:
260 if isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 403:
261 errmsg = ee.cause.read()
262 if b'Because of its privacy settings, this video cannot be played here' in errmsg:
263 raise ExtractorError(
264 'Cannot download embed-only video without embedding '
265 'URL. Please call youtube-dl with the URL of the page '
266 'that embeds this video.',
270 # Now we begin extracting as much information as we can from what we
271 # retrieved. First we extract the information common to all extractors,
272 # and latter we extract those that are Vimeo specific.
273 self.report_extraction(video_id)
275 vimeo_config = self._search_regex(
276 r'vimeo\.config\s*=\s*({.+?});', webpage,
277 'vimeo config', default=None)
279 seed_status = self._parse_json(vimeo_config, video_id).get('seed_status', {})
280 if seed_status.get('state') == 'failed':
281 raise ExtractorError(
282 '%s returned error: %s' % (self.IE_NAME, seed_status['title']),
285 # Extract the config JSON
288 config_url = self._html_search_regex(
289 r' data-config-url="(.+?)"', webpage, 'config URL')
290 config_json = self._download_webpage(config_url, video_id)
291 config = json.loads(config_json)
292 except RegexNotFoundError:
293 # For pro videos or player.vimeo.com urls
294 # We try to find out to which variable is assigned the config dic
295 m_variable_name = re.search('(\w)\.video\.id', webpage)
296 if m_variable_name is not None:
297 config_re = r'%s=({[^}].+?});' % re.escape(m_variable_name.group(1))
299 config_re = [r' = {config:({.+?}),assets:', r'(?:[abc])=({.+?});']
300 config = self._search_regex(config_re, webpage, 'info section',
302 config = json.loads(config)
303 except Exception as e:
304 if re.search('The creator of this video has not given you permission to embed it on this domain.', webpage):
305 raise ExtractorError('The author has restricted the access to this video, try with the "--referer" option')
307 if re.search(r'<form[^>]+?id="pw_form"', webpage) is not None:
308 if data and '_video_password_verified' in data:
309 raise ExtractorError('video password verification failed!')
310 self._verify_video_password(url, video_id, webpage)
311 return self._real_extract(
312 smuggle_url(url, {'_video_password_verified': 'verified'}))
314 raise ExtractorError('Unable to extract info section',
317 if config.get('view') == 4:
318 config = self._verify_player_video_password(url, video_id)
321 video_title = config["video"]["title"]
323 # Extract uploader and uploader_id
324 video_uploader = config["video"]["owner"]["name"]
325 video_uploader_id = config["video"]["owner"]["url"].split('/')[-1] if config["video"]["owner"]["url"] else None
327 # Extract video thumbnail
328 video_thumbnail = config["video"].get("thumbnail")
329 if video_thumbnail is None:
330 video_thumbs = config["video"].get("thumbs")
331 if video_thumbs and isinstance(video_thumbs, dict):
332 _, video_thumbnail = sorted((int(width if width.isdigit() else 0), t_url) for (width, t_url) in video_thumbs.items())[-1]
334 # Extract video description
336 video_description = self._html_search_regex(
337 r'(?s)<div\s+class="[^"]*description[^"]*"[^>]*>(.*?)</div>',
338 webpage, 'description', default=None)
339 if not video_description:
340 video_description = self._html_search_meta(
341 'description', webpage, default=None)
342 if not video_description and mobj.group('pro'):
343 orig_webpage = self._download_webpage(
345 note='Downloading webpage for description',
348 video_description = self._html_search_meta(
349 'description', orig_webpage, default=None)
350 if not video_description and not mobj.group('player'):
351 self._downloader.report_warning('Cannot find video description')
353 # Extract video duration
354 video_duration = int_or_none(config["video"].get("duration"))
356 # Extract upload date
357 video_upload_date = None
358 mobj = re.search(r'<time[^>]+datetime="([^"]+)"', webpage)
360 video_upload_date = unified_strdate(mobj.group(1))
363 view_count = int(self._search_regex(r'UserPlays:(\d+)', webpage, 'view count'))
364 like_count = int(self._search_regex(r'UserLikes:(\d+)', webpage, 'like count'))
365 comment_count = int(self._search_regex(r'UserComments:(\d+)', webpage, 'comment count'))
366 except RegexNotFoundError:
367 # This info is only available in vimeo.com/{id} urls
372 # Vimeo specific: extract request signature and timestamp
373 sig = config['request']['signature']
374 timestamp = config['request']['timestamp']
376 # Vimeo specific: extract video codec and quality information
377 # First consider quality, then codecs, then take everything
378 codecs = [('vp6', 'flv'), ('vp8', 'flv'), ('h264', 'mp4')]
379 files = {'hd': [], 'sd': [], 'other': []}
380 config_files = config["video"].get("files") or config["request"].get("files")
381 for codec_name, codec_extension in codecs:
382 for quality in config_files.get(codec_name, []):
383 format_id = '-'.join((codec_name, quality)).lower()
384 key = quality if quality in files else 'other'
386 if isinstance(config_files[codec_name], dict):
387 file_info = config_files[codec_name][quality]
388 video_url = file_info.get('url')
391 if video_url is None:
392 video_url = "http://player.vimeo.com/play_redirect?clip_id=%s&sig=%s&time=%s&quality=%s&codecs=%s&type=moogaloop_local&embed_location=" \
393 % (video_id, sig, timestamp, quality, codec_name.upper())
396 'ext': codec_extension,
398 'format_id': format_id,
399 'width': int_or_none(file_info.get('width')),
400 'height': int_or_none(file_info.get('height')),
401 'tbr': int_or_none(file_info.get('bitrate')),
404 m3u8_url = config_files.get('hls', {}).get('all')
406 m3u8_formats = self._extract_m3u8_formats(
407 m3u8_url, video_id, 'mp4', 'm3u8_native', 0, 'hls', fatal=False)
409 formats.extend(m3u8_formats)
410 for key in ('other', 'sd', 'hd'):
411 formats += files[key]
412 self._sort_formats(formats)
415 text_tracks = config['request'].get('text_tracks')
417 for tt in text_tracks:
418 subtitles[tt['lang']] = [{
420 'url': 'https://vimeo.com' + tt['url'],
425 'uploader': video_uploader,
426 'uploader_id': video_uploader_id,
427 'upload_date': video_upload_date,
428 'title': video_title,
429 'thumbnail': video_thumbnail,
430 'description': video_description,
431 'duration': video_duration,
434 'view_count': view_count,
435 'like_count': like_count,
436 'comment_count': comment_count,
437 'subtitles': subtitles,
441 class VimeoChannelIE(VimeoBaseInfoExtractor):
442 IE_NAME = 'vimeo:channel'
443 _VALID_URL = r'https://vimeo\.com/channels/(?P<id>[^/?#]+)/?(?:$|[?#])'
444 _MORE_PAGES_INDICATOR = r'<a.+?rel="next"'
446 _TITLE_RE = r'<link rel="alternate"[^>]+?title="(.*?)"'
448 'url': 'https://vimeo.com/channels/tributes',
451 'title': 'Vimeo Tributes',
453 'playlist_mincount': 25,
456 def _page_url(self, base_url, pagenum):
457 return '%s/videos/page:%d/' % (base_url, pagenum)
459 def _extract_list_title(self, webpage):
460 return self._TITLE or self._html_search_regex(self._TITLE_RE, webpage, 'list title')
462 def _login_list_password(self, page_url, list_id, webpage):
463 login_form = self._search_regex(
464 r'(?s)<form[^>]+?id="pw_form"(.*?)</form>',
465 webpage, 'login form', default=None)
469 password = self._downloader.params.get('videopassword', None)
471 raise ExtractorError('This album is protected by a password, use the --video-password option', expected=True)
472 fields = self._hidden_inputs(login_form)
473 token, vuid = self._extract_xsrft_and_vuid(webpage)
474 fields['token'] = token
475 fields['password'] = password
476 post = urlencode_postdata(fields)
477 password_path = self._search_regex(
478 r'action="([^"]+)"', login_form, 'password URL')
479 password_url = compat_urlparse.urljoin(page_url, password_path)
480 password_request = compat_urllib_request.Request(password_url, post)
481 password_request.add_header('Content-type', 'application/x-www-form-urlencoded')
482 password_request.add_header('Cookie', 'vuid=%s' % vuid)
483 self._set_cookie('vimeo.com', 'xsrft', token)
485 return self._download_webpage(
486 password_request, list_id,
487 'Verifying the password', 'Wrong password')
489 def _extract_videos(self, list_id, base_url):
491 for pagenum in itertools.count(1):
492 page_url = self._page_url(base_url, pagenum)
493 webpage = self._download_webpage(
495 'Downloading page %s' % pagenum)
498 webpage = self._login_list_password(page_url, list_id, webpage)
500 video_ids.extend(re.findall(r'id="clip_(\d+?)"', webpage))
501 if re.search(self._MORE_PAGES_INDICATOR, webpage, re.DOTALL) is None:
504 entries = [self.url_result('https://vimeo.com/%s' % video_id, 'Vimeo')
505 for video_id in video_ids]
506 return {'_type': 'playlist',
508 'title': self._extract_list_title(webpage),
512 def _real_extract(self, url):
513 mobj = re.match(self._VALID_URL, url)
514 channel_id = mobj.group('id')
515 return self._extract_videos(channel_id, 'https://vimeo.com/channels/%s' % channel_id)
518 class VimeoUserIE(VimeoChannelIE):
519 IE_NAME = 'vimeo:user'
520 _VALID_URL = r'https://vimeo\.com/(?!(?:[0-9]+|watchlater)(?:$|[?#/]))(?P<name>[^/]+)(?:/videos|[#?]|$)'
521 _TITLE_RE = r'<a[^>]+?class="user">([^<>]+?)</a>'
523 'url': 'https://vimeo.com/nkistudio/videos',
528 'playlist_mincount': 66,
531 def _real_extract(self, url):
532 mobj = re.match(self._VALID_URL, url)
533 name = mobj.group('name')
534 return self._extract_videos(name, 'https://vimeo.com/%s' % name)
537 class VimeoAlbumIE(VimeoChannelIE):
538 IE_NAME = 'vimeo:album'
539 _VALID_URL = r'https://vimeo\.com/album/(?P<id>\d+)'
540 _TITLE_RE = r'<header id="page_header">\n\s*<h1>(.*?)</h1>'
542 'url': 'https://vimeo.com/album/2632481',
545 'title': 'Staff Favorites: November 2013',
547 'playlist_mincount': 13,
549 'note': 'Password-protected album',
550 'url': 'https://vimeo.com/album/3253534',
557 'videopassword': 'youtube-dl',
561 def _page_url(self, base_url, pagenum):
562 return '%s/page:%d/' % (base_url, pagenum)
564 def _real_extract(self, url):
565 album_id = self._match_id(url)
566 return self._extract_videos(album_id, 'https://vimeo.com/album/%s' % album_id)
569 class VimeoGroupsIE(VimeoAlbumIE):
570 IE_NAME = 'vimeo:group'
571 _VALID_URL = r'https://vimeo\.com/groups/(?P<name>[^/]+)'
573 'url': 'https://vimeo.com/groups/rolexawards',
576 'title': 'Rolex Awards for Enterprise',
578 'playlist_mincount': 73,
581 def _extract_list_title(self, webpage):
582 return self._og_search_title(webpage)
584 def _real_extract(self, url):
585 mobj = re.match(self._VALID_URL, url)
586 name = mobj.group('name')
587 return self._extract_videos(name, 'https://vimeo.com/groups/%s' % name)
590 class VimeoReviewIE(InfoExtractor):
591 IE_NAME = 'vimeo:review'
592 IE_DESC = 'Review pages on vimeo'
593 _VALID_URL = r'https://vimeo\.com/[^/]+/review/(?P<id>[^/]+)'
595 'url': 'https://vimeo.com/user21297594/review/75524534/3c257a1b5d',
596 'md5': 'c507a72f780cacc12b2248bb4006d253',
600 'title': "DICK HARDWICK 'Comedian'",
601 'uploader': 'Richard Hardwick',
604 'note': 'video player needs Referer',
605 'url': 'https://vimeo.com/user22258446/review/91613211/13f927e053',
606 'md5': '6295fdab8f4bf6a002d058b2c6dce276',
610 'title': 're:(?i)^Death by dogma versus assembling agile . Sander Hoogendoorn',
611 'uploader': 'DevWeek Events',
613 'thumbnail': 're:^https?://.*\.jpg$',
617 def _real_extract(self, url):
618 mobj = re.match(self._VALID_URL, url)
619 video_id = mobj.group('id')
620 player_url = 'https://player.vimeo.com/player/' + video_id
621 return self.url_result(player_url, 'Vimeo', video_id)
624 class VimeoWatchLaterIE(VimeoChannelIE):
625 IE_NAME = 'vimeo:watchlater'
626 IE_DESC = 'Vimeo watch later list, "vimeowatchlater" keyword (requires authentication)'
627 _VALID_URL = r'https://vimeo\.com/(?:home/)?watchlater|:vimeowatchlater'
628 _TITLE = 'Watch Later'
629 _LOGIN_REQUIRED = True
631 'url': 'https://vimeo.com/watchlater',
632 'only_matching': True,
635 def _real_initialize(self):
638 def _page_url(self, base_url, pagenum):
639 url = '%s/page:%d/' % (base_url, pagenum)
640 request = compat_urllib_request.Request(url)
641 # Set the header to get a partial html page with the ids,
642 # the normal page doesn't contain them.
643 request.add_header('X-Requested-With', 'XMLHttpRequest')
646 def _real_extract(self, url):
647 return self._extract_videos('watchlater', 'https://vimeo.com/watchlater')
650 class VimeoLikesIE(InfoExtractor):
651 _VALID_URL = r'https://(?:www\.)?vimeo\.com/user(?P<id>[0-9]+)/likes/?(?:$|[?#]|sort:)'
652 IE_NAME = 'vimeo:likes'
653 IE_DESC = 'Vimeo user likes'
655 'url': 'https://vimeo.com/user755559/likes/',
656 'playlist_mincount': 293,
658 'id': 'user755559_likes',
659 "description": "See all the videos urza likes",
660 "title": 'Videos urza likes',
664 def _real_extract(self, url):
665 user_id = self._match_id(url)
666 webpage = self._download_webpage(url, user_id)
667 page_count = self._int(
669 r'''(?x)<li><a\s+href="[^"]+"\s+data-page="([0-9]+)">
670 .*?</a></li>\s*<li\s+class="pagination_next">
671 ''', webpage, 'page count'),
672 'page count', fatal=True)
674 title = self._html_search_regex(
675 r'(?s)<h1>(.+?)</h1>', webpage, 'title', fatal=False)
676 description = self._html_search_meta('description', webpage)
679 page_url = 'https://vimeo.com/user%s/likes/page:%d/sort:date' % (
681 webpage = self._download_webpage(
683 note='Downloading page %d/%d' % (idx + 1, page_count))
684 video_list = self._search_regex(
685 r'(?s)<ol class="js-browse_list[^"]+"[^>]*>(.*?)</ol>',
686 webpage, 'video content')
688 r'<li[^>]*>\s*<a\s+href="([^"]+)"', video_list)
692 'url': compat_urlparse.urljoin(page_url, path),
695 pl = InAdvancePagedList(_get_page, page_count, PAGE_SIZE)
699 'id': 'user%s_likes' % user_id,
701 'description': description,