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