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