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