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