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