[vimeo:group] Improve _VALID_URL (Closes #7552)
[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         formats = []
391         config_files = config['video'].get('files') or config['request'].get('files', {})
392         for f in config_files.get('progressive', []):
393             video_url = f.get('url')
394             if not video_url:
395                 continue
396             formats.append({
397                 'url': video_url,
398                 'format_id': 'http-%s' % f.get('quality'),
399                 'width': int_or_none(f.get('width')),
400                 'height': int_or_none(f.get('height')),
401                 'fps': int_or_none(f.get('fps')),
402                 'tbr': int_or_none(f.get('bitrate')),
403             })
404         m3u8_url = config_files.get('hls', {}).get('url')
405         if m3u8_url:
406             m3u8_formats = self._extract_m3u8_formats(
407                 m3u8_url, video_id, 'mp4', 'm3u8_native', 0, 'hls', fatal=False)
408             if m3u8_formats:
409                 formats.extend(m3u8_formats)
410         # Bitrates are completely broken. Single m3u8 may contain entries in kbps and bps
411         # at the same time without actual units specified. This lead to wrong sorting.
412         self._sort_formats(formats, field_preference=('height', 'width', 'fps', 'format_id'))
413
414         subtitles = {}
415         text_tracks = config['request'].get('text_tracks')
416         if text_tracks:
417             for tt in text_tracks:
418                 subtitles[tt['lang']] = [{
419                     'ext': 'vtt',
420                     'url': 'https://vimeo.com' + tt['url'],
421                 }]
422
423         return {
424             'id': video_id,
425             'uploader': video_uploader,
426             'uploader_id': video_uploader_id,
427             'upload_date': video_upload_date,
428             'title': video_title,
429             'thumbnail': video_thumbnail,
430             'description': video_description,
431             'duration': video_duration,
432             'formats': formats,
433             'webpage_url': url,
434             'view_count': view_count,
435             'like_count': like_count,
436             'comment_count': comment_count,
437             'subtitles': subtitles,
438         }
439
440
441 class VimeoChannelIE(VimeoBaseInfoExtractor):
442     IE_NAME = 'vimeo:channel'
443     _VALID_URL = r'https://vimeo\.com/channels/(?P<id>[^/?#]+)/?(?:$|[?#])'
444     _MORE_PAGES_INDICATOR = r'<a.+?rel="next"'
445     _TITLE = None
446     _TITLE_RE = r'<link rel="alternate"[^>]+?title="(.*?)"'
447     _TESTS = [{
448         'url': 'https://vimeo.com/channels/tributes',
449         'info_dict': {
450             'id': 'tributes',
451             'title': 'Vimeo Tributes',
452         },
453         'playlist_mincount': 25,
454     }]
455
456     def _page_url(self, base_url, pagenum):
457         return '%s/videos/page:%d/' % (base_url, pagenum)
458
459     def _extract_list_title(self, webpage):
460         return self._TITLE or self._html_search_regex(self._TITLE_RE, webpage, 'list title')
461
462     def _login_list_password(self, page_url, list_id, webpage):
463         login_form = self._search_regex(
464             r'(?s)<form[^>]+?id="pw_form"(.*?)</form>',
465             webpage, 'login form', default=None)
466         if not login_form:
467             return webpage
468
469         password = self._downloader.params.get('videopassword', None)
470         if password is None:
471             raise ExtractorError('This album is protected by a password, use the --video-password option', expected=True)
472         fields = self._hidden_inputs(login_form)
473         token, vuid = self._extract_xsrft_and_vuid(webpage)
474         fields['token'] = token
475         fields['password'] = password
476         post = urlencode_postdata(encode_dict(fields))
477         password_path = self._search_regex(
478             r'action="([^"]+)"', login_form, 'password URL')
479         password_url = compat_urlparse.urljoin(page_url, password_path)
480         password_request = compat_urllib_request.Request(password_url, post)
481         password_request.add_header('Content-type', 'application/x-www-form-urlencoded')
482         self._set_vimeo_cookie('vuid', vuid)
483         self._set_vimeo_cookie('xsrft', token)
484
485         return self._download_webpage(
486             password_request, list_id,
487             'Verifying the password', 'Wrong password')
488
489     def _title_and_entries(self, list_id, base_url):
490         for pagenum in itertools.count(1):
491             page_url = self._page_url(base_url, pagenum)
492             webpage = self._download_webpage(
493                 page_url, list_id,
494                 'Downloading page %s' % pagenum)
495
496             if pagenum == 1:
497                 webpage = self._login_list_password(page_url, list_id, webpage)
498                 yield self._extract_list_title(webpage)
499
500             for video_id in re.findall(r'id="clip_(\d+?)"', webpage):
501                 yield self.url_result('https://vimeo.com/%s' % video_id, 'Vimeo')
502
503             if re.search(self._MORE_PAGES_INDICATOR, webpage, re.DOTALL) is None:
504                 break
505
506     def _extract_videos(self, list_id, base_url):
507         title_and_entries = self._title_and_entries(list_id, base_url)
508         list_title = next(title_and_entries)
509         return self.playlist_result(title_and_entries, list_id, list_title)
510
511     def _real_extract(self, url):
512         mobj = re.match(self._VALID_URL, url)
513         channel_id = mobj.group('id')
514         return self._extract_videos(channel_id, 'https://vimeo.com/channels/%s' % channel_id)
515
516
517 class VimeoUserIE(VimeoChannelIE):
518     IE_NAME = 'vimeo:user'
519     _VALID_URL = r'https://vimeo\.com/(?!(?:[0-9]+|watchlater)(?:$|[?#/]))(?P<name>[^/]+)(?:/videos|[#?]|$)'
520     _TITLE_RE = r'<a[^>]+?class="user">([^<>]+?)</a>'
521     _TESTS = [{
522         'url': 'https://vimeo.com/nkistudio/videos',
523         'info_dict': {
524             'title': 'Nki',
525             'id': 'nkistudio',
526         },
527         'playlist_mincount': 66,
528     }]
529
530     def _real_extract(self, url):
531         mobj = re.match(self._VALID_URL, url)
532         name = mobj.group('name')
533         return self._extract_videos(name, 'https://vimeo.com/%s' % name)
534
535
536 class VimeoAlbumIE(VimeoChannelIE):
537     IE_NAME = 'vimeo:album'
538     _VALID_URL = r'https://vimeo\.com/album/(?P<id>\d+)'
539     _TITLE_RE = r'<header id="page_header">\n\s*<h1>(.*?)</h1>'
540     _TESTS = [{
541         'url': 'https://vimeo.com/album/2632481',
542         'info_dict': {
543             'id': '2632481',
544             'title': 'Staff Favorites: November 2013',
545         },
546         'playlist_mincount': 13,
547     }, {
548         'note': 'Password-protected album',
549         'url': 'https://vimeo.com/album/3253534',
550         'info_dict': {
551             'title': 'test',
552             'id': '3253534',
553         },
554         'playlist_count': 1,
555         'params': {
556             'videopassword': 'youtube-dl',
557         }
558     }]
559
560     def _page_url(self, base_url, pagenum):
561         return '%s/page:%d/' % (base_url, pagenum)
562
563     def _real_extract(self, url):
564         album_id = self._match_id(url)
565         return self._extract_videos(album_id, 'https://vimeo.com/album/%s' % album_id)
566
567
568 class VimeoGroupsIE(VimeoAlbumIE):
569     IE_NAME = 'vimeo:group'
570     _VALID_URL = r'https://vimeo\.com/groups/(?P<name>[^/]+)(?:/(?!videos?/\d+)|$)'
571     _TESTS = [{
572         'url': 'https://vimeo.com/groups/rolexawards',
573         'info_dict': {
574             'id': 'rolexawards',
575             'title': 'Rolex Awards for Enterprise',
576         },
577         'playlist_mincount': 73,
578     }]
579
580     def _extract_list_title(self, webpage):
581         return self._og_search_title(webpage)
582
583     def _real_extract(self, url):
584         mobj = re.match(self._VALID_URL, url)
585         name = mobj.group('name')
586         return self._extract_videos(name, 'https://vimeo.com/groups/%s' % name)
587
588
589 class VimeoReviewIE(InfoExtractor):
590     IE_NAME = 'vimeo:review'
591     IE_DESC = 'Review pages on vimeo'
592     _VALID_URL = r'https://vimeo\.com/[^/]+/review/(?P<id>[^/]+)'
593     _TESTS = [{
594         'url': 'https://vimeo.com/user21297594/review/75524534/3c257a1b5d',
595         'md5': 'c507a72f780cacc12b2248bb4006d253',
596         'info_dict': {
597             'id': '75524534',
598             'ext': 'mp4',
599             'title': "DICK HARDWICK 'Comedian'",
600             'uploader': 'Richard Hardwick',
601         }
602     }, {
603         'note': 'video player needs Referer',
604         'url': 'https://vimeo.com/user22258446/review/91613211/13f927e053',
605         'md5': '6295fdab8f4bf6a002d058b2c6dce276',
606         'info_dict': {
607             'id': '91613211',
608             'ext': 'mp4',
609             'title': 're:(?i)^Death by dogma versus assembling agile . Sander Hoogendoorn',
610             'uploader': 'DevWeek Events',
611             'duration': 2773,
612             'thumbnail': 're:^https?://.*\.jpg$',
613         }
614     }]
615
616     def _real_extract(self, url):
617         mobj = re.match(self._VALID_URL, url)
618         video_id = mobj.group('id')
619         player_url = 'https://player.vimeo.com/player/' + video_id
620         return self.url_result(player_url, 'Vimeo', video_id)
621
622
623 class VimeoWatchLaterIE(VimeoChannelIE):
624     IE_NAME = 'vimeo:watchlater'
625     IE_DESC = 'Vimeo watch later list, "vimeowatchlater" keyword (requires authentication)'
626     _VALID_URL = r'https://vimeo\.com/(?:home/)?watchlater|:vimeowatchlater'
627     _TITLE = 'Watch Later'
628     _LOGIN_REQUIRED = True
629     _TESTS = [{
630         'url': 'https://vimeo.com/watchlater',
631         'only_matching': True,
632     }]
633
634     def _real_initialize(self):
635         self._login()
636
637     def _page_url(self, base_url, pagenum):
638         url = '%s/page:%d/' % (base_url, pagenum)
639         request = compat_urllib_request.Request(url)
640         # Set the header to get a partial html page with the ids,
641         # the normal page doesn't contain them.
642         request.add_header('X-Requested-With', 'XMLHttpRequest')
643         return request
644
645     def _real_extract(self, url):
646         return self._extract_videos('watchlater', 'https://vimeo.com/watchlater')
647
648
649 class VimeoLikesIE(InfoExtractor):
650     _VALID_URL = r'https://(?:www\.)?vimeo\.com/user(?P<id>[0-9]+)/likes/?(?:$|[?#]|sort:)'
651     IE_NAME = 'vimeo:likes'
652     IE_DESC = 'Vimeo user likes'
653     _TEST = {
654         'url': 'https://vimeo.com/user755559/likes/',
655         'playlist_mincount': 293,
656         "info_dict": {
657             'id': 'user755559_likes',
658             "description": "See all the videos urza likes",
659             "title": 'Videos urza likes',
660         },
661     }
662
663     def _real_extract(self, url):
664         user_id = self._match_id(url)
665         webpage = self._download_webpage(url, user_id)
666         page_count = self._int(
667             self._search_regex(
668                 r'''(?x)<li><a\s+href="[^"]+"\s+data-page="([0-9]+)">
669                     .*?</a></li>\s*<li\s+class="pagination_next">
670                 ''', webpage, 'page count'),
671             'page count', fatal=True)
672         PAGE_SIZE = 12
673         title = self._html_search_regex(
674             r'(?s)<h1>(.+?)</h1>', webpage, 'title', fatal=False)
675         description = self._html_search_meta('description', webpage)
676
677         def _get_page(idx):
678             page_url = 'https://vimeo.com/user%s/likes/page:%d/sort:date' % (
679                 user_id, idx + 1)
680             webpage = self._download_webpage(
681                 page_url, user_id,
682                 note='Downloading page %d/%d' % (idx + 1, page_count))
683             video_list = self._search_regex(
684                 r'(?s)<ol class="js-browse_list[^"]+"[^>]*>(.*?)</ol>',
685                 webpage, 'video content')
686             paths = re.findall(
687                 r'<li[^>]*>\s*<a\s+href="([^"]+)"', video_list)
688             for path in paths:
689                 yield {
690                     '_type': 'url',
691                     'url': compat_urlparse.urljoin(page_url, path),
692                 }
693
694         pl = InAdvancePagedList(_get_page, page_count, PAGE_SIZE)
695
696         return {
697             '_type': 'playlist',
698             'id': 'user%s_likes' % user_id,
699             'title': title,
700             'description': description,
701             'entries': pl,
702         }