2 from __future__ import unicode_literals
9 from .common import InfoExtractor
10 from .subtitles import SubtitlesInfoExtractor
11 from ..compat import (
14 compat_urllib_request,
29 class VimeoBaseInfoExtractor(InfoExtractor):
30 _NETRC_MACHINE = 'vimeo'
31 _LOGIN_REQUIRED = False
34 (username, password) = self._get_login_info()
36 if self._LOGIN_REQUIRED:
37 raise ExtractorError('No login info available, needed for using %s.' % self.IE_NAME, expected=True)
40 login_url = 'https://vimeo.com/log_in'
41 webpage = self._download_webpage(login_url, None, False)
42 token = self._search_regex(r'xsrft: \'(.*?)\'', webpage, 'login token')
43 data = urlencode_postdata({
50 login_request = compat_urllib_request.Request(login_url, data)
51 login_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
52 login_request.add_header('Cookie', 'xsrft=%s' % token)
53 self._download_webpage(login_request, None, False, 'Wrong login info')
56 class VimeoIE(VimeoBaseInfoExtractor, SubtitlesInfoExtractor):
57 """Information extractor for vimeo.com."""
59 # _VALID_URL matches Vimeo URLs
62 (?:(?:www|(?P<player>player))\.)?
63 vimeo(?P<pro>pro)?\.com/
64 (?!channels/[^/?#]+/?(?:$|[?#])|album/)
66 (?:(?:play_redirect_hls|moogaloop\.swf)\?clip_id=)?
69 /?(?:[?&].*)?(?:[#].*)?$'''
73 'url': 'http://vimeo.com/56015672#at=0',
74 'md5': '8879b6cc097e987f02484baf890129e5',
78 "upload_date": "20121220",
79 "description": "This is a test case for youtube-dl.\nFor more information, see github.com/rg3/youtube-dl\nTest chars: \u2605 \" ' \u5e78 / \\ \u00e4 \u21ad \U0001d550",
80 "uploader_id": "user7108434",
81 "uploader": "Filippo Valsorda",
82 "title": "youtube-dl test video - \u2605 \" ' \u5e78 / \\ \u00e4 \u21ad \U0001d550",
87 'url': 'http://vimeopro.com/openstreetmapus/state-of-the-map-us-2013/video/68093876',
88 'md5': '3b5ca6aa22b60dfeeadf50b72e44ed82',
89 'note': 'Vimeo Pro video (#1197)',
93 'uploader_id': 'openstreetmapus',
94 'uploader': 'OpenStreetMap US',
95 'title': 'Andy Allan - Putting the Carto into OpenStreetMap Cartography',
96 'description': 'md5:380943ec71b89736ff4bf27183233d09',
101 'url': 'http://player.vimeo.com/video/54469442',
102 'md5': '619b811a4417aa4abe78dc653becf511',
103 'note': 'Videos that embed the url in the player page',
107 'title': 'Kathy Sierra: Building the minimum Badass User, Business of Software 2012',
108 'uploader': 'The BLN & Business of Software',
109 'uploader_id': 'theblnbusinessofsoftware',
115 'url': 'http://vimeo.com/68375962',
116 'md5': 'aaf896bdb7ddd6476df50007a0ac0ae7',
117 'note': 'Video protected with password',
121 'title': 'youtube-dl password protected test video',
122 'upload_date': '20130614',
123 'uploader_id': 'user18948128',
124 'uploader': 'Jaime Marquínez Ferrándiz',
126 '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.',
129 'videopassword': 'youtube-dl',
133 'url': 'http://vimeo.com/channels/keypeele/75629013',
134 'md5': '2f86a05afe9d7abc0b9126d229bbe15d',
135 'note': 'Video is freely available via original URL '
136 'and protected with password when accessed via http://vimeo.com/75629013',
140 'title': 'Key & Peele: Terrorist Interrogation',
141 'description': 'md5:8678b246399b070816b12313e8b4eb5c',
142 'uploader_id': 'atencio',
143 'uploader': 'Peter Atencio',
148 'url': 'http://vimeo.com/76979871',
149 'md5': '3363dd6ffebe3784d56f4132317fd446',
150 'note': 'Video with subtitles',
154 'title': 'The New Vimeo Player (You Know, For Videos)',
155 'description': 'md5:2ec900bf97c3f389378a96aee11260ea',
156 'upload_date': '20131015',
157 'uploader_id': 'staff',
158 'uploader': 'Vimeo Staff',
163 # from https://www.ouya.tv/game/Pier-Solar-and-the-Great-Architects/
164 'url': 'https://player.vimeo.com/video/98044508',
165 'note': 'The js code contains assignments to the same variable as the config',
169 'title': 'Pier Solar OUYA Official Trailer',
170 'uploader': 'Tulio Gonçalves',
171 'uploader_id': 'user28849593',
176 def _verify_video_password(self, url, video_id, webpage):
177 password = self._downloader.params.get('videopassword', None)
179 raise ExtractorError('This video is protected by a password, use the --video-password option', expected=True)
180 token = self._search_regex(r'xsrft: \'(.*?)\'', webpage, 'login token')
181 data = compat_urllib_parse.urlencode({
182 'password': password,
185 # I didn't manage to use the password with https
186 if url.startswith('https'):
187 pass_url = url.replace('https', 'http')
190 password_request = compat_urllib_request.Request(pass_url + '/password', data)
191 password_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
192 password_request.add_header('Cookie', 'xsrft=%s' % token)
193 return self._download_webpage(
194 password_request, video_id,
195 'Verifying the password', 'Wrong password')
197 def _verify_player_video_password(self, url, video_id):
198 password = self._downloader.params.get('videopassword', None)
200 raise ExtractorError('This video is protected by a password, use the --video-password option')
201 data = compat_urllib_parse.urlencode({'password': password})
202 pass_url = url + '/check-password'
203 password_request = compat_urllib_request.Request(pass_url, data)
204 password_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
205 return self._download_json(
206 password_request, video_id,
207 'Verifying the password',
210 def _real_initialize(self):
213 def _real_extract(self, url):
214 url, data = unsmuggle_url(url)
215 headers = std_headers
217 headers = headers.copy()
219 if 'Referer' not in headers:
220 headers['Referer'] = url
222 # Extract ID from URL
223 mobj = re.match(self._VALID_URL, url)
224 video_id = mobj.group('id')
226 if mobj.group('pro') or mobj.group('player'):
227 url = 'http://player.vimeo.com/video/' + video_id
229 password = self._downloader.params.get('videopassword', None)
231 headers['Cookie'] = '%s_password=%s' % (
232 video_id, hashlib.md5(password.encode('utf-8')).hexdigest())
234 # Retrieve video webpage to extract further information
235 request = compat_urllib_request.Request(url, None, headers)
237 webpage = self._download_webpage(request, video_id)
238 except ExtractorError as ee:
239 if isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 403:
240 errmsg = ee.cause.read()
241 if b'Because of its privacy settings, this video cannot be played here' in errmsg:
242 raise ExtractorError(
243 'Cannot download embed-only video without embedding '
244 'URL. Please call youtube-dl with the URL of the page '
245 'that embeds this video.',
249 # Now we begin extracting as much information as we can from what we
250 # retrieved. First we extract the information common to all extractors,
251 # and latter we extract those that are Vimeo specific.
252 self.report_extraction(video_id)
254 # Extract the config JSON
257 config_url = self._html_search_regex(
258 r' data-config-url="(.+?)"', webpage, 'config URL')
259 config_json = self._download_webpage(config_url, video_id)
260 config = json.loads(config_json)
261 except RegexNotFoundError:
262 # For pro videos or player.vimeo.com urls
263 # We try to find out to which variable is assigned the config dic
264 m_variable_name = re.search('(\w)\.video\.id', webpage)
265 if m_variable_name is not None:
266 config_re = r'%s=({[^}].+?});' % re.escape(m_variable_name.group(1))
268 config_re = [r' = {config:({.+?}),assets:', r'(?:[abc])=({.+?});']
269 config = self._search_regex(config_re, webpage, 'info section',
271 config = json.loads(config)
272 except Exception as e:
273 if re.search('The creator of this video has not given you permission to embed it on this domain.', webpage):
274 raise ExtractorError('The author has restricted the access to this video, try with the "--referer" option')
276 if re.search(r'<form[^>]+?id="pw_form"', webpage) is not None:
277 if data and '_video_password_verified' in data:
278 raise ExtractorError('video password verification failed!')
279 self._verify_video_password(url, video_id, webpage)
280 return self._real_extract(
281 smuggle_url(url, {'_video_password_verified': 'verified'}))
283 raise ExtractorError('Unable to extract info section',
286 if config.get('view') == 4:
287 config = self._verify_player_video_password(url, video_id)
290 video_title = config["video"]["title"]
292 # Extract uploader and uploader_id
293 video_uploader = config["video"]["owner"]["name"]
294 video_uploader_id = config["video"]["owner"]["url"].split('/')[-1] if config["video"]["owner"]["url"] else None
296 # Extract video thumbnail
297 video_thumbnail = config["video"].get("thumbnail")
298 if video_thumbnail is None:
299 video_thumbs = config["video"].get("thumbs")
300 if video_thumbs and isinstance(video_thumbs, dict):
301 _, video_thumbnail = sorted((int(width if width.isdigit() else 0), t_url) for (width, t_url) in video_thumbs.items())[-1]
303 # Extract video description
305 video_description = self._html_search_regex(
306 r'(?s)<div\s+class="[^"]*description[^"]*"[^>]*>(.*?)</div>',
307 webpage, 'description', default=None)
308 if not video_description:
309 video_description = self._html_search_meta(
310 'description', webpage, default=None)
311 if not video_description and mobj.group('pro'):
312 orig_webpage = self._download_webpage(
314 note='Downloading webpage for description',
317 video_description = self._html_search_meta(
318 'description', orig_webpage, default=None)
319 if not video_description and not mobj.group('player'):
320 self._downloader.report_warning('Cannot find video description')
322 # Extract video duration
323 video_duration = int_or_none(config["video"].get("duration"))
325 # Extract upload date
326 video_upload_date = None
327 mobj = re.search(r'<meta itemprop="dateCreated" content="(\d{4})-(\d{2})-(\d{2})T', webpage)
329 video_upload_date = mobj.group(1) + mobj.group(2) + mobj.group(3)
332 view_count = int(self._search_regex(r'UserPlays:(\d+)', webpage, 'view count'))
333 like_count = int(self._search_regex(r'UserLikes:(\d+)', webpage, 'like count'))
334 comment_count = int(self._search_regex(r'UserComments:(\d+)', webpage, 'comment count'))
335 except RegexNotFoundError:
336 # This info is only available in vimeo.com/{id} urls
341 # Vimeo specific: extract request signature and timestamp
342 sig = config['request']['signature']
343 timestamp = config['request']['timestamp']
345 # Vimeo specific: extract video codec and quality information
346 # First consider quality, then codecs, then take everything
347 codecs = [('vp6', 'flv'), ('vp8', 'flv'), ('h264', 'mp4')]
348 files = {'hd': [], 'sd': [], 'other': []}
349 config_files = config["video"].get("files") or config["request"].get("files")
350 for codec_name, codec_extension in codecs:
351 for quality in config_files.get(codec_name, []):
352 format_id = '-'.join((codec_name, quality)).lower()
353 key = quality if quality in files else 'other'
355 if isinstance(config_files[codec_name], dict):
356 file_info = config_files[codec_name][quality]
357 video_url = file_info.get('url')
360 if video_url is None:
361 video_url = "http://player.vimeo.com/play_redirect?clip_id=%s&sig=%s&time=%s&quality=%s&codecs=%s&type=moogaloop_local&embed_location=" \
362 % (video_id, sig, timestamp, quality, codec_name.upper())
365 'ext': codec_extension,
367 'format_id': format_id,
368 'width': file_info.get('width'),
369 'height': file_info.get('height'),
372 for key in ('other', 'sd', 'hd'):
373 formats += files[key]
374 if len(formats) == 0:
375 raise ExtractorError('No known codec found')
378 text_tracks = config['request'].get('text_tracks')
380 for tt in text_tracks:
381 subtitles[tt['lang']] = 'http://vimeo.com' + tt['url']
383 video_subtitles = self.extract_subtitles(video_id, subtitles)
384 if self._downloader.params.get('listsubtitles', False):
385 self._list_available_subtitles(video_id, subtitles)
390 'uploader': video_uploader,
391 'uploader_id': video_uploader_id,
392 'upload_date': video_upload_date,
393 'title': video_title,
394 'thumbnail': video_thumbnail,
395 'description': video_description,
396 'duration': video_duration,
399 'view_count': view_count,
400 'like_count': like_count,
401 'comment_count': comment_count,
402 'subtitles': video_subtitles,
406 class VimeoChannelIE(InfoExtractor):
407 IE_NAME = 'vimeo:channel'
408 _VALID_URL = r'https?://vimeo\.com/channels/(?P<id>[^/?#]+)/?(?:$|[?#])'
409 _MORE_PAGES_INDICATOR = r'<a.+?rel="next"'
410 _TITLE_RE = r'<link rel="alternate"[^>]+?title="(.*?)"'
412 'url': 'http://vimeo.com/channels/tributes',
415 'title': 'Vimeo Tributes',
417 'playlist_mincount': 25,
420 def _page_url(self, base_url, pagenum):
421 return '%s/videos/page:%d/' % (base_url, pagenum)
423 def _extract_list_title(self, webpage):
424 return self._html_search_regex(self._TITLE_RE, webpage, 'list title')
426 def _login_list_password(self, page_url, list_id, webpage):
427 login_form = self._search_regex(
428 r'(?s)<form[^>]+?id="pw_form"(.*?)</form>',
429 webpage, 'login form', default=None)
433 password = self._downloader.params.get('videopassword', None)
435 raise ExtractorError('This album is protected by a password, use the --video-password option', expected=True)
436 fields = dict(re.findall(r'''(?x)<input\s+
441 token = self._search_regex(r'xsrft: \'(.*?)\'', webpage, 'login token')
442 fields['token'] = token
443 fields['password'] = password
444 post = compat_urllib_parse.urlencode(fields)
445 password_path = self._search_regex(
446 r'action="([^"]+)"', login_form, 'password URL')
447 password_url = compat_urlparse.urljoin(page_url, password_path)
448 password_request = compat_urllib_request.Request(password_url, post)
449 password_request.add_header('Content-type', 'application/x-www-form-urlencoded')
450 self._set_cookie('vimeo.com', 'xsrft', token)
452 return self._download_webpage(
453 password_request, list_id,
454 'Verifying the password', 'Wrong password')
456 def _extract_videos(self, list_id, base_url):
458 for pagenum in itertools.count(1):
459 page_url = self._page_url(base_url, pagenum)
460 webpage = self._download_webpage(
462 'Downloading page %s' % pagenum)
465 webpage = self._login_list_password(page_url, list_id, webpage)
467 video_ids.extend(re.findall(r'id="clip_(\d+?)"', webpage))
468 if re.search(self._MORE_PAGES_INDICATOR, webpage, re.DOTALL) is None:
471 entries = [self.url_result('http://vimeo.com/%s' % video_id, 'Vimeo')
472 for video_id in video_ids]
473 return {'_type': 'playlist',
475 'title': self._extract_list_title(webpage),
479 def _real_extract(self, url):
480 mobj = re.match(self._VALID_URL, url)
481 channel_id = mobj.group('id')
482 return self._extract_videos(channel_id, 'http://vimeo.com/channels/%s' % channel_id)
485 class VimeoUserIE(VimeoChannelIE):
486 IE_NAME = 'vimeo:user'
487 _VALID_URL = r'https?://vimeo\.com/(?![0-9]+(?:$|[?#/]))(?P<name>[^/]+)(?:/videos|[#?]|$)'
488 _TITLE_RE = r'<a[^>]+?class="user">([^<>]+?)</a>'
490 'url': 'http://vimeo.com/nkistudio/videos',
495 'playlist_mincount': 66,
498 def _real_extract(self, url):
499 mobj = re.match(self._VALID_URL, url)
500 name = mobj.group('name')
501 return self._extract_videos(name, 'http://vimeo.com/%s' % name)
504 class VimeoAlbumIE(VimeoChannelIE):
505 IE_NAME = 'vimeo:album'
506 _VALID_URL = r'https?://vimeo\.com/album/(?P<id>\d+)'
507 _TITLE_RE = r'<header id="page_header">\n\s*<h1>(.*?)</h1>'
509 'url': 'http://vimeo.com/album/2632481',
512 'title': 'Staff Favorites: November 2013',
514 'playlist_mincount': 13,
516 'note': 'Password-protected album',
517 'url': 'https://vimeo.com/album/3253534',
524 'videopassword': 'youtube-dl',
528 def _page_url(self, base_url, pagenum):
529 return '%s/page:%d/' % (base_url, pagenum)
531 def _real_extract(self, url):
532 album_id = self._match_id(url)
533 return self._extract_videos(album_id, 'http://vimeo.com/album/%s' % album_id)
536 class VimeoGroupsIE(VimeoAlbumIE):
537 IE_NAME = 'vimeo:group'
538 _VALID_URL = r'(?:https?://)?vimeo\.com/groups/(?P<name>[^/]+)'
540 'url': 'http://vimeo.com/groups/rolexawards',
543 'title': 'Rolex Awards for Enterprise',
545 'playlist_mincount': 73,
548 def _extract_list_title(self, webpage):
549 return self._og_search_title(webpage)
551 def _real_extract(self, url):
552 mobj = re.match(self._VALID_URL, url)
553 name = mobj.group('name')
554 return self._extract_videos(name, 'http://vimeo.com/groups/%s' % name)
557 class VimeoReviewIE(InfoExtractor):
558 IE_NAME = 'vimeo:review'
559 IE_DESC = 'Review pages on vimeo'
560 _VALID_URL = r'https?://vimeo\.com/[^/]+/review/(?P<id>[^/]+)'
562 'url': 'https://vimeo.com/user21297594/review/75524534/3c257a1b5d',
563 'md5': 'c507a72f780cacc12b2248bb4006d253',
567 'title': "DICK HARDWICK 'Comedian'",
568 'uploader': 'Richard Hardwick',
571 'note': 'video player needs Referer',
572 'url': 'http://vimeo.com/user22258446/review/91613211/13f927e053',
573 'md5': '6295fdab8f4bf6a002d058b2c6dce276',
577 'title': 're:(?i)^Death by dogma versus assembling agile . Sander Hoogendoorn',
578 'uploader': 'DevWeek Events',
580 'thumbnail': 're:^https?://.*\.jpg$',
584 def _real_extract(self, url):
585 mobj = re.match(self._VALID_URL, url)
586 video_id = mobj.group('id')
587 player_url = 'https://player.vimeo.com/player/' + video_id
588 return self.url_result(player_url, 'Vimeo', video_id)
591 class VimeoWatchLaterIE(VimeoBaseInfoExtractor, VimeoChannelIE):
592 IE_NAME = 'vimeo:watchlater'
593 IE_DESC = 'Vimeo watch later list, "vimeowatchlater" keyword (requires authentication)'
594 _VALID_URL = r'https?://vimeo\.com/home/watchlater|:vimeowatchlater'
595 _LOGIN_REQUIRED = True
596 _TITLE_RE = r'href="/home/watchlater".*?>(.*?)<'
598 'url': 'http://vimeo.com/home/watchlater',
599 'only_matching': True,
602 def _real_initialize(self):
605 def _page_url(self, base_url, pagenum):
606 url = '%s/page:%d/' % (base_url, pagenum)
607 request = compat_urllib_request.Request(url)
608 # Set the header to get a partial html page with the ids,
609 # the normal page doesn't contain them.
610 request.add_header('X-Requested-With', 'XMLHttpRequest')
613 def _real_extract(self, url):
614 return self._extract_videos('watchlater', 'https://vimeo.com/home/watchlater')
617 class VimeoLikesIE(InfoExtractor):
618 _VALID_URL = r'https?://(?:www\.)?vimeo\.com/user(?P<id>[0-9]+)/likes/?(?:$|[?#]|sort:)'
619 IE_NAME = 'vimeo:likes'
620 IE_DESC = 'Vimeo user likes'
622 'url': 'https://vimeo.com/user755559/likes/',
623 'playlist_mincount': 293,
625 'id': 'user755559_likes',
626 "description": "See all the videos urza likes",
627 "title": 'Videos urza likes',
631 def _real_extract(self, url):
632 user_id = self._match_id(url)
633 webpage = self._download_webpage(url, user_id)
634 page_count = self._int(
636 r'''(?x)<li><a\s+href="[^"]+"\s+data-page="([0-9]+)">
637 .*?</a></li>\s*<li\s+class="pagination_next">
638 ''', webpage, 'page count'),
639 'page count', fatal=True)
641 title = self._html_search_regex(
642 r'(?s)<h1>(.+?)</h1>', webpage, 'title', fatal=False)
643 description = self._html_search_meta('description', webpage)
646 page_url = '%s//vimeo.com/user%s/likes/page:%d/sort:date' % (
647 self.http_scheme(), user_id, idx + 1)
648 webpage = self._download_webpage(
650 note='Downloading page %d/%d' % (idx + 1, page_count))
651 video_list = self._search_regex(
652 r'(?s)<ol class="js-browse_list[^"]+"[^>]*>(.*?)</ol>',
653 webpage, 'video content')
655 r'<li[^>]*>\s*<a\s+href="([^"]+)"', video_list)
659 'url': compat_urlparse.urljoin(page_url, path),
662 pl = InAdvancePagedList(_get_page, page_count, PAGE_SIZE)
666 'id': 'user%s_likes' % user_id,
668 'description': description,