]> jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/vimeo.py
Merge branch 'kusi' of https://github.com/mutantmonkey/youtube-dl into mutantmonkey...
[yt-dlp.git] / youtube_dl / extractor / vimeo.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 import json
5 import re
6 import itertools
7
8 from .common import InfoExtractor
9 from ..compat import (
10 compat_HTTPError,
11 compat_urlparse,
12 )
13 from ..utils import (
14 determine_ext,
15 encode_dict,
16 ExtractorError,
17 InAdvancePagedList,
18 int_or_none,
19 RegexNotFoundError,
20 sanitized_Request,
21 smuggle_url,
22 std_headers,
23 unified_strdate,
24 unsmuggle_url,
25 urlencode_postdata,
26 unescapeHTML,
27 parse_filesize,
28 )
29
30
31 class VimeoBaseInfoExtractor(InfoExtractor):
32 _NETRC_MACHINE = 'vimeo'
33 _LOGIN_REQUIRED = False
34 _LOGIN_URL = 'https://vimeo.com/log_in'
35
36 def _login(self):
37 (username, password) = self._get_login_info()
38 if username is None:
39 if self._LOGIN_REQUIRED:
40 raise ExtractorError('No login info available, needed for using %s.' % self.IE_NAME, expected=True)
41 return
42 self.report_login()
43 webpage = self._download_webpage(self._LOGIN_URL, None, False)
44 token, vuid = self._extract_xsrft_and_vuid(webpage)
45 data = urlencode_postdata(encode_dict({
46 'action': 'login',
47 'email': username,
48 'password': password,
49 'service': 'vimeo',
50 'token': token,
51 }))
52 login_request = sanitized_Request(self._LOGIN_URL, data)
53 login_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
54 login_request.add_header('Referer', self._LOGIN_URL)
55 self._set_vimeo_cookie('vuid', vuid)
56 self._download_webpage(login_request, None, False, 'Wrong login info')
57
58 def _extract_xsrft_and_vuid(self, webpage):
59 xsrft = self._search_regex(
60 r'(?:(?P<q1>["\'])xsrft(?P=q1)\s*:|xsrft\s*[=:])\s*(?P<q>["\'])(?P<xsrft>.+?)(?P=q)',
61 webpage, 'login token', group='xsrft')
62 vuid = self._search_regex(
63 r'["\']vuid["\']\s*:\s*(["\'])(?P<vuid>.+?)\1',
64 webpage, 'vuid', group='vuid')
65 return xsrft, vuid
66
67 def _set_vimeo_cookie(self, name, value):
68 self._set_cookie('vimeo.com', name, value)
69
70
71 class VimeoIE(VimeoBaseInfoExtractor):
72 """Information extractor for vimeo.com."""
73
74 # _VALID_URL matches Vimeo URLs
75 _VALID_URL = r'''(?x)
76 https?://
77 (?:(?:www|(?P<player>player))\.)?
78 vimeo(?P<pro>pro)?\.com/
79 (?!channels/[^/?#]+/?(?:$|[?#])|album/)
80 (?:.*?/)?
81 (?:(?:play_redirect_hls|moogaloop\.swf)\?clip_id=)?
82 (?:videos?/)?
83 (?P<id>[0-9]+)
84 /?(?:[?&].*)?(?:[#].*)?$'''
85 IE_NAME = 'vimeo'
86 _TESTS = [
87 {
88 'url': 'http://vimeo.com/56015672#at=0',
89 'md5': '8879b6cc097e987f02484baf890129e5',
90 'info_dict': {
91 'id': '56015672',
92 'ext': 'mp4',
93 'title': "youtube-dl test video - \u2605 \" ' \u5e78 / \\ \u00e4 \u21ad \U0001d550",
94 'description': 'md5:2d3305bad981a06ff79f027f19865021',
95 'upload_date': '20121220',
96 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/user7108434',
97 'uploader_id': 'user7108434',
98 'uploader': 'Filippo Valsorda',
99 'duration': 10,
100 },
101 },
102 {
103 'url': 'http://vimeopro.com/openstreetmapus/state-of-the-map-us-2013/video/68093876',
104 'md5': '3b5ca6aa22b60dfeeadf50b72e44ed82',
105 'note': 'Vimeo Pro video (#1197)',
106 'info_dict': {
107 'id': '68093876',
108 'ext': 'mp4',
109 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/openstreetmapus',
110 'uploader_id': 'openstreetmapus',
111 'uploader': 'OpenStreetMap US',
112 'title': 'Andy Allan - Putting the Carto into OpenStreetMap Cartography',
113 'description': 'md5:fd69a7b8d8c34a4e1d2ec2e4afd6ec30',
114 'duration': 1595,
115 },
116 },
117 {
118 'url': 'http://player.vimeo.com/video/54469442',
119 'md5': '619b811a4417aa4abe78dc653becf511',
120 'note': 'Videos that embed the url in the player page',
121 'info_dict': {
122 'id': '54469442',
123 'ext': 'mp4',
124 'title': 'Kathy Sierra: Building the minimum Badass User, Business of Software 2012',
125 'uploader': 'The BLN & Business of Software',
126 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/theblnbusinessofsoftware',
127 'uploader_id': 'theblnbusinessofsoftware',
128 'duration': 3610,
129 'description': None,
130 },
131 },
132 {
133 'url': 'http://vimeo.com/68375962',
134 'md5': 'aaf896bdb7ddd6476df50007a0ac0ae7',
135 'note': 'Video protected with password',
136 'info_dict': {
137 'id': '68375962',
138 'ext': 'mp4',
139 'title': 'youtube-dl password protected test video',
140 'upload_date': '20130614',
141 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/user18948128',
142 'uploader_id': 'user18948128',
143 'uploader': 'Jaime Marquínez Ferrándiz',
144 'duration': 10,
145 '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',
146 },
147 'params': {
148 'videopassword': 'youtube-dl',
149 },
150 },
151 {
152 'url': 'http://vimeo.com/channels/keypeele/75629013',
153 'md5': '2f86a05afe9d7abc0b9126d229bbe15d',
154 'note': 'Video is freely available via original URL '
155 'and protected with password when accessed via http://vimeo.com/75629013',
156 'info_dict': {
157 'id': '75629013',
158 'ext': 'mp4',
159 'title': 'Key & Peele: Terrorist Interrogation',
160 'description': 'md5:8678b246399b070816b12313e8b4eb5c',
161 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/atencio',
162 'uploader_id': 'atencio',
163 'uploader': 'Peter Atencio',
164 'upload_date': '20130927',
165 'duration': 187,
166 },
167 },
168 {
169 'url': 'http://vimeo.com/76979871',
170 'note': 'Video with subtitles',
171 'info_dict': {
172 'id': '76979871',
173 'ext': 'mp4',
174 'title': 'The New Vimeo Player (You Know, For Videos)',
175 'description': 'md5:2ec900bf97c3f389378a96aee11260ea',
176 'upload_date': '20131015',
177 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/staff',
178 'uploader_id': 'staff',
179 'uploader': 'Vimeo Staff',
180 'duration': 62,
181 }
182 },
183 {
184 # from https://www.ouya.tv/game/Pier-Solar-and-the-Great-Architects/
185 'url': 'https://player.vimeo.com/video/98044508',
186 'note': 'The js code contains assignments to the same variable as the config',
187 'info_dict': {
188 'id': '98044508',
189 'ext': 'mp4',
190 'title': 'Pier Solar OUYA Official Trailer',
191 'uploader': 'Tulio Gonçalves',
192 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/user28849593',
193 'uploader_id': 'user28849593',
194 },
195 },
196 {
197 # contains original format
198 'url': 'https://vimeo.com/33951933',
199 'md5': '53c688fa95a55bf4b7293d37a89c5c53',
200 'info_dict': {
201 'id': '33951933',
202 'ext': 'mp4',
203 'title': 'FOX CLASSICS - Forever Classic ID - A Full Minute',
204 'uploader': 'The DMCI',
205 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/dmci',
206 'uploader_id': 'dmci',
207 'upload_date': '20111220',
208 'description': 'md5:ae23671e82d05415868f7ad1aec21147',
209 },
210 },
211 {
212 'url': 'https://vimeo.com/109815029',
213 'note': 'Video not completely processed, "failed" seed status',
214 'only_matching': True,
215 },
216 {
217 'url': 'https://vimeo.com/groups/travelhd/videos/22439234',
218 'only_matching': True,
219 },
220 {
221 # source file returns 403: Forbidden
222 'url': 'https://vimeo.com/7809605',
223 'only_matching': True,
224 },
225 ]
226
227 @staticmethod
228 def _extract_vimeo_url(url, webpage):
229 # Look for embedded (iframe) Vimeo player
230 mobj = re.search(
231 r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/.+?)\1', webpage)
232 if mobj:
233 player_url = unescapeHTML(mobj.group('url'))
234 surl = smuggle_url(player_url, {'http_headers': {'Referer': url}})
235 return surl
236 # Look for embedded (swf embed) Vimeo player
237 mobj = re.search(
238 r'<embed[^>]+?src="((?:https?:)?//(?:www\.)?vimeo\.com/moogaloop\.swf.+?)"', webpage)
239 if mobj:
240 return mobj.group(1)
241
242 def _verify_video_password(self, url, video_id, webpage):
243 password = self._downloader.params.get('videopassword')
244 if password is None:
245 raise ExtractorError('This video is protected by a password, use the --video-password option', expected=True)
246 token, vuid = self._extract_xsrft_and_vuid(webpage)
247 data = urlencode_postdata(encode_dict({
248 'password': password,
249 'token': token,
250 }))
251 if url.startswith('http://'):
252 # vimeo only supports https now, but the user can give an http url
253 url = url.replace('http://', 'https://')
254 password_request = sanitized_Request(url + '/password', data)
255 password_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
256 password_request.add_header('Referer', url)
257 self._set_vimeo_cookie('vuid', vuid)
258 return self._download_webpage(
259 password_request, video_id,
260 'Verifying the password', 'Wrong password')
261
262 def _verify_player_video_password(self, url, video_id):
263 password = self._downloader.params.get('videopassword')
264 if password is None:
265 raise ExtractorError('This video is protected by a password, use the --video-password option')
266 data = urlencode_postdata(encode_dict({'password': password}))
267 pass_url = url + '/check-password'
268 password_request = sanitized_Request(pass_url, data)
269 password_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
270 return self._download_json(
271 password_request, video_id,
272 'Verifying the password',
273 'Wrong password')
274
275 def _real_initialize(self):
276 self._login()
277
278 def _real_extract(self, url):
279 url, data = unsmuggle_url(url, {})
280 headers = std_headers
281 if 'http_headers' in data:
282 headers = headers.copy()
283 headers.update(data['http_headers'])
284 if 'Referer' not in headers:
285 headers['Referer'] = url
286
287 # Extract ID from URL
288 mobj = re.match(self._VALID_URL, url)
289 video_id = mobj.group('id')
290 orig_url = url
291 if mobj.group('pro') or mobj.group('player'):
292 url = 'https://player.vimeo.com/video/' + video_id
293 else:
294 url = 'https://vimeo.com/' + video_id
295
296 # Retrieve video webpage to extract further information
297 request = sanitized_Request(url, None, headers)
298 try:
299 webpage = self._download_webpage(request, video_id)
300 except ExtractorError as ee:
301 if isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 403:
302 errmsg = ee.cause.read()
303 if b'Because of its privacy settings, this video cannot be played here' in errmsg:
304 raise ExtractorError(
305 'Cannot download embed-only video without embedding '
306 'URL. Please call youtube-dl with the URL of the page '
307 'that embeds this video.',
308 expected=True)
309 raise
310
311 # Now we begin extracting as much information as we can from what we
312 # retrieved. First we extract the information common to all extractors,
313 # and latter we extract those that are Vimeo specific.
314 self.report_extraction(video_id)
315
316 vimeo_config = self._search_regex(
317 r'vimeo\.config\s*=\s*(?:({.+?})|_extend\([^,]+,\s+({.+?})\));', webpage,
318 'vimeo config', default=None)
319 if vimeo_config:
320 seed_status = self._parse_json(vimeo_config, video_id).get('seed_status', {})
321 if seed_status.get('state') == 'failed':
322 raise ExtractorError(
323 '%s said: %s' % (self.IE_NAME, seed_status['title']),
324 expected=True)
325
326 # Extract the config JSON
327 try:
328 try:
329 config_url = self._html_search_regex(
330 r' data-config-url="(.+?)"', webpage,
331 'config URL', default=None)
332 if not config_url:
333 # Sometimes new react-based page is served instead of old one that require
334 # different config URL extraction approach (see
335 # https://github.com/rg3/youtube-dl/pull/7209)
336 vimeo_clip_page_config = self._search_regex(
337 r'vimeo\.clip_page_config\s*=\s*({.+?});', webpage,
338 'vimeo clip page config')
339 config_url = self._parse_json(
340 vimeo_clip_page_config, video_id)['player']['config_url']
341 config_json = self._download_webpage(config_url, video_id)
342 config = json.loads(config_json)
343 except RegexNotFoundError:
344 # For pro videos or player.vimeo.com urls
345 # We try to find out to which variable is assigned the config dic
346 m_variable_name = re.search('(\w)\.video\.id', webpage)
347 if m_variable_name is not None:
348 config_re = r'%s=({[^}].+?});' % re.escape(m_variable_name.group(1))
349 else:
350 config_re = [r' = {config:({.+?}),assets:', r'(?:[abc])=({.+?});']
351 config = self._search_regex(config_re, webpage, 'info section',
352 flags=re.DOTALL)
353 config = json.loads(config)
354 except Exception as e:
355 if re.search('The creator of this video has not given you permission to embed it on this domain.', webpage):
356 raise ExtractorError('The author has restricted the access to this video, try with the "--referer" option')
357
358 if re.search(r'<form[^>]+?id="pw_form"', webpage) is not None:
359 if '_video_password_verified' in data:
360 raise ExtractorError('video password verification failed!')
361 self._verify_video_password(url, video_id, webpage)
362 return self._real_extract(
363 smuggle_url(url, {'_video_password_verified': 'verified'}))
364 else:
365 raise ExtractorError('Unable to extract info section',
366 cause=e)
367 else:
368 if config.get('view') == 4:
369 config = self._verify_player_video_password(url, video_id)
370
371 if '>You rented this title.<' in webpage:
372 feature_id = config.get('video', {}).get('vod', {}).get('feature_id')
373 if feature_id and not data.get('force_feature_id', False):
374 return self.url_result(smuggle_url(
375 'https://player.vimeo.com/player/%s' % feature_id,
376 {'force_feature_id': True}), 'Vimeo')
377
378 # Extract title
379 video_title = config['video']['title']
380
381 # Extract uploader, uploader_url and uploader_id
382 video_uploader = config['video'].get('owner', {}).get('name')
383 video_uploader_url = config['video'].get('owner', {}).get('url')
384 video_uploader_id = video_uploader_url.split('/')[-1] if video_uploader_url else None
385
386 # Extract video thumbnail
387 video_thumbnail = config['video'].get('thumbnail')
388 if video_thumbnail is None:
389 video_thumbs = config['video'].get('thumbs')
390 if video_thumbs and isinstance(video_thumbs, dict):
391 _, video_thumbnail = sorted((int(width if width.isdigit() else 0), t_url) for (width, t_url) in video_thumbs.items())[-1]
392
393 # Extract video description
394
395 video_description = self._html_search_regex(
396 r'(?s)<div\s+class="[^"]*description[^"]*"[^>]*>(.*?)</div>',
397 webpage, 'description', default=None)
398 if not video_description:
399 video_description = self._html_search_meta(
400 'description', webpage, default=None)
401 if not video_description and mobj.group('pro'):
402 orig_webpage = self._download_webpage(
403 orig_url, video_id,
404 note='Downloading webpage for description',
405 fatal=False)
406 if orig_webpage:
407 video_description = self._html_search_meta(
408 'description', orig_webpage, default=None)
409 if not video_description and not mobj.group('player'):
410 self._downloader.report_warning('Cannot find video description')
411
412 # Extract video duration
413 video_duration = int_or_none(config['video'].get('duration'))
414
415 # Extract upload date
416 video_upload_date = None
417 mobj = re.search(r'<time[^>]+datetime="([^"]+)"', webpage)
418 if mobj is not None:
419 video_upload_date = unified_strdate(mobj.group(1))
420
421 try:
422 view_count = int(self._search_regex(r'UserPlays:(\d+)', webpage, 'view count'))
423 like_count = int(self._search_regex(r'UserLikes:(\d+)', webpage, 'like count'))
424 comment_count = int(self._search_regex(r'UserComments:(\d+)', webpage, 'comment count'))
425 except RegexNotFoundError:
426 # This info is only available in vimeo.com/{id} urls
427 view_count = None
428 like_count = None
429 comment_count = None
430
431 formats = []
432 download_request = sanitized_Request('https://vimeo.com/%s?action=load_download_config' % video_id, headers={
433 'X-Requested-With': 'XMLHttpRequest'})
434 download_data = self._download_json(download_request, video_id, fatal=False)
435 if download_data:
436 source_file = download_data.get('source_file')
437 if isinstance(source_file, dict):
438 download_url = source_file.get('download_url')
439 if download_url and not source_file.get('is_cold') and not source_file.get('is_defrosting'):
440 source_name = source_file.get('public_name', 'Original')
441 if self._is_valid_url(download_url, video_id, '%s video' % source_name):
442 ext = source_file.get('extension', determine_ext(download_url)).lower()
443 formats.append({
444 'url': download_url,
445 'ext': ext,
446 'width': int_or_none(source_file.get('width')),
447 'height': int_or_none(source_file.get('height')),
448 'filesize': parse_filesize(source_file.get('size')),
449 'format_id': source_name,
450 'preference': 1,
451 })
452 config_files = config['video'].get('files') or config['request'].get('files', {})
453 for f in config_files.get('progressive', []):
454 video_url = f.get('url')
455 if not video_url:
456 continue
457 formats.append({
458 'url': video_url,
459 'format_id': 'http-%s' % f.get('quality'),
460 'width': int_or_none(f.get('width')),
461 'height': int_or_none(f.get('height')),
462 'fps': int_or_none(f.get('fps')),
463 'tbr': int_or_none(f.get('bitrate')),
464 })
465 m3u8_url = config_files.get('hls', {}).get('url')
466 if m3u8_url:
467 formats.extend(self._extract_m3u8_formats(
468 m3u8_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
469 # Bitrates are completely broken. Single m3u8 may contain entries in kbps and bps
470 # at the same time without actual units specified. This lead to wrong sorting.
471 self._sort_formats(formats, field_preference=('preference', 'height', 'width', 'fps', 'format_id'))
472
473 subtitles = {}
474 text_tracks = config['request'].get('text_tracks')
475 if text_tracks:
476 for tt in text_tracks:
477 subtitles[tt['lang']] = [{
478 'ext': 'vtt',
479 'url': 'https://vimeo.com' + tt['url'],
480 }]
481
482 return {
483 'id': video_id,
484 'uploader': video_uploader,
485 'uploader_url': video_uploader_url,
486 'uploader_id': video_uploader_id,
487 'upload_date': video_upload_date,
488 'title': video_title,
489 'thumbnail': video_thumbnail,
490 'description': video_description,
491 'duration': video_duration,
492 'formats': formats,
493 'webpage_url': url,
494 'view_count': view_count,
495 'like_count': like_count,
496 'comment_count': comment_count,
497 'subtitles': subtitles,
498 }
499
500
501 class VimeoChannelIE(VimeoBaseInfoExtractor):
502 IE_NAME = 'vimeo:channel'
503 _VALID_URL = r'https://vimeo\.com/channels/(?P<id>[^/?#]+)/?(?:$|[?#])'
504 _MORE_PAGES_INDICATOR = r'<a.+?rel="next"'
505 _TITLE = None
506 _TITLE_RE = r'<link rel="alternate"[^>]+?title="(.*?)"'
507 _TESTS = [{
508 'url': 'https://vimeo.com/channels/tributes',
509 'info_dict': {
510 'id': 'tributes',
511 'title': 'Vimeo Tributes',
512 },
513 'playlist_mincount': 25,
514 }]
515
516 def _page_url(self, base_url, pagenum):
517 return '%s/videos/page:%d/' % (base_url, pagenum)
518
519 def _extract_list_title(self, webpage):
520 return self._TITLE or self._html_search_regex(self._TITLE_RE, webpage, 'list title')
521
522 def _login_list_password(self, page_url, list_id, webpage):
523 login_form = self._search_regex(
524 r'(?s)<form[^>]+?id="pw_form"(.*?)</form>',
525 webpage, 'login form', default=None)
526 if not login_form:
527 return webpage
528
529 password = self._downloader.params.get('videopassword')
530 if password is None:
531 raise ExtractorError('This album is protected by a password, use the --video-password option', expected=True)
532 fields = self._hidden_inputs(login_form)
533 token, vuid = self._extract_xsrft_and_vuid(webpage)
534 fields['token'] = token
535 fields['password'] = password
536 post = urlencode_postdata(encode_dict(fields))
537 password_path = self._search_regex(
538 r'action="([^"]+)"', login_form, 'password URL')
539 password_url = compat_urlparse.urljoin(page_url, password_path)
540 password_request = sanitized_Request(password_url, post)
541 password_request.add_header('Content-type', 'application/x-www-form-urlencoded')
542 self._set_vimeo_cookie('vuid', vuid)
543 self._set_vimeo_cookie('xsrft', token)
544
545 return self._download_webpage(
546 password_request, list_id,
547 'Verifying the password', 'Wrong password')
548
549 def _title_and_entries(self, list_id, base_url):
550 for pagenum in itertools.count(1):
551 page_url = self._page_url(base_url, pagenum)
552 webpage = self._download_webpage(
553 page_url, list_id,
554 'Downloading page %s' % pagenum)
555
556 if pagenum == 1:
557 webpage = self._login_list_password(page_url, list_id, webpage)
558 yield self._extract_list_title(webpage)
559
560 for video_id in re.findall(r'id="clip_(\d+?)"', webpage):
561 yield self.url_result('https://vimeo.com/%s' % video_id, 'Vimeo')
562
563 if re.search(self._MORE_PAGES_INDICATOR, webpage, re.DOTALL) is None:
564 break
565
566 def _extract_videos(self, list_id, base_url):
567 title_and_entries = self._title_and_entries(list_id, base_url)
568 list_title = next(title_and_entries)
569 return self.playlist_result(title_and_entries, list_id, list_title)
570
571 def _real_extract(self, url):
572 mobj = re.match(self._VALID_URL, url)
573 channel_id = mobj.group('id')
574 return self._extract_videos(channel_id, 'https://vimeo.com/channels/%s' % channel_id)
575
576
577 class VimeoUserIE(VimeoChannelIE):
578 IE_NAME = 'vimeo:user'
579 _VALID_URL = r'https://vimeo\.com/(?!(?:[0-9]+|watchlater)(?:$|[?#/]))(?P<name>[^/]+)(?:/videos|[#?]|$)'
580 _TITLE_RE = r'<a[^>]+?class="user">([^<>]+?)</a>'
581 _TESTS = [{
582 'url': 'https://vimeo.com/nkistudio/videos',
583 'info_dict': {
584 'title': 'Nki',
585 'id': 'nkistudio',
586 },
587 'playlist_mincount': 66,
588 }]
589
590 def _real_extract(self, url):
591 mobj = re.match(self._VALID_URL, url)
592 name = mobj.group('name')
593 return self._extract_videos(name, 'https://vimeo.com/%s' % name)
594
595
596 class VimeoAlbumIE(VimeoChannelIE):
597 IE_NAME = 'vimeo:album'
598 _VALID_URL = r'https://vimeo\.com/album/(?P<id>\d+)'
599 _TITLE_RE = r'<header id="page_header">\n\s*<h1>(.*?)</h1>'
600 _TESTS = [{
601 'url': 'https://vimeo.com/album/2632481',
602 'info_dict': {
603 'id': '2632481',
604 'title': 'Staff Favorites: November 2013',
605 },
606 'playlist_mincount': 13,
607 }, {
608 'note': 'Password-protected album',
609 'url': 'https://vimeo.com/album/3253534',
610 'info_dict': {
611 'title': 'test',
612 'id': '3253534',
613 },
614 'playlist_count': 1,
615 'params': {
616 'videopassword': 'youtube-dl',
617 }
618 }]
619
620 def _page_url(self, base_url, pagenum):
621 return '%s/page:%d/' % (base_url, pagenum)
622
623 def _real_extract(self, url):
624 album_id = self._match_id(url)
625 return self._extract_videos(album_id, 'https://vimeo.com/album/%s' % album_id)
626
627
628 class VimeoGroupsIE(VimeoAlbumIE):
629 IE_NAME = 'vimeo:group'
630 _VALID_URL = r'https://vimeo\.com/groups/(?P<name>[^/]+)(?:/(?!videos?/\d+)|$)'
631 _TESTS = [{
632 'url': 'https://vimeo.com/groups/rolexawards',
633 'info_dict': {
634 'id': 'rolexawards',
635 'title': 'Rolex Awards for Enterprise',
636 },
637 'playlist_mincount': 73,
638 }]
639
640 def _extract_list_title(self, webpage):
641 return self._og_search_title(webpage)
642
643 def _real_extract(self, url):
644 mobj = re.match(self._VALID_URL, url)
645 name = mobj.group('name')
646 return self._extract_videos(name, 'https://vimeo.com/groups/%s' % name)
647
648
649 class VimeoReviewIE(InfoExtractor):
650 IE_NAME = 'vimeo:review'
651 IE_DESC = 'Review pages on vimeo'
652 _VALID_URL = r'https://vimeo\.com/[^/]+/review/(?P<id>[^/]+)'
653 _TESTS = [{
654 'url': 'https://vimeo.com/user21297594/review/75524534/3c257a1b5d',
655 'md5': 'c507a72f780cacc12b2248bb4006d253',
656 'info_dict': {
657 'id': '75524534',
658 'ext': 'mp4',
659 'title': "DICK HARDWICK 'Comedian'",
660 'uploader': 'Richard Hardwick',
661 }
662 }, {
663 'note': 'video player needs Referer',
664 'url': 'https://vimeo.com/user22258446/review/91613211/13f927e053',
665 'md5': '6295fdab8f4bf6a002d058b2c6dce276',
666 'info_dict': {
667 'id': '91613211',
668 'ext': 'mp4',
669 'title': 're:(?i)^Death by dogma versus assembling agile . Sander Hoogendoorn',
670 'uploader': 'DevWeek Events',
671 'duration': 2773,
672 'thumbnail': 're:^https?://.*\.jpg$',
673 }
674 }]
675
676 def _real_extract(self, url):
677 mobj = re.match(self._VALID_URL, url)
678 video_id = mobj.group('id')
679 player_url = 'https://player.vimeo.com/player/' + video_id
680 return self.url_result(player_url, 'Vimeo', video_id)
681
682
683 class VimeoWatchLaterIE(VimeoChannelIE):
684 IE_NAME = 'vimeo:watchlater'
685 IE_DESC = 'Vimeo watch later list, "vimeowatchlater" keyword (requires authentication)'
686 _VALID_URL = r'https://vimeo\.com/(?:home/)?watchlater|:vimeowatchlater'
687 _TITLE = 'Watch Later'
688 _LOGIN_REQUIRED = True
689 _TESTS = [{
690 'url': 'https://vimeo.com/watchlater',
691 'only_matching': True,
692 }]
693
694 def _real_initialize(self):
695 self._login()
696
697 def _page_url(self, base_url, pagenum):
698 url = '%s/page:%d/' % (base_url, pagenum)
699 request = sanitized_Request(url)
700 # Set the header to get a partial html page with the ids,
701 # the normal page doesn't contain them.
702 request.add_header('X-Requested-With', 'XMLHttpRequest')
703 return request
704
705 def _real_extract(self, url):
706 return self._extract_videos('watchlater', 'https://vimeo.com/watchlater')
707
708
709 class VimeoLikesIE(InfoExtractor):
710 _VALID_URL = r'https://(?:www\.)?vimeo\.com/user(?P<id>[0-9]+)/likes/?(?:$|[?#]|sort:)'
711 IE_NAME = 'vimeo:likes'
712 IE_DESC = 'Vimeo user likes'
713 _TEST = {
714 'url': 'https://vimeo.com/user755559/likes/',
715 'playlist_mincount': 293,
716 'info_dict': {
717 'id': 'user755559_likes',
718 'description': 'See all the videos urza likes',
719 'title': 'Videos urza likes',
720 },
721 }
722
723 def _real_extract(self, url):
724 user_id = self._match_id(url)
725 webpage = self._download_webpage(url, user_id)
726 page_count = self._int(
727 self._search_regex(
728 r'''(?x)<li><a\s+href="[^"]+"\s+data-page="([0-9]+)">
729 .*?</a></li>\s*<li\s+class="pagination_next">
730 ''', webpage, 'page count'),
731 'page count', fatal=True)
732 PAGE_SIZE = 12
733 title = self._html_search_regex(
734 r'(?s)<h1>(.+?)</h1>', webpage, 'title', fatal=False)
735 description = self._html_search_meta('description', webpage)
736
737 def _get_page(idx):
738 page_url = 'https://vimeo.com/user%s/likes/page:%d/sort:date' % (
739 user_id, idx + 1)
740 webpage = self._download_webpage(
741 page_url, user_id,
742 note='Downloading page %d/%d' % (idx + 1, page_count))
743 video_list = self._search_regex(
744 r'(?s)<ol class="js-browse_list[^"]+"[^>]*>(.*?)</ol>',
745 webpage, 'video content')
746 paths = re.findall(
747 r'<li[^>]*>\s*<a\s+href="([^"]+)"', video_list)
748 for path in paths:
749 yield {
750 '_type': 'url',
751 'url': compat_urlparse.urljoin(page_url, path),
752 }
753
754 pl = InAdvancePagedList(_get_page, page_count, PAGE_SIZE)
755
756 return {
757 '_type': 'playlist',
758 'id': 'user%s_likes' % user_id,
759 'title': title,
760 'description': description,
761 'entries': pl,
762 }