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