[vimeo] prefer original format
[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             'url': 'https://vimeo.com/109815029',
190             'note': 'Video not completely processed, "failed" seed status',
191             'only_matching': True,
192         },
193         {
194             'url': 'https://vimeo.com/groups/travelhd/videos/22439234',
195             'only_matching': True,
196         },
197     ]
198
199     @staticmethod
200     def _extract_vimeo_url(url, webpage):
201         # Look for embedded (iframe) Vimeo player
202         mobj = re.search(
203             r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/.+?)\1', webpage)
204         if mobj:
205             player_url = unescapeHTML(mobj.group('url'))
206             surl = smuggle_url(player_url, {'Referer': url})
207             return surl
208         # Look for embedded (swf embed) Vimeo player
209         mobj = re.search(
210             r'<embed[^>]+?src="((?:https?:)?//(?:www\.)?vimeo\.com/moogaloop\.swf.+?)"', webpage)
211         if mobj:
212             return mobj.group(1)
213
214     def _verify_video_password(self, url, video_id, webpage):
215         password = self._downloader.params.get('videopassword', None)
216         if password is None:
217             raise ExtractorError('This video is protected by a password, use the --video-password option', expected=True)
218         token, vuid = self._extract_xsrft_and_vuid(webpage)
219         data = urlencode_postdata(encode_dict({
220             'password': password,
221             'token': token,
222         }))
223         if url.startswith('http://'):
224             # vimeo only supports https now, but the user can give an http url
225             url = url.replace('http://', 'https://')
226         password_request = sanitized_Request(url + '/password', data)
227         password_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
228         password_request.add_header('Referer', url)
229         self._set_vimeo_cookie('vuid', vuid)
230         return self._download_webpage(
231             password_request, video_id,
232             'Verifying the password', 'Wrong password')
233
234     def _verify_player_video_password(self, url, video_id):
235         password = self._downloader.params.get('videopassword', None)
236         if password is None:
237             raise ExtractorError('This video is protected by a password, use the --video-password option')
238         data = urlencode_postdata(encode_dict({'password': password}))
239         pass_url = url + '/check-password'
240         password_request = sanitized_Request(pass_url, data)
241         password_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
242         return self._download_json(
243             password_request, video_id,
244             'Verifying the password',
245             'Wrong password')
246
247     def _real_initialize(self):
248         self._login()
249
250     def _real_extract(self, url):
251         url, data = unsmuggle_url(url)
252         headers = std_headers
253         if data is not None:
254             headers = headers.copy()
255             headers.update(data)
256         if 'Referer' not in headers:
257             headers['Referer'] = url
258
259         # Extract ID from URL
260         mobj = re.match(self._VALID_URL, url)
261         video_id = mobj.group('id')
262         orig_url = url
263         if mobj.group('pro') or mobj.group('player'):
264             url = 'https://player.vimeo.com/video/' + video_id
265         else:
266             url = 'https://vimeo.com/' + video_id
267
268         # Retrieve video webpage to extract further information
269         request = sanitized_Request(url, None, headers)
270         try:
271             webpage = self._download_webpage(request, video_id)
272         except ExtractorError as ee:
273             if isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 403:
274                 errmsg = ee.cause.read()
275                 if b'Because of its privacy settings, this video cannot be played here' in errmsg:
276                     raise ExtractorError(
277                         'Cannot download embed-only video without embedding '
278                         'URL. Please call youtube-dl with the URL of the page '
279                         'that embeds this video.',
280                         expected=True)
281             raise
282
283         # Now we begin extracting as much information as we can from what we
284         # retrieved. First we extract the information common to all extractors,
285         # and latter we extract those that are Vimeo specific.
286         self.report_extraction(video_id)
287
288         vimeo_config = self._search_regex(
289             r'vimeo\.config\s*=\s*(?:({.+?})|_extend\([^,]+,\s+({.+?})\));', webpage,
290             'vimeo config', default=None)
291         if vimeo_config:
292             seed_status = self._parse_json(vimeo_config, video_id).get('seed_status', {})
293             if seed_status.get('state') == 'failed':
294                 raise ExtractorError(
295                     '%s said: %s' % (self.IE_NAME, seed_status['title']),
296                     expected=True)
297
298         # Extract the config JSON
299         try:
300             try:
301                 config_url = self._html_search_regex(
302                     r' data-config-url="(.+?)"', webpage,
303                     'config URL', default=None)
304                 if not config_url:
305                     # Sometimes new react-based page is served instead of old one that require
306                     # different config URL extraction approach (see
307                     # https://github.com/rg3/youtube-dl/pull/7209)
308                     vimeo_clip_page_config = self._search_regex(
309                         r'vimeo\.clip_page_config\s*=\s*({.+?});', webpage,
310                         'vimeo clip page config')
311                     config_url = self._parse_json(
312                         vimeo_clip_page_config, video_id)['player']['config_url']
313                 config_json = self._download_webpage(config_url, video_id)
314                 config = json.loads(config_json)
315             except RegexNotFoundError:
316                 # For pro videos or player.vimeo.com urls
317                 # We try to find out to which variable is assigned the config dic
318                 m_variable_name = re.search('(\w)\.video\.id', webpage)
319                 if m_variable_name is not None:
320                     config_re = r'%s=({[^}].+?});' % re.escape(m_variable_name.group(1))
321                 else:
322                     config_re = [r' = {config:({.+?}),assets:', r'(?:[abc])=({.+?});']
323                 config = self._search_regex(config_re, webpage, 'info section',
324                                             flags=re.DOTALL)
325                 config = json.loads(config)
326         except Exception as e:
327             if re.search('The creator of this video has not given you permission to embed it on this domain.', webpage):
328                 raise ExtractorError('The author has restricted the access to this video, try with the "--referer" option')
329
330             if re.search(r'<form[^>]+?id="pw_form"', webpage) is not None:
331                 if data and '_video_password_verified' in data:
332                     raise ExtractorError('video password verification failed!')
333                 self._verify_video_password(url, video_id, webpage)
334                 return self._real_extract(
335                     smuggle_url(url, {'_video_password_verified': 'verified'}))
336             else:
337                 raise ExtractorError('Unable to extract info section',
338                                      cause=e)
339         else:
340             if config.get('view') == 4:
341                 config = self._verify_player_video_password(url, video_id)
342
343         # Extract title
344         video_title = config["video"]["title"]
345
346         # Extract uploader and uploader_id
347         video_uploader = config["video"]["owner"]["name"]
348         video_uploader_id = config["video"]["owner"]["url"].split('/')[-1] if config["video"]["owner"]["url"] else None
349
350         # Extract video thumbnail
351         video_thumbnail = config["video"].get("thumbnail")
352         if video_thumbnail is None:
353             video_thumbs = config["video"].get("thumbs")
354             if video_thumbs and isinstance(video_thumbs, dict):
355                 _, video_thumbnail = sorted((int(width if width.isdigit() else 0), t_url) for (width, t_url) in video_thumbs.items())[-1]
356
357         # Extract video description
358
359         video_description = self._html_search_regex(
360             r'(?s)<div\s+class="[^"]*description[^"]*"[^>]*>(.*?)</div>',
361             webpage, 'description', default=None)
362         if not video_description:
363             video_description = self._html_search_meta(
364                 'description', webpage, default=None)
365         if not video_description and mobj.group('pro'):
366             orig_webpage = self._download_webpage(
367                 orig_url, video_id,
368                 note='Downloading webpage for description',
369                 fatal=False)
370             if orig_webpage:
371                 video_description = self._html_search_meta(
372                     'description', orig_webpage, default=None)
373         if not video_description and not mobj.group('player'):
374             self._downloader.report_warning('Cannot find video description')
375
376         # Extract video duration
377         video_duration = int_or_none(config["video"].get("duration"))
378
379         # Extract upload date
380         video_upload_date = None
381         mobj = re.search(r'<time[^>]+datetime="([^"]+)"', webpage)
382         if mobj is not None:
383             video_upload_date = unified_strdate(mobj.group(1))
384
385         try:
386             view_count = int(self._search_regex(r'UserPlays:(\d+)', webpage, 'view count'))
387             like_count = int(self._search_regex(r'UserLikes:(\d+)', webpage, 'like count'))
388             comment_count = int(self._search_regex(r'UserComments:(\d+)', webpage, 'comment count'))
389         except RegexNotFoundError:
390             # This info is only available in vimeo.com/{id} urls
391             view_count = None
392             like_count = None
393             comment_count = None
394
395         formats = []
396         download_request = sanitized_Request('https://vimeo.com/%s?action=load_download_config' % video_id, headers={
397             'X-Requested-With': 'XMLHttpRequest'})
398         download_data = self._download_json(download_request, video_id, fatal=False)
399         if download_data:
400             source_file = download_data.get('source_file')
401             if source_file and not source_file.get('is_cold') and not source_file.get('is_defrosting'):
402                 formats.append({
403                     'url': source_file['download_url'],
404                     'ext': source_file['extension'].lower(),
405                     'width': int_or_none(source_file.get('width')),
406                     'height': int_or_none(source_file.get('height')),
407                     'filesize': parse_filesize(source_file.get('size')),
408                     'format_id': source_file.get('public_name', 'Original'),
409                     'preference': 1,
410                 })
411         config_files = config['video'].get('files') or config['request'].get('files', {})
412         for f in config_files.get('progressive', []):
413             video_url = f.get('url')
414             if not video_url:
415                 continue
416             formats.append({
417                 'url': video_url,
418                 'format_id': 'http-%s' % f.get('quality'),
419                 'width': int_or_none(f.get('width')),
420                 'height': int_or_none(f.get('height')),
421                 'fps': int_or_none(f.get('fps')),
422                 'tbr': int_or_none(f.get('bitrate')),
423             })
424         m3u8_url = config_files.get('hls', {}).get('url')
425         if m3u8_url:
426             m3u8_formats = self._extract_m3u8_formats(
427                 m3u8_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False)
428             if m3u8_formats:
429                 formats.extend(m3u8_formats)
430         # Bitrates are completely broken. Single m3u8 may contain entries in kbps and bps
431         # at the same time without actual units specified. This lead to wrong sorting.
432         self._sort_formats(formats, field_preference=('preference', 'height', 'width', 'fps', 'format_id'))
433
434         subtitles = {}
435         text_tracks = config['request'].get('text_tracks')
436         if text_tracks:
437             for tt in text_tracks:
438                 subtitles[tt['lang']] = [{
439                     'ext': 'vtt',
440                     'url': 'https://vimeo.com' + tt['url'],
441                 }]
442
443         return {
444             'id': video_id,
445             'uploader': video_uploader,
446             'uploader_id': video_uploader_id,
447             'upload_date': video_upload_date,
448             'title': video_title,
449             'thumbnail': video_thumbnail,
450             'description': video_description,
451             'duration': video_duration,
452             'formats': formats,
453             'webpage_url': url,
454             'view_count': view_count,
455             'like_count': like_count,
456             'comment_count': comment_count,
457             'subtitles': subtitles,
458         }
459
460
461 class VimeoChannelIE(VimeoBaseInfoExtractor):
462     IE_NAME = 'vimeo:channel'
463     _VALID_URL = r'https://vimeo\.com/channels/(?P<id>[^/?#]+)/?(?:$|[?#])'
464     _MORE_PAGES_INDICATOR = r'<a.+?rel="next"'
465     _TITLE = None
466     _TITLE_RE = r'<link rel="alternate"[^>]+?title="(.*?)"'
467     _TESTS = [{
468         'url': 'https://vimeo.com/channels/tributes',
469         'info_dict': {
470             'id': 'tributes',
471             'title': 'Vimeo Tributes',
472         },
473         'playlist_mincount': 25,
474     }]
475
476     def _page_url(self, base_url, pagenum):
477         return '%s/videos/page:%d/' % (base_url, pagenum)
478
479     def _extract_list_title(self, webpage):
480         return self._TITLE or self._html_search_regex(self._TITLE_RE, webpage, 'list title')
481
482     def _login_list_password(self, page_url, list_id, webpage):
483         login_form = self._search_regex(
484             r'(?s)<form[^>]+?id="pw_form"(.*?)</form>',
485             webpage, 'login form', default=None)
486         if not login_form:
487             return webpage
488
489         password = self._downloader.params.get('videopassword', None)
490         if password is None:
491             raise ExtractorError('This album is protected by a password, use the --video-password option', expected=True)
492         fields = self._hidden_inputs(login_form)
493         token, vuid = self._extract_xsrft_and_vuid(webpage)
494         fields['token'] = token
495         fields['password'] = password
496         post = urlencode_postdata(encode_dict(fields))
497         password_path = self._search_regex(
498             r'action="([^"]+)"', login_form, 'password URL')
499         password_url = compat_urlparse.urljoin(page_url, password_path)
500         password_request = sanitized_Request(password_url, post)
501         password_request.add_header('Content-type', 'application/x-www-form-urlencoded')
502         self._set_vimeo_cookie('vuid', vuid)
503         self._set_vimeo_cookie('xsrft', token)
504
505         return self._download_webpage(
506             password_request, list_id,
507             'Verifying the password', 'Wrong password')
508
509     def _title_and_entries(self, list_id, base_url):
510         for pagenum in itertools.count(1):
511             page_url = self._page_url(base_url, pagenum)
512             webpage = self._download_webpage(
513                 page_url, list_id,
514                 'Downloading page %s' % pagenum)
515
516             if pagenum == 1:
517                 webpage = self._login_list_password(page_url, list_id, webpage)
518                 yield self._extract_list_title(webpage)
519
520             for video_id in re.findall(r'id="clip_(\d+?)"', webpage):
521                 yield self.url_result('https://vimeo.com/%s' % video_id, 'Vimeo')
522
523             if re.search(self._MORE_PAGES_INDICATOR, webpage, re.DOTALL) is None:
524                 break
525
526     def _extract_videos(self, list_id, base_url):
527         title_and_entries = self._title_and_entries(list_id, base_url)
528         list_title = next(title_and_entries)
529         return self.playlist_result(title_and_entries, list_id, list_title)
530
531     def _real_extract(self, url):
532         mobj = re.match(self._VALID_URL, url)
533         channel_id = mobj.group('id')
534         return self._extract_videos(channel_id, 'https://vimeo.com/channels/%s' % channel_id)
535
536
537 class VimeoUserIE(VimeoChannelIE):
538     IE_NAME = 'vimeo:user'
539     _VALID_URL = r'https://vimeo\.com/(?!(?:[0-9]+|watchlater)(?:$|[?#/]))(?P<name>[^/]+)(?:/videos|[#?]|$)'
540     _TITLE_RE = r'<a[^>]+?class="user">([^<>]+?)</a>'
541     _TESTS = [{
542         'url': 'https://vimeo.com/nkistudio/videos',
543         'info_dict': {
544             'title': 'Nki',
545             'id': 'nkistudio',
546         },
547         'playlist_mincount': 66,
548     }]
549
550     def _real_extract(self, url):
551         mobj = re.match(self._VALID_URL, url)
552         name = mobj.group('name')
553         return self._extract_videos(name, 'https://vimeo.com/%s' % name)
554
555
556 class VimeoAlbumIE(VimeoChannelIE):
557     IE_NAME = 'vimeo:album'
558     _VALID_URL = r'https://vimeo\.com/album/(?P<id>\d+)'
559     _TITLE_RE = r'<header id="page_header">\n\s*<h1>(.*?)</h1>'
560     _TESTS = [{
561         'url': 'https://vimeo.com/album/2632481',
562         'info_dict': {
563             'id': '2632481',
564             'title': 'Staff Favorites: November 2013',
565         },
566         'playlist_mincount': 13,
567     }, {
568         'note': 'Password-protected album',
569         'url': 'https://vimeo.com/album/3253534',
570         'info_dict': {
571             'title': 'test',
572             'id': '3253534',
573         },
574         'playlist_count': 1,
575         'params': {
576             'videopassword': 'youtube-dl',
577         }
578     }]
579
580     def _page_url(self, base_url, pagenum):
581         return '%s/page:%d/' % (base_url, pagenum)
582
583     def _real_extract(self, url):
584         album_id = self._match_id(url)
585         return self._extract_videos(album_id, 'https://vimeo.com/album/%s' % album_id)
586
587
588 class VimeoGroupsIE(VimeoAlbumIE):
589     IE_NAME = 'vimeo:group'
590     _VALID_URL = r'https://vimeo\.com/groups/(?P<name>[^/]+)(?:/(?!videos?/\d+)|$)'
591     _TESTS = [{
592         'url': 'https://vimeo.com/groups/rolexawards',
593         'info_dict': {
594             'id': 'rolexawards',
595             'title': 'Rolex Awards for Enterprise',
596         },
597         'playlist_mincount': 73,
598     }]
599
600     def _extract_list_title(self, webpage):
601         return self._og_search_title(webpage)
602
603     def _real_extract(self, url):
604         mobj = re.match(self._VALID_URL, url)
605         name = mobj.group('name')
606         return self._extract_videos(name, 'https://vimeo.com/groups/%s' % name)
607
608
609 class VimeoReviewIE(InfoExtractor):
610     IE_NAME = 'vimeo:review'
611     IE_DESC = 'Review pages on vimeo'
612     _VALID_URL = r'https://vimeo\.com/[^/]+/review/(?P<id>[^/]+)'
613     _TESTS = [{
614         'url': 'https://vimeo.com/user21297594/review/75524534/3c257a1b5d',
615         'md5': 'c507a72f780cacc12b2248bb4006d253',
616         'info_dict': {
617             'id': '75524534',
618             'ext': 'mp4',
619             'title': "DICK HARDWICK 'Comedian'",
620             'uploader': 'Richard Hardwick',
621         }
622     }, {
623         'note': 'video player needs Referer',
624         'url': 'https://vimeo.com/user22258446/review/91613211/13f927e053',
625         'md5': '6295fdab8f4bf6a002d058b2c6dce276',
626         'info_dict': {
627             'id': '91613211',
628             'ext': 'mp4',
629             'title': 're:(?i)^Death by dogma versus assembling agile . Sander Hoogendoorn',
630             'uploader': 'DevWeek Events',
631             'duration': 2773,
632             'thumbnail': 're:^https?://.*\.jpg$',
633         }
634     }]
635
636     def _real_extract(self, url):
637         mobj = re.match(self._VALID_URL, url)
638         video_id = mobj.group('id')
639         player_url = 'https://player.vimeo.com/player/' + video_id
640         return self.url_result(player_url, 'Vimeo', video_id)
641
642
643 class VimeoWatchLaterIE(VimeoChannelIE):
644     IE_NAME = 'vimeo:watchlater'
645     IE_DESC = 'Vimeo watch later list, "vimeowatchlater" keyword (requires authentication)'
646     _VALID_URL = r'https://vimeo\.com/(?:home/)?watchlater|:vimeowatchlater'
647     _TITLE = 'Watch Later'
648     _LOGIN_REQUIRED = True
649     _TESTS = [{
650         'url': 'https://vimeo.com/watchlater',
651         'only_matching': True,
652     }]
653
654     def _real_initialize(self):
655         self._login()
656
657     def _page_url(self, base_url, pagenum):
658         url = '%s/page:%d/' % (base_url, pagenum)
659         request = sanitized_Request(url)
660         # Set the header to get a partial html page with the ids,
661         # the normal page doesn't contain them.
662         request.add_header('X-Requested-With', 'XMLHttpRequest')
663         return request
664
665     def _real_extract(self, url):
666         return self._extract_videos('watchlater', 'https://vimeo.com/watchlater')
667
668
669 class VimeoLikesIE(InfoExtractor):
670     _VALID_URL = r'https://(?:www\.)?vimeo\.com/user(?P<id>[0-9]+)/likes/?(?:$|[?#]|sort:)'
671     IE_NAME = 'vimeo:likes'
672     IE_DESC = 'Vimeo user likes'
673     _TEST = {
674         'url': 'https://vimeo.com/user755559/likes/',
675         'playlist_mincount': 293,
676         "info_dict": {
677             'id': 'user755559_likes',
678             "description": "See all the videos urza likes",
679             "title": 'Videos urza likes',
680         },
681     }
682
683     def _real_extract(self, url):
684         user_id = self._match_id(url)
685         webpage = self._download_webpage(url, user_id)
686         page_count = self._int(
687             self._search_regex(
688                 r'''(?x)<li><a\s+href="[^"]+"\s+data-page="([0-9]+)">
689                     .*?</a></li>\s*<li\s+class="pagination_next">
690                 ''', webpage, 'page count'),
691             'page count', fatal=True)
692         PAGE_SIZE = 12
693         title = self._html_search_regex(
694             r'(?s)<h1>(.+?)</h1>', webpage, 'title', fatal=False)
695         description = self._html_search_meta('description', webpage)
696
697         def _get_page(idx):
698             page_url = 'https://vimeo.com/user%s/likes/page:%d/sort:date' % (
699                 user_id, idx + 1)
700             webpage = self._download_webpage(
701                 page_url, user_id,
702                 note='Downloading page %d/%d' % (idx + 1, page_count))
703             video_list = self._search_regex(
704                 r'(?s)<ol class="js-browse_list[^"]+"[^>]*>(.*?)</ol>',
705                 webpage, 'video content')
706             paths = re.findall(
707                 r'<li[^>]*>\s*<a\s+href="([^"]+)"', video_list)
708             for path in paths:
709                 yield {
710                     '_type': 'url',
711                     'url': compat_urlparse.urljoin(page_url, path),
712                 }
713
714         pl = InAdvancePagedList(_get_page, page_count, PAGE_SIZE)
715
716         return {
717             '_type': 'playlist',
718             'id': 'user%s_likes' % user_id,
719             'title': title,
720             'description': description,
721             'entries': pl,
722         }