]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/vimeo.py
51c69a80c216889315a4c5fe070572100c13dd36
[youtubedl] / youtube_dl / extractor / vimeo.py
1 # coding: 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_str,
12 compat_urlparse,
13 )
14 from ..utils import (
15 determine_ext,
16 ExtractorError,
17 InAdvancePagedList,
18 int_or_none,
19 NO_DEFAULT,
20 RegexNotFoundError,
21 sanitized_Request,
22 smuggle_url,
23 std_headers,
24 unified_strdate,
25 unsmuggle_url,
26 urlencode_postdata,
27 unescapeHTML,
28 parse_filesize,
29 try_get,
30 )
31
32
33 class VimeoBaseInfoExtractor(InfoExtractor):
34 _NETRC_MACHINE = 'vimeo'
35 _LOGIN_REQUIRED = False
36 _LOGIN_URL = 'https://vimeo.com/log_in'
37
38 def _login(self):
39 (username, password) = self._get_login_info()
40 if username is None:
41 if self._LOGIN_REQUIRED:
42 raise ExtractorError('No login info available, needed for using %s.' % self.IE_NAME, expected=True)
43 return
44 self.report_login()
45 webpage = self._download_webpage(self._LOGIN_URL, None, False)
46 token, vuid = self._extract_xsrft_and_vuid(webpage)
47 data = urlencode_postdata({
48 'action': 'login',
49 'email': username,
50 'password': password,
51 'service': 'vimeo',
52 'token': token,
53 })
54 login_request = sanitized_Request(self._LOGIN_URL, data)
55 login_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
56 login_request.add_header('Referer', self._LOGIN_URL)
57 self._set_vimeo_cookie('vuid', vuid)
58 self._download_webpage(login_request, None, False, 'Wrong login info')
59
60 def _verify_video_password(self, url, video_id, webpage):
61 password = self._downloader.params.get('videopassword')
62 if password is None:
63 raise ExtractorError('This video is protected by a password, use the --video-password option', expected=True)
64 token, vuid = self._extract_xsrft_and_vuid(webpage)
65 data = urlencode_postdata({
66 'password': password,
67 'token': token,
68 })
69 if url.startswith('http://'):
70 # vimeo only supports https now, but the user can give an http url
71 url = url.replace('http://', 'https://')
72 password_request = sanitized_Request(url + '/password', data)
73 password_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
74 password_request.add_header('Referer', url)
75 self._set_vimeo_cookie('vuid', vuid)
76 return self._download_webpage(
77 password_request, video_id,
78 'Verifying the password', 'Wrong password')
79
80 def _extract_xsrft_and_vuid(self, webpage):
81 xsrft = self._search_regex(
82 r'(?:(?P<q1>["\'])xsrft(?P=q1)\s*:|xsrft\s*[=:])\s*(?P<q>["\'])(?P<xsrft>.+?)(?P=q)',
83 webpage, 'login token', group='xsrft')
84 vuid = self._search_regex(
85 r'["\']vuid["\']\s*:\s*(["\'])(?P<vuid>.+?)\1',
86 webpage, 'vuid', group='vuid')
87 return xsrft, vuid
88
89 def _set_vimeo_cookie(self, name, value):
90 self._set_cookie('vimeo.com', name, value)
91
92 def _vimeo_sort_formats(self, formats):
93 # Bitrates are completely broken. Single m3u8 may contain entries in kbps and bps
94 # at the same time without actual units specified. This lead to wrong sorting.
95 self._sort_formats(formats, field_preference=('preference', 'height', 'width', 'fps', 'format_id'))
96
97 def _parse_config(self, config, video_id):
98 # Extract title
99 video_title = config['video']['title']
100
101 # Extract uploader, uploader_url and uploader_id
102 video_uploader = config['video'].get('owner', {}).get('name')
103 video_uploader_url = config['video'].get('owner', {}).get('url')
104 video_uploader_id = video_uploader_url.split('/')[-1] if video_uploader_url else None
105
106 # Extract video thumbnail
107 video_thumbnail = config['video'].get('thumbnail')
108 if video_thumbnail is None:
109 video_thumbs = config['video'].get('thumbs')
110 if video_thumbs and isinstance(video_thumbs, dict):
111 _, video_thumbnail = sorted((int(width if width.isdigit() else 0), t_url) for (width, t_url) in video_thumbs.items())[-1]
112
113 # Extract video duration
114 video_duration = int_or_none(config['video'].get('duration'))
115
116 formats = []
117 config_files = config['video'].get('files') or config['request'].get('files', {})
118 for f in config_files.get('progressive', []):
119 video_url = f.get('url')
120 if not video_url:
121 continue
122 formats.append({
123 'url': video_url,
124 'format_id': 'http-%s' % f.get('quality'),
125 'width': int_or_none(f.get('width')),
126 'height': int_or_none(f.get('height')),
127 'fps': int_or_none(f.get('fps')),
128 'tbr': int_or_none(f.get('bitrate')),
129 })
130 m3u8_url = config_files.get('hls', {}).get('url')
131 if m3u8_url:
132 formats.extend(self._extract_m3u8_formats(
133 m3u8_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
134
135 subtitles = {}
136 text_tracks = config['request'].get('text_tracks')
137 if text_tracks:
138 for tt in text_tracks:
139 subtitles[tt['lang']] = [{
140 'ext': 'vtt',
141 'url': 'https://vimeo.com' + tt['url'],
142 }]
143
144 return {
145 'title': video_title,
146 'uploader': video_uploader,
147 'uploader_id': video_uploader_id,
148 'uploader_url': video_uploader_url,
149 'thumbnail': video_thumbnail,
150 'duration': video_duration,
151 'formats': formats,
152 'subtitles': subtitles,
153 }
154
155
156 class VimeoIE(VimeoBaseInfoExtractor):
157 """Information extractor for vimeo.com."""
158
159 # _VALID_URL matches Vimeo URLs
160 _VALID_URL = r'''(?x)
161 https?://
162 (?:
163 (?:
164 www|
165 (?P<player>player)
166 )
167 \.
168 )?
169 vimeo(?P<pro>pro)?\.com/
170 (?!(?:channels|album)/[^/?#]+/?(?:$|[?#])|[^/]+/review/|ondemand/)
171 (?:.*?/)?
172 (?:
173 (?:
174 play_redirect_hls|
175 moogaloop\.swf)\?clip_id=
176 )?
177 (?:videos?/)?
178 (?P<id>[0-9]+)
179 (?:/[\da-f]+)?
180 /?(?:[?&].*)?(?:[#].*)?$
181 '''
182 IE_NAME = 'vimeo'
183 _TESTS = [
184 {
185 'url': 'http://vimeo.com/56015672#at=0',
186 'md5': '8879b6cc097e987f02484baf890129e5',
187 'info_dict': {
188 'id': '56015672',
189 'ext': 'mp4',
190 'title': "youtube-dl test video - \u2605 \" ' \u5e78 / \\ \u00e4 \u21ad \U0001d550",
191 'description': 'md5:2d3305bad981a06ff79f027f19865021',
192 'upload_date': '20121220',
193 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/user7108434',
194 'uploader_id': 'user7108434',
195 'uploader': 'Filippo Valsorda',
196 'duration': 10,
197 },
198 },
199 {
200 'url': 'http://vimeopro.com/openstreetmapus/state-of-the-map-us-2013/video/68093876',
201 'md5': '3b5ca6aa22b60dfeeadf50b72e44ed82',
202 'note': 'Vimeo Pro video (#1197)',
203 'info_dict': {
204 'id': '68093876',
205 'ext': 'mp4',
206 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/openstreetmapus',
207 'uploader_id': 'openstreetmapus',
208 'uploader': 'OpenStreetMap US',
209 'title': 'Andy Allan - Putting the Carto into OpenStreetMap Cartography',
210 'description': 'md5:fd69a7b8d8c34a4e1d2ec2e4afd6ec30',
211 'duration': 1595,
212 },
213 },
214 {
215 'url': 'http://player.vimeo.com/video/54469442',
216 'md5': '619b811a4417aa4abe78dc653becf511',
217 'note': 'Videos that embed the url in the player page',
218 'info_dict': {
219 'id': '54469442',
220 'ext': 'mp4',
221 'title': 'Kathy Sierra: Building the minimum Badass User, Business of Software 2012',
222 'uploader': 'The BLN & Business of Software',
223 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/theblnbusinessofsoftware',
224 'uploader_id': 'theblnbusinessofsoftware',
225 'duration': 3610,
226 'description': None,
227 },
228 },
229 {
230 'url': 'http://vimeo.com/68375962',
231 'md5': 'aaf896bdb7ddd6476df50007a0ac0ae7',
232 'note': 'Video protected with password',
233 'info_dict': {
234 'id': '68375962',
235 'ext': 'mp4',
236 'title': 'youtube-dl password protected test video',
237 'upload_date': '20130614',
238 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/user18948128',
239 'uploader_id': 'user18948128',
240 'uploader': 'Jaime Marquƭnez FerrƔndiz',
241 'duration': 10,
242 'description': 'This is "youtube-dl password protected test video" by on Vimeo, the home for high quality videos and the people who love them.',
243 },
244 'params': {
245 'videopassword': 'youtube-dl',
246 },
247 },
248 {
249 'url': 'http://vimeo.com/channels/keypeele/75629013',
250 'md5': '2f86a05afe9d7abc0b9126d229bbe15d',
251 'info_dict': {
252 'id': '75629013',
253 'ext': 'mp4',
254 'title': 'Key & Peele: Terrorist Interrogation',
255 'description': 'md5:8678b246399b070816b12313e8b4eb5c',
256 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/atencio',
257 'uploader_id': 'atencio',
258 'uploader': 'Peter Atencio',
259 'upload_date': '20130927',
260 'duration': 187,
261 },
262 },
263 {
264 'url': 'http://vimeo.com/76979871',
265 'note': 'Video with subtitles',
266 'info_dict': {
267 'id': '76979871',
268 'ext': 'mp4',
269 'title': 'The New Vimeo Player (You Know, For Videos)',
270 'description': 'md5:2ec900bf97c3f389378a96aee11260ea',
271 'upload_date': '20131015',
272 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/staff',
273 'uploader_id': 'staff',
274 'uploader': 'Vimeo Staff',
275 'duration': 62,
276 }
277 },
278 {
279 # from https://www.ouya.tv/game/Pier-Solar-and-the-Great-Architects/
280 'url': 'https://player.vimeo.com/video/98044508',
281 'note': 'The js code contains assignments to the same variable as the config',
282 'info_dict': {
283 'id': '98044508',
284 'ext': 'mp4',
285 'title': 'Pier Solar OUYA Official Trailer',
286 'uploader': 'Tulio GonƧalves',
287 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/user28849593',
288 'uploader_id': 'user28849593',
289 },
290 },
291 {
292 # contains original format
293 'url': 'https://vimeo.com/33951933',
294 'md5': '2d9f5475e0537f013d0073e812ab89e6',
295 'info_dict': {
296 'id': '33951933',
297 'ext': 'mp4',
298 'title': 'FOX CLASSICS - Forever Classic ID - A Full Minute',
299 'uploader': 'The DMCI',
300 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/dmci',
301 'uploader_id': 'dmci',
302 'upload_date': '20111220',
303 'description': 'md5:ae23671e82d05415868f7ad1aec21147',
304 },
305 },
306 {
307 # only available via https://vimeo.com/channels/tributes/6213729 and
308 # not via https://vimeo.com/6213729
309 'url': 'https://vimeo.com/channels/tributes/6213729',
310 'info_dict': {
311 'id': '6213729',
312 'ext': 'mp4',
313 'title': 'Vimeo Tribute: The Shining',
314 'uploader': 'Casey Donahue',
315 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/caseydonahue',
316 'uploader_id': 'caseydonahue',
317 'upload_date': '20090821',
318 'description': 'md5:bdbf314014e58713e6e5b66eb252f4a6',
319 },
320 'params': {
321 'skip_download': True,
322 },
323 'expected_warnings': ['Unable to download JSON metadata'],
324 },
325 {
326 # redirects to ondemand extractor and should be passed throught it
327 # for successful extraction
328 'url': 'https://vimeo.com/73445910',
329 'info_dict': {
330 'id': '73445910',
331 'ext': 'mp4',
332 'title': 'The Reluctant Revolutionary',
333 'uploader': '10Ft Films',
334 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/tenfootfilms',
335 'uploader_id': 'tenfootfilms',
336 },
337 'params': {
338 'skip_download': True,
339 },
340 },
341 {
342 'url': 'http://vimeo.com/moogaloop.swf?clip_id=2539741',
343 'only_matching': True,
344 },
345 {
346 'url': 'https://vimeo.com/109815029',
347 'note': 'Video not completely processed, "failed" seed status',
348 'only_matching': True,
349 },
350 {
351 'url': 'https://vimeo.com/groups/travelhd/videos/22439234',
352 'only_matching': True,
353 },
354 {
355 'url': 'https://vimeo.com/album/2632481/video/79010983',
356 'only_matching': True,
357 },
358 {
359 # source file returns 403: Forbidden
360 'url': 'https://vimeo.com/7809605',
361 'only_matching': True,
362 },
363 {
364 'url': 'https://vimeo.com/160743502/abd0e13fb4',
365 'only_matching': True,
366 }
367 ]
368
369 @staticmethod
370 def _smuggle_referrer(url, referrer_url):
371 return smuggle_url(url, {'http_headers': {'Referer': referrer_url}})
372
373 @staticmethod
374 def _extract_urls(url, webpage):
375 urls = []
376 # Look for embedded (iframe) Vimeo player
377 for mobj in re.finditer(
378 r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/.+?)\1',
379 webpage):
380 urls.append(VimeoIE._smuggle_referrer(unescapeHTML(mobj.group('url')), url))
381 PLAIN_EMBED_RE = (
382 # Look for embedded (swf embed) Vimeo player
383 r'<embed[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?vimeo\.com/moogaloop\.swf.+?)\1',
384 # Look more for non-standard embedded Vimeo player
385 r'<video[^>]+src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?vimeo\.com/[0-9]+)\1',
386 )
387 for embed_re in PLAIN_EMBED_RE:
388 for mobj in re.finditer(embed_re, webpage):
389 urls.append(mobj.group('url'))
390 return urls
391
392 @staticmethod
393 def _extract_url(url, webpage):
394 urls = VimeoIE._extract_urls(url, webpage)
395 return urls[0] if urls else None
396
397 def _verify_player_video_password(self, url, video_id):
398 password = self._downloader.params.get('videopassword')
399 if password is None:
400 raise ExtractorError('This video is protected by a password, use the --video-password option')
401 data = urlencode_postdata({'password': password})
402 pass_url = url + '/check-password'
403 password_request = sanitized_Request(pass_url, data)
404 password_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
405 password_request.add_header('Referer', url)
406 return self._download_json(
407 password_request, video_id,
408 'Verifying the password', 'Wrong password')
409
410 def _real_initialize(self):
411 self._login()
412
413 def _real_extract(self, url):
414 url, data = unsmuggle_url(url, {})
415 headers = std_headers.copy()
416 if 'http_headers' in data:
417 headers.update(data['http_headers'])
418 if 'Referer' not in headers:
419 headers['Referer'] = url
420
421 # Extract ID from URL
422 mobj = re.match(self._VALID_URL, url)
423 video_id = mobj.group('id')
424 orig_url = url
425 if mobj.group('pro') or mobj.group('player'):
426 url = 'https://player.vimeo.com/video/' + video_id
427 elif any(p in url for p in ('play_redirect_hls', 'moogaloop.swf')):
428 url = 'https://vimeo.com/' + video_id
429
430 # Retrieve video webpage to extract further information
431 request = sanitized_Request(url, headers=headers)
432 try:
433 webpage, urlh = self._download_webpage_handle(request, video_id)
434 # Some URLs redirect to ondemand can't be extracted with
435 # this extractor right away thus should be passed through
436 # ondemand extractor (e.g. https://vimeo.com/73445910)
437 if VimeoOndemandIE.suitable(urlh.geturl()):
438 return self.url_result(urlh.geturl(), VimeoOndemandIE.ie_key())
439 except ExtractorError as ee:
440 if isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 403:
441 errmsg = ee.cause.read()
442 if b'Because of its privacy settings, this video cannot be played here' in errmsg:
443 raise ExtractorError(
444 'Cannot download embed-only video without embedding '
445 'URL. Please call youtube-dl with the URL of the page '
446 'that embeds this video.',
447 expected=True)
448 raise
449
450 # Now we begin extracting as much information as we can from what we
451 # retrieved. First we extract the information common to all extractors,
452 # and latter we extract those that are Vimeo specific.
453 self.report_extraction(video_id)
454
455 vimeo_config = self._search_regex(
456 r'vimeo\.config\s*=\s*(?:({.+?})|_extend\([^,]+,\s+({.+?})\));', webpage,
457 'vimeo config', default=None)
458 if vimeo_config:
459 seed_status = self._parse_json(vimeo_config, video_id).get('seed_status', {})
460 if seed_status.get('state') == 'failed':
461 raise ExtractorError(
462 '%s said: %s' % (self.IE_NAME, seed_status['title']),
463 expected=True)
464
465 # Extract the config JSON
466 try:
467 try:
468 config_url = self._html_search_regex(
469 r' data-config-url="(.+?)"', webpage,
470 'config URL', default=None)
471 if not config_url:
472 # Sometimes new react-based page is served instead of old one that require
473 # different config URL extraction approach (see
474 # https://github.com/rg3/youtube-dl/pull/7209)
475 vimeo_clip_page_config = self._search_regex(
476 r'vimeo\.clip_page_config\s*=\s*({.+?});', webpage,
477 'vimeo clip page config')
478 config_url = self._parse_json(
479 vimeo_clip_page_config, video_id)['player']['config_url']
480 config_json = self._download_webpage(config_url, video_id)
481 config = json.loads(config_json)
482 except RegexNotFoundError:
483 # For pro videos or player.vimeo.com urls
484 # We try to find out to which variable is assigned the config dic
485 m_variable_name = re.search('(\w)\.video\.id', webpage)
486 if m_variable_name is not None:
487 config_re = r'%s=({[^}].+?});' % re.escape(m_variable_name.group(1))
488 else:
489 config_re = [r' = {config:({.+?}),assets:', r'(?:[abc])=({.+?});']
490 config = self._search_regex(config_re, webpage, 'info section',
491 flags=re.DOTALL)
492 config = json.loads(config)
493 except Exception as e:
494 if re.search('The creator of this video has not given you permission to embed it on this domain.', webpage):
495 raise ExtractorError('The author has restricted the access to this video, try with the "--referer" option')
496
497 if re.search(r'<form[^>]+?id="pw_form"', webpage) is not None:
498 if '_video_password_verified' in data:
499 raise ExtractorError('video password verification failed!')
500 self._verify_video_password(url, video_id, webpage)
501 return self._real_extract(
502 smuggle_url(url, {'_video_password_verified': 'verified'}))
503 else:
504 raise ExtractorError('Unable to extract info section',
505 cause=e)
506 else:
507 if config.get('view') == 4:
508 config = self._verify_player_video_password(url, video_id)
509
510 def is_rented():
511 if '>You rented this title.<' in webpage:
512 return True
513 if config.get('user', {}).get('purchased'):
514 return True
515 label = try_get(
516 config, lambda x: x['video']['vod']['purchase_options'][0]['label_string'], compat_str)
517 if label and label.startswith('You rented this'):
518 return True
519 return False
520
521 if is_rented():
522 feature_id = config.get('video', {}).get('vod', {}).get('feature_id')
523 if feature_id and not data.get('force_feature_id', False):
524 return self.url_result(smuggle_url(
525 'https://player.vimeo.com/player/%s' % feature_id,
526 {'force_feature_id': True}), 'Vimeo')
527
528 # Extract video description
529
530 video_description = self._html_search_regex(
531 r'(?s)<div\s+class="[^"]*description[^"]*"[^>]*>(.*?)</div>',
532 webpage, 'description', default=None)
533 if not video_description:
534 video_description = self._html_search_meta(
535 'description', webpage, default=None)
536 if not video_description and mobj.group('pro'):
537 orig_webpage = self._download_webpage(
538 orig_url, video_id,
539 note='Downloading webpage for description',
540 fatal=False)
541 if orig_webpage:
542 video_description = self._html_search_meta(
543 'description', orig_webpage, default=None)
544 if not video_description and not mobj.group('player'):
545 self._downloader.report_warning('Cannot find video description')
546
547 # Extract upload date
548 video_upload_date = None
549 mobj = re.search(r'<time[^>]+datetime="([^"]+)"', webpage)
550 if mobj is not None:
551 video_upload_date = unified_strdate(mobj.group(1))
552
553 try:
554 view_count = int(self._search_regex(r'UserPlays:(\d+)', webpage, 'view count'))
555 like_count = int(self._search_regex(r'UserLikes:(\d+)', webpage, 'like count'))
556 comment_count = int(self._search_regex(r'UserComments:(\d+)', webpage, 'comment count'))
557 except RegexNotFoundError:
558 # This info is only available in vimeo.com/{id} urls
559 view_count = None
560 like_count = None
561 comment_count = None
562
563 formats = []
564 download_request = sanitized_Request('https://vimeo.com/%s?action=load_download_config' % video_id, headers={
565 'X-Requested-With': 'XMLHttpRequest'})
566 download_data = self._download_json(download_request, video_id, fatal=False)
567 if download_data:
568 source_file = download_data.get('source_file')
569 if isinstance(source_file, dict):
570 download_url = source_file.get('download_url')
571 if download_url and not source_file.get('is_cold') and not source_file.get('is_defrosting'):
572 source_name = source_file.get('public_name', 'Original')
573 if self._is_valid_url(download_url, video_id, '%s video' % source_name):
574 ext = source_file.get('extension', determine_ext(download_url)).lower()
575 formats.append({
576 'url': download_url,
577 'ext': ext,
578 'width': int_or_none(source_file.get('width')),
579 'height': int_or_none(source_file.get('height')),
580 'filesize': parse_filesize(source_file.get('size')),
581 'format_id': source_name,
582 'preference': 1,
583 })
584
585 info_dict = self._parse_config(config, video_id)
586 formats.extend(info_dict['formats'])
587 self._vimeo_sort_formats(formats)
588 info_dict.update({
589 'id': video_id,
590 'formats': formats,
591 'upload_date': video_upload_date,
592 'description': video_description,
593 'webpage_url': url,
594 'view_count': view_count,
595 'like_count': like_count,
596 'comment_count': comment_count,
597 })
598
599 return info_dict
600
601
602 class VimeoOndemandIE(VimeoBaseInfoExtractor):
603 IE_NAME = 'vimeo:ondemand'
604 _VALID_URL = r'https?://(?:www\.)?vimeo\.com/ondemand/(?P<id>[^/?#&]+)'
605 _TESTS = [{
606 # ondemand video not available via https://vimeo.com/id
607 'url': 'https://vimeo.com/ondemand/20704',
608 'md5': 'c424deda8c7f73c1dfb3edd7630e2f35',
609 'info_dict': {
610 'id': '105442900',
611 'ext': 'mp4',
612 'title': 'המעבדה - במאי יו×Ŗם פלדמן',
613 'uploader': 'גם ×”×Øטים',
614 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/gumfilms',
615 'uploader_id': 'gumfilms',
616 },
617 }, {
618 # requires Referer to be passed along with og:video:url
619 'url': 'https://vimeo.com/ondemand/36938/126682985',
620 'info_dict': {
621 'id': '126682985',
622 'ext': 'mp4',
623 'title': 'RƤvlock, rƤtt lƤte pƄ rƤtt plats',
624 'uploader': 'Lindroth & Norin',
625 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/user14430847',
626 'uploader_id': 'user14430847',
627 },
628 'params': {
629 'skip_download': True,
630 },
631 }, {
632 'url': 'https://vimeo.com/ondemand/nazmaalik',
633 'only_matching': True,
634 }, {
635 'url': 'https://vimeo.com/ondemand/141692381',
636 'only_matching': True,
637 }, {
638 'url': 'https://vimeo.com/ondemand/thelastcolony/150274832',
639 'only_matching': True,
640 }]
641
642 def _real_extract(self, url):
643 video_id = self._match_id(url)
644 webpage = self._download_webpage(url, video_id)
645 return self.url_result(
646 # Some videos require Referer to be passed along with og:video:url
647 # similarly to generic vimeo embeds (e.g.
648 # https://vimeo.com/ondemand/36938/126682985).
649 VimeoIE._smuggle_referrer(self._og_search_video_url(webpage), url),
650 VimeoIE.ie_key())
651
652
653 class VimeoChannelIE(VimeoBaseInfoExtractor):
654 IE_NAME = 'vimeo:channel'
655 _VALID_URL = r'https://vimeo\.com/channels/(?P<id>[^/?#]+)/?(?:$|[?#])'
656 _MORE_PAGES_INDICATOR = r'<a.+?rel="next"'
657 _TITLE = None
658 _TITLE_RE = r'<link rel="alternate"[^>]+?title="(.*?)"'
659 _TESTS = [{
660 'url': 'https://vimeo.com/channels/tributes',
661 'info_dict': {
662 'id': 'tributes',
663 'title': 'Vimeo Tributes',
664 },
665 'playlist_mincount': 25,
666 }]
667
668 def _page_url(self, base_url, pagenum):
669 return '%s/videos/page:%d/' % (base_url, pagenum)
670
671 def _extract_list_title(self, webpage):
672 return self._TITLE or self._html_search_regex(self._TITLE_RE, webpage, 'list title')
673
674 def _login_list_password(self, page_url, list_id, webpage):
675 login_form = self._search_regex(
676 r'(?s)<form[^>]+?id="pw_form"(.*?)</form>',
677 webpage, 'login form', default=None)
678 if not login_form:
679 return webpage
680
681 password = self._downloader.params.get('videopassword')
682 if password is None:
683 raise ExtractorError('This album is protected by a password, use the --video-password option', expected=True)
684 fields = self._hidden_inputs(login_form)
685 token, vuid = self._extract_xsrft_and_vuid(webpage)
686 fields['token'] = token
687 fields['password'] = password
688 post = urlencode_postdata(fields)
689 password_path = self._search_regex(
690 r'action="([^"]+)"', login_form, 'password URL')
691 password_url = compat_urlparse.urljoin(page_url, password_path)
692 password_request = sanitized_Request(password_url, post)
693 password_request.add_header('Content-type', 'application/x-www-form-urlencoded')
694 self._set_vimeo_cookie('vuid', vuid)
695 self._set_vimeo_cookie('xsrft', token)
696
697 return self._download_webpage(
698 password_request, list_id,
699 'Verifying the password', 'Wrong password')
700
701 def _title_and_entries(self, list_id, base_url):
702 for pagenum in itertools.count(1):
703 page_url = self._page_url(base_url, pagenum)
704 webpage = self._download_webpage(
705 page_url, list_id,
706 'Downloading page %s' % pagenum)
707
708 if pagenum == 1:
709 webpage = self._login_list_password(page_url, list_id, webpage)
710 yield self._extract_list_title(webpage)
711
712 # Try extracting href first since not all videos are available via
713 # short https://vimeo.com/id URL (e.g. https://vimeo.com/channels/tributes/6213729)
714 clips = re.findall(
715 r'id="clip_(\d+)"[^>]*>\s*<a[^>]+href="(/(?:[^/]+/)*\1)', webpage)
716 if clips:
717 for video_id, video_url in clips:
718 yield self.url_result(
719 compat_urlparse.urljoin(base_url, video_url),
720 VimeoIE.ie_key(), video_id=video_id)
721 # More relaxed fallback
722 else:
723 for video_id in re.findall(r'id=["\']clip_(\d+)', webpage):
724 yield self.url_result(
725 'https://vimeo.com/%s' % video_id,
726 VimeoIE.ie_key(), video_id=video_id)
727
728 if re.search(self._MORE_PAGES_INDICATOR, webpage, re.DOTALL) is None:
729 break
730
731 def _extract_videos(self, list_id, base_url):
732 title_and_entries = self._title_and_entries(list_id, base_url)
733 list_title = next(title_and_entries)
734 return self.playlist_result(title_and_entries, list_id, list_title)
735
736 def _real_extract(self, url):
737 mobj = re.match(self._VALID_URL, url)
738 channel_id = mobj.group('id')
739 return self._extract_videos(channel_id, 'https://vimeo.com/channels/%s' % channel_id)
740
741
742 class VimeoUserIE(VimeoChannelIE):
743 IE_NAME = 'vimeo:user'
744 _VALID_URL = r'https://vimeo\.com/(?!(?:[0-9]+|watchlater)(?:$|[?#/]))(?P<name>[^/]+)(?:/videos|[#?]|$)'
745 _TITLE_RE = r'<a[^>]+?class="user">([^<>]+?)</a>'
746 _TESTS = [{
747 'url': 'https://vimeo.com/nkistudio/videos',
748 'info_dict': {
749 'title': 'Nki',
750 'id': 'nkistudio',
751 },
752 'playlist_mincount': 66,
753 }]
754
755 def _real_extract(self, url):
756 mobj = re.match(self._VALID_URL, url)
757 name = mobj.group('name')
758 return self._extract_videos(name, 'https://vimeo.com/%s' % name)
759
760
761 class VimeoAlbumIE(VimeoChannelIE):
762 IE_NAME = 'vimeo:album'
763 _VALID_URL = r'https://vimeo\.com/album/(?P<id>\d+)(?:$|[?#]|/(?!video))'
764 _TITLE_RE = r'<header id="page_header">\n\s*<h1>(.*?)</h1>'
765 _TESTS = [{
766 'url': 'https://vimeo.com/album/2632481',
767 'info_dict': {
768 'id': '2632481',
769 'title': 'Staff Favorites: November 2013',
770 },
771 'playlist_mincount': 13,
772 }, {
773 'note': 'Password-protected album',
774 'url': 'https://vimeo.com/album/3253534',
775 'info_dict': {
776 'title': 'test',
777 'id': '3253534',
778 },
779 'playlist_count': 1,
780 'params': {
781 'videopassword': 'youtube-dl',
782 }
783 }, {
784 'url': 'https://vimeo.com/album/2632481/sort:plays/format:thumbnail',
785 'only_matching': True,
786 }, {
787 # TODO: respect page number
788 'url': 'https://vimeo.com/album/2632481/page:2/sort:plays/format:thumbnail',
789 'only_matching': True,
790 }]
791
792 def _page_url(self, base_url, pagenum):
793 return '%s/page:%d/' % (base_url, pagenum)
794
795 def _real_extract(self, url):
796 album_id = self._match_id(url)
797 return self._extract_videos(album_id, 'https://vimeo.com/album/%s' % album_id)
798
799
800 class VimeoGroupsIE(VimeoAlbumIE):
801 IE_NAME = 'vimeo:group'
802 _VALID_URL = r'https://vimeo\.com/groups/(?P<name>[^/]+)(?:/(?!videos?/\d+)|$)'
803 _TESTS = [{
804 'url': 'https://vimeo.com/groups/rolexawards',
805 'info_dict': {
806 'id': 'rolexawards',
807 'title': 'Rolex Awards for Enterprise',
808 },
809 'playlist_mincount': 73,
810 }]
811
812 def _extract_list_title(self, webpage):
813 return self._og_search_title(webpage)
814
815 def _real_extract(self, url):
816 mobj = re.match(self._VALID_URL, url)
817 name = mobj.group('name')
818 return self._extract_videos(name, 'https://vimeo.com/groups/%s' % name)
819
820
821 class VimeoReviewIE(VimeoBaseInfoExtractor):
822 IE_NAME = 'vimeo:review'
823 IE_DESC = 'Review pages on vimeo'
824 _VALID_URL = r'https://vimeo\.com/[^/]+/review/(?P<id>[^/]+)'
825 _TESTS = [{
826 'url': 'https://vimeo.com/user21297594/review/75524534/3c257a1b5d',
827 'md5': 'c507a72f780cacc12b2248bb4006d253',
828 'info_dict': {
829 'id': '75524534',
830 'ext': 'mp4',
831 'title': "DICK HARDWICK 'Comedian'",
832 'uploader': 'Richard Hardwick',
833 'uploader_id': 'user21297594',
834 }
835 }, {
836 'note': 'video player needs Referer',
837 'url': 'https://vimeo.com/user22258446/review/91613211/13f927e053',
838 'md5': '6295fdab8f4bf6a002d058b2c6dce276',
839 'info_dict': {
840 'id': '91613211',
841 'ext': 'mp4',
842 'title': 're:(?i)^Death by dogma versus assembling agile . Sander Hoogendoorn',
843 'uploader': 'DevWeek Events',
844 'duration': 2773,
845 'thumbnail': 're:^https?://.*\.jpg$',
846 'uploader_id': 'user22258446',
847 }
848 }, {
849 'note': 'Password protected',
850 'url': 'https://vimeo.com/user37284429/review/138823582/c4d865efde',
851 'info_dict': {
852 'id': '138823582',
853 'ext': 'mp4',
854 'title': 'EFFICIENT PICKUP MASTERCLASS MODULE 1',
855 'uploader': 'TMB',
856 'uploader_id': 'user37284429',
857 },
858 'params': {
859 'videopassword': 'holygrail',
860 },
861 'skip': 'video gone',
862 }]
863
864 def _real_initialize(self):
865 self._login()
866
867 def _get_config_url(self, webpage_url, video_id, video_password_verified=False):
868 webpage = self._download_webpage(webpage_url, video_id)
869 data = self._parse_json(self._search_regex(
870 r'window\s*=\s*_extend\(window,\s*({.+?})\);', webpage, 'data',
871 default=NO_DEFAULT if video_password_verified else '{}'), video_id)
872 config_url = data.get('vimeo_esi', {}).get('config', {}).get('configUrl')
873 if config_url is None:
874 self._verify_video_password(webpage_url, video_id, webpage)
875 config_url = self._get_config_url(
876 webpage_url, video_id, video_password_verified=True)
877 return config_url
878
879 def _real_extract(self, url):
880 video_id = self._match_id(url)
881 config_url = self._get_config_url(url, video_id)
882 config = self._download_json(config_url, video_id)
883 info_dict = self._parse_config(config, video_id)
884 self._vimeo_sort_formats(info_dict['formats'])
885 info_dict['id'] = video_id
886 return info_dict
887
888
889 class VimeoWatchLaterIE(VimeoChannelIE):
890 IE_NAME = 'vimeo:watchlater'
891 IE_DESC = 'Vimeo watch later list, "vimeowatchlater" keyword (requires authentication)'
892 _VALID_URL = r'https://vimeo\.com/(?:home/)?watchlater|:vimeowatchlater'
893 _TITLE = 'Watch Later'
894 _LOGIN_REQUIRED = True
895 _TESTS = [{
896 'url': 'https://vimeo.com/watchlater',
897 'only_matching': True,
898 }]
899
900 def _real_initialize(self):
901 self._login()
902
903 def _page_url(self, base_url, pagenum):
904 url = '%s/page:%d/' % (base_url, pagenum)
905 request = sanitized_Request(url)
906 # Set the header to get a partial html page with the ids,
907 # the normal page doesn't contain them.
908 request.add_header('X-Requested-With', 'XMLHttpRequest')
909 return request
910
911 def _real_extract(self, url):
912 return self._extract_videos('watchlater', 'https://vimeo.com/watchlater')
913
914
915 class VimeoLikesIE(InfoExtractor):
916 _VALID_URL = r'https://(?:www\.)?vimeo\.com/user(?P<id>[0-9]+)/likes/?(?:$|[?#]|sort:)'
917 IE_NAME = 'vimeo:likes'
918 IE_DESC = 'Vimeo user likes'
919 _TEST = {
920 'url': 'https://vimeo.com/user755559/likes/',
921 'playlist_mincount': 293,
922 'info_dict': {
923 'id': 'user755559_likes',
924 'description': 'See all the videos urza likes',
925 'title': 'Videos urza likes',
926 },
927 }
928
929 def _real_extract(self, url):
930 user_id = self._match_id(url)
931 webpage = self._download_webpage(url, user_id)
932 page_count = self._int(
933 self._search_regex(
934 r'''(?x)<li><a\s+href="[^"]+"\s+data-page="([0-9]+)">
935 .*?</a></li>\s*<li\s+class="pagination_next">
936 ''', webpage, 'page count'),
937 'page count', fatal=True)
938 PAGE_SIZE = 12
939 title = self._html_search_regex(
940 r'(?s)<h1>(.+?)</h1>', webpage, 'title', fatal=False)
941 description = self._html_search_meta('description', webpage)
942
943 def _get_page(idx):
944 page_url = 'https://vimeo.com/user%s/likes/page:%d/sort:date' % (
945 user_id, idx + 1)
946 webpage = self._download_webpage(
947 page_url, user_id,
948 note='Downloading page %d/%d' % (idx + 1, page_count))
949 video_list = self._search_regex(
950 r'(?s)<ol class="js-browse_list[^"]+"[^>]*>(.*?)</ol>',
951 webpage, 'video content')
952 paths = re.findall(
953 r'<li[^>]*>\s*<a\s+href="([^"]+)"', video_list)
954 for path in paths:
955 yield {
956 '_type': 'url',
957 'url': compat_urlparse.urljoin(page_url, path),
958 }
959
960 pl = InAdvancePagedList(_get_page, page_count, PAGE_SIZE)
961
962 return {
963 '_type': 'playlist',
964 'id': 'user%s_likes' % user_id,
965 'title': title,
966 'description': description,
967 'entries': pl,
968 }