2 from __future__ import unicode_literals
8 from .common import InfoExtractor
9 from .subtitles import SubtitlesInfoExtractor
13 compat_urllib_request,
15 get_element_by_attribute,
25 class VimeoBaseInfoExtractor(InfoExtractor):
26 _NETRC_MACHINE = 'vimeo'
27 _LOGIN_REQUIRED = False
30 (username, password) = self._get_login_info()
32 if self._LOGIN_REQUIRED:
33 raise ExtractorError('No login info available, needed for using %s.' % self.IE_NAME, expected=True)
36 login_url = 'https://vimeo.com/log_in'
37 webpage = self._download_webpage(login_url, None, False)
38 token = self._search_regex(r'xsrft: \'(.*?)\'', webpage, 'login token')
39 data = urlencode_postdata({
46 login_request = compat_urllib_request.Request(login_url, data)
47 login_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
48 login_request.add_header('Cookie', 'xsrft=%s' % token)
49 self._download_webpage(login_request, None, False, 'Wrong login info')
52 class VimeoIE(VimeoBaseInfoExtractor, SubtitlesInfoExtractor):
53 """Information extractor for vimeo.com."""
55 # _VALID_URL matches Vimeo URLs
57 (?P<proto>(?:https?:)?//)?
58 (?:(?:www|(?P<player>player))\.)?
59 vimeo(?P<pro>pro)?\.com/
61 (?:(?:play_redirect_hls|moogaloop\.swf)\?clip_id=)?
64 /?(?:[?&].*)?(?:[#].*)?$'''
68 'url': 'http://vimeo.com/56015672#at=0',
69 'md5': '8879b6cc097e987f02484baf890129e5',
73 "upload_date": "20121220",
74 "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",
75 "uploader_id": "user7108434",
76 "uploader": "Filippo Valsorda",
77 "title": "youtube-dl test video - \u2605 \" ' \u5e78 / \\ \u00e4 \u21ad \U0001d550",
82 'url': 'http://vimeopro.com/openstreetmapus/state-of-the-map-us-2013/video/68093876',
83 'md5': '3b5ca6aa22b60dfeeadf50b72e44ed82',
84 'note': 'Vimeo Pro video (#1197)',
88 'uploader_id': 'openstreetmapus',
89 'uploader': 'OpenStreetMap US',
90 'title': 'Andy Allan - Putting the Carto into OpenStreetMap Cartography',
95 'url': 'http://player.vimeo.com/video/54469442',
96 'md5': '619b811a4417aa4abe78dc653becf511',
97 'note': 'Videos that embed the url in the player page',
101 'title': 'Kathy Sierra: Building the minimum Badass User, Business of Software 2012',
102 'uploader': 'The BLN & Business of Software',
103 'uploader_id': 'theblnbusinessofsoftware',
108 'url': 'http://vimeo.com/68375962',
109 'md5': 'aaf896bdb7ddd6476df50007a0ac0ae7',
110 'note': 'Video protected with password',
114 'title': 'youtube-dl password protected test video',
115 'upload_date': '20130614',
116 'uploader_id': 'user18948128',
117 'uploader': 'Jaime Marquínez Ferrándiz',
121 'videopassword': 'youtube-dl',
125 'url': 'http://vimeo.com/channels/keypeele/75629013',
126 'md5': '2f86a05afe9d7abc0b9126d229bbe15d',
127 'note': 'Video is freely available via original URL '
128 'and protected with password when accessed via http://vimeo.com/75629013',
132 'title': 'Key & Peele: Terrorist Interrogation',
133 'description': 'md5:8678b246399b070816b12313e8b4eb5c',
134 'uploader_id': 'atencio',
135 'uploader': 'Peter Atencio',
140 'url': 'http://vimeo.com/76979871',
141 'md5': '3363dd6ffebe3784d56f4132317fd446',
142 'note': 'Video with subtitles',
146 'title': 'The New Vimeo Player (You Know, For Videos)',
147 'description': 'md5:2ec900bf97c3f389378a96aee11260ea',
148 'upload_date': '20131015',
149 'uploader_id': 'staff',
150 'uploader': 'Vimeo Staff',
155 'note': 'video player needs Referer',
156 'url': 'http://vimeo.com/user22258446/review/91613211/13f927e053',
157 'md5': '6295fdab8f4bf6a002d058b2c6dce276',
161 'title': 'Death by dogma versus assembling agile - Sander Hoogendoorn',
162 'uploader': 'DevWeek Events',
164 'thumbnail': 're:^https?://.*\.jpg$',
170 def suitable(cls, url):
171 if VimeoChannelIE.suitable(url):
172 # Otherwise channel urls like http://vimeo.com/channels/31259 would
176 return super(VimeoIE, cls).suitable(url)
178 def _verify_video_password(self, url, video_id, webpage):
179 password = self._downloader.params.get('videopassword', None)
181 raise ExtractorError('This video is protected by a password, use the --video-password option')
182 token = self._search_regex(r'xsrft: \'(.*?)\'', webpage, 'login token')
183 data = compat_urllib_parse.urlencode({
184 'password': password,
187 # I didn't manage to use the password with https
188 if url.startswith('https'):
189 pass_url = url.replace('https', 'http')
192 password_request = compat_urllib_request.Request(pass_url + '/password', data)
193 password_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
194 password_request.add_header('Cookie', 'xsrft=%s' % token)
195 self._download_webpage(password_request, video_id,
196 'Verifying the password',
199 def _verify_player_video_password(self, url, video_id):
200 password = self._downloader.params.get('videopassword', None)
202 raise ExtractorError('This video is protected by a password, use the --video-password option')
203 data = compat_urllib_parse.urlencode({'password': password})
204 pass_url = url + '/check-password'
205 password_request = compat_urllib_request.Request(pass_url, data)
206 password_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
207 return self._download_json(
208 password_request, video_id,
209 'Verifying the password',
212 def _real_initialize(self):
215 def _real_extract(self, url):
216 url, data = unsmuggle_url(url)
217 headers = std_headers
219 headers = headers.copy()
221 if 'Referer' not in headers:
222 headers['Referer'] = url
224 # Extract ID from URL
225 mobj = re.match(self._VALID_URL, url)
226 video_id = mobj.group('id')
227 if mobj.group('pro') or mobj.group('player'):
228 url = 'http://player.vimeo.com/video/' + video_id
230 # Retrieve video webpage to extract further information
231 request = compat_urllib_request.Request(url, None, headers)
233 webpage = self._download_webpage(request, video_id)
234 except ExtractorError as ee:
235 if isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 403:
236 errmsg = ee.cause.read()
237 if b'Because of its privacy settings, this video cannot be played here' in errmsg:
238 raise ExtractorError(
239 'Cannot download embed-only video without embedding '
240 'URL. Please call youtube-dl with the URL of the page '
241 'that embeds this video.',
245 # Now we begin extracting as much information as we can from what we
246 # retrieved. First we extract the information common to all extractors,
247 # and latter we extract those that are Vimeo specific.
248 self.report_extraction(video_id)
250 # Extract the config JSON
253 config_url = self._html_search_regex(
254 r' data-config-url="(.+?)"', webpage, 'config URL')
255 config_json = self._download_webpage(config_url, video_id)
256 config = json.loads(config_json)
257 except RegexNotFoundError:
258 # For pro videos or player.vimeo.com urls
259 # We try to find out to which variable is assigned the config dic
260 m_variable_name = re.search('(\w)\.video\.id', webpage)
261 if m_variable_name is not None:
262 config_re = r'%s=({.+?});' % re.escape(m_variable_name.group(1))
264 config_re = [r' = {config:({.+?}),assets:', r'(?:[abc])=({.+?});']
265 config = self._search_regex(config_re, webpage, 'info section',
267 config = json.loads(config)
268 except Exception as e:
269 if re.search('The creator of this video has not given you permission to embed it on this domain.', webpage):
270 raise ExtractorError('The author has restricted the access to this video, try with the "--referer" option')
272 if re.search('<form[^>]+?id="pw_form"', webpage) is not None:
273 self._verify_video_password(url, video_id, webpage)
274 return self._real_extract(url)
276 raise ExtractorError('Unable to extract info section',
279 if config.get('view') == 4:
280 config = self._verify_player_video_password(url, video_id)
283 video_title = config["video"]["title"]
285 # Extract uploader and uploader_id
286 video_uploader = config["video"]["owner"]["name"]
287 video_uploader_id = config["video"]["owner"]["url"].split('/')[-1] if config["video"]["owner"]["url"] else None
289 # Extract video thumbnail
290 video_thumbnail = config["video"].get("thumbnail")
291 if video_thumbnail is None:
292 video_thumbs = config["video"].get("thumbs")
293 if video_thumbs and isinstance(video_thumbs, dict):
294 _, video_thumbnail = sorted((int(width if width.isdigit() else 0), t_url) for (width, t_url) in video_thumbs.items())[-1]
296 # Extract video description
297 video_description = None
299 video_description = get_element_by_attribute("class", "description_wrapper", webpage)
300 if video_description:
301 video_description = clean_html(video_description)
302 except AssertionError as err:
303 # On some pages like (http://player.vimeo.com/video/54469442) the
304 # html tags are not closed, python 2.6 cannot handle it
305 if err.args[0] == 'we should not get here!':
310 # Extract video duration
311 video_duration = int_or_none(config["video"].get("duration"))
313 # Extract upload date
314 video_upload_date = None
315 mobj = re.search(r'<meta itemprop="dateCreated" content="(\d{4})-(\d{2})-(\d{2})T', webpage)
317 video_upload_date = mobj.group(1) + mobj.group(2) + mobj.group(3)
320 view_count = int(self._search_regex(r'UserPlays:(\d+)', webpage, 'view count'))
321 like_count = int(self._search_regex(r'UserLikes:(\d+)', webpage, 'like count'))
322 comment_count = int(self._search_regex(r'UserComments:(\d+)', webpage, 'comment count'))
323 except RegexNotFoundError:
324 # This info is only available in vimeo.com/{id} urls
329 # Vimeo specific: extract request signature and timestamp
330 sig = config['request']['signature']
331 timestamp = config['request']['timestamp']
333 # Vimeo specific: extract video codec and quality information
334 # First consider quality, then codecs, then take everything
335 codecs = [('vp6', 'flv'), ('vp8', 'flv'), ('h264', 'mp4')]
336 files = {'hd': [], 'sd': [], 'other': []}
337 config_files = config["video"].get("files") or config["request"].get("files")
338 for codec_name, codec_extension in codecs:
339 for quality in config_files.get(codec_name, []):
340 format_id = '-'.join((codec_name, quality)).lower()
341 key = quality if quality in files else 'other'
343 if isinstance(config_files[codec_name], dict):
344 file_info = config_files[codec_name][quality]
345 video_url = file_info.get('url')
348 if video_url is None:
349 video_url = "http://player.vimeo.com/play_redirect?clip_id=%s&sig=%s&time=%s&quality=%s&codecs=%s&type=moogaloop_local&embed_location=" \
350 % (video_id, sig, timestamp, quality, codec_name.upper())
353 'ext': codec_extension,
355 'format_id': format_id,
356 'width': file_info.get('width'),
357 'height': file_info.get('height'),
360 for key in ('other', 'sd', 'hd'):
361 formats += files[key]
362 if len(formats) == 0:
363 raise ExtractorError('No known codec found')
366 text_tracks = config['request'].get('text_tracks')
368 for tt in text_tracks:
369 subtitles[tt['lang']] = 'http://vimeo.com' + tt['url']
371 video_subtitles = self.extract_subtitles(video_id, subtitles)
372 if self._downloader.params.get('listsubtitles', False):
373 self._list_available_subtitles(video_id, subtitles)
378 'uploader': video_uploader,
379 'uploader_id': video_uploader_id,
380 'upload_date': video_upload_date,
381 'title': video_title,
382 'thumbnail': video_thumbnail,
383 'description': video_description,
384 'duration': video_duration,
387 'view_count': view_count,
388 'like_count': like_count,
389 'comment_count': comment_count,
390 'subtitles': video_subtitles,
394 class VimeoChannelIE(InfoExtractor):
395 IE_NAME = 'vimeo:channel'
396 _VALID_URL = r'(?:https?://)?vimeo\.com/channels/(?P<id>[^/]+)/?(\?.*)?$'
397 _MORE_PAGES_INDICATOR = r'<a.+?rel="next"'
398 _TITLE_RE = r'<link rel="alternate"[^>]+?title="(.*?)"'
400 def _page_url(self, base_url, pagenum):
401 return '%s/videos/page:%d/' % (base_url, pagenum)
403 def _extract_list_title(self, webpage):
404 return self._html_search_regex(self._TITLE_RE, webpage, 'list title')
406 def _extract_videos(self, list_id, base_url):
408 for pagenum in itertools.count(1):
409 webpage = self._download_webpage(
410 self._page_url(base_url, pagenum), list_id,
411 'Downloading page %s' % pagenum)
412 video_ids.extend(re.findall(r'id="clip_(\d+?)"', webpage))
413 if re.search(self._MORE_PAGES_INDICATOR, webpage, re.DOTALL) is None:
416 entries = [self.url_result('http://vimeo.com/%s' % video_id, 'Vimeo')
417 for video_id in video_ids]
418 return {'_type': 'playlist',
420 'title': self._extract_list_title(webpage),
424 def _real_extract(self, url):
425 mobj = re.match(self._VALID_URL, url)
426 channel_id = mobj.group('id')
427 return self._extract_videos(channel_id, 'http://vimeo.com/channels/%s' % channel_id)
430 class VimeoUserIE(VimeoChannelIE):
431 IE_NAME = 'vimeo:user'
432 _VALID_URL = r'(?:https?://)?vimeo\.com/(?P<name>[^/]+)(?:/videos|[#?]|$)'
433 _TITLE_RE = r'<a[^>]+?class="user">([^<>]+?)</a>'
436 def suitable(cls, url):
437 if VimeoChannelIE.suitable(url) or VimeoIE.suitable(url) or VimeoAlbumIE.suitable(url) or VimeoGroupsIE.suitable(url):
439 return super(VimeoUserIE, cls).suitable(url)
441 def _real_extract(self, url):
442 mobj = re.match(self._VALID_URL, url)
443 name = mobj.group('name')
444 return self._extract_videos(name, 'http://vimeo.com/%s' % name)
447 class VimeoAlbumIE(VimeoChannelIE):
448 IE_NAME = 'vimeo:album'
449 _VALID_URL = r'(?:https?://)?vimeo\.com/album/(?P<id>\d+)'
450 _TITLE_RE = r'<header id="page_header">\n\s*<h1>(.*?)</h1>'
452 def _page_url(self, base_url, pagenum):
453 return '%s/page:%d/' % (base_url, pagenum)
455 def _real_extract(self, url):
456 mobj = re.match(self._VALID_URL, url)
457 album_id = mobj.group('id')
458 return self._extract_videos(album_id, 'http://vimeo.com/album/%s' % album_id)
461 class VimeoGroupsIE(VimeoAlbumIE):
462 IE_NAME = 'vimeo:group'
463 _VALID_URL = r'(?:https?://)?vimeo\.com/groups/(?P<name>[^/]+)'
465 def _extract_list_title(self, webpage):
466 return self._og_search_title(webpage)
468 def _real_extract(self, url):
469 mobj = re.match(self._VALID_URL, url)
470 name = mobj.group('name')
471 return self._extract_videos(name, 'http://vimeo.com/groups/%s' % name)
474 class VimeoReviewIE(InfoExtractor):
475 IE_NAME = 'vimeo:review'
476 IE_DESC = 'Review pages on vimeo'
477 _VALID_URL = r'(?:https?://)?vimeo\.com/[^/]+/review/(?P<id>[^/]+)'
479 'url': 'https://vimeo.com/user21297594/review/75524534/3c257a1b5d',
480 'file': '75524534.mp4',
481 'md5': 'c507a72f780cacc12b2248bb4006d253',
483 'title': "DICK HARDWICK 'Comedian'",
484 'uploader': 'Richard Hardwick',
488 def _real_extract(self, url):
489 mobj = re.match(self._VALID_URL, url)
490 video_id = mobj.group('id')
491 player_url = 'https://player.vimeo.com/player/' + video_id
492 return self.url_result(player_url, 'Vimeo', video_id)
495 class VimeoWatchLaterIE(VimeoBaseInfoExtractor, VimeoChannelIE):
496 IE_NAME = 'vimeo:watchlater'
497 IE_DESC = 'Vimeo watch later list, "vimeowatchlater" keyword (requires authentication)'
498 _VALID_URL = r'https?://vimeo\.com/home/watchlater|:vimeowatchlater'
499 _LOGIN_REQUIRED = True
500 _TITLE_RE = r'href="/home/watchlater".*?>(.*?)<'
502 def _real_initialize(self):
505 def _page_url(self, base_url, pagenum):
506 url = '%s/page:%d/' % (base_url, pagenum)
507 request = compat_urllib_request.Request(url)
508 # Set the header to get a partial html page with the ids,
509 # the normal page doesn't contain them.
510 request.add_header('X-Requested-With', 'XMLHttpRequest')
513 def _real_extract(self, url):
514 return self._extract_videos('watchlater', 'https://vimeo.com/home/watchlater')