2 from __future__
import unicode_literals
8 from .common
import InfoExtractor
9 from .subtitles
import SubtitlesInfoExtractor
10 from ..compat
import (
13 compat_urllib_request
,
27 class VimeoBaseInfoExtractor(InfoExtractor
):
28 _NETRC_MACHINE
= 'vimeo'
29 _LOGIN_REQUIRED
= False
32 (username
, password
) = self
._get
_login
_info
()
34 if self
._LOGIN
_REQUIRED
:
35 raise ExtractorError('No login info available, needed for using %s.' % self
.IE_NAME
, expected
=True)
38 login_url
= 'https://vimeo.com/log_in'
39 webpage
= self
._download
_webpage
(login_url
, None, False)
40 token
= self
._search
_regex
(r
'xsrft: \'(.*?
)\'', webpage, 'login token
')
41 data = urlencode_postdata({
48 login_request = compat_urllib_request.Request(login_url, data)
49 login_request.add_header('Content
-Type
', 'application
/x
-www
-form
-urlencoded
')
50 login_request.add_header('Cookie
', 'xsrft
=%s' % token)
51 self._download_webpage(login_request, None, False, 'Wrong login info
')
54 class VimeoIE(VimeoBaseInfoExtractor, SubtitlesInfoExtractor):
55 """Information extractor for vimeo.com."""
57 # _VALID_URL matches Vimeo URLs
60 (?:(?:www|(?P<player>player))\.)?
61 vimeo(?P<pro>pro)?\.com/
62 (?!channels/[^/?#]+/?(?:$|[?#])|album/)
64 (?:(?:play_redirect_hls|moogaloop\.swf)\?clip_id=)?
67 /?(?:[?&].*)?(?:[#].*)?$'''
71 'url
': 'http
://vimeo
.com
/56015672#at=0',
72 'md5': '8879b6cc097e987f02484baf890129e5',
76 "upload_date": "20121220",
77 "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",
78 "uploader_id": "user7108434",
79 "uploader": "Filippo Valsorda",
80 "title": "youtube-dl test video - \u2605 \" ' \u5e78 / \\ \u00e4 \u21ad \U0001d550",
85 'url': 'http://vimeopro.com/openstreetmapus/state-of-the-map-us-2013/video/68093876',
86 'md5': '3b5ca6aa22b60dfeeadf50b72e44ed82',
87 'note': 'Vimeo Pro video (#1197)',
91 'uploader_id': 'openstreetmapus',
92 'uploader': 'OpenStreetMap US',
93 'title': 'Andy Allan - Putting the Carto into OpenStreetMap Cartography',
94 'description': 'md5:380943ec71b89736ff4bf27183233d09',
99 'url': 'http://player.vimeo.com/video/54469442',
100 'md5': '619b811a4417aa4abe78dc653becf511',
101 'note': 'Videos that embed the url in the player page',
105 'title': 'Kathy Sierra: Building the minimum Badass User, Business of Software 2012',
106 'uploader': 'The BLN & Business of Software',
107 'uploader_id': 'theblnbusinessofsoftware',
113 'url': 'http://vimeo.com/68375962',
114 'md5': 'aaf896bdb7ddd6476df50007a0ac0ae7',
115 'note': 'Video protected with password',
119 'title': 'youtube-dl password protected test video',
120 'upload_date': '20130614',
121 'uploader_id': 'user18948128',
122 'uploader': 'Jaime Marquínez Ferrándiz',
124 '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 'videopassword': 'youtube-dl',
131 'url': 'http://vimeo.com/channels/keypeele/75629013',
132 'md5': '2f86a05afe9d7abc0b9126d229bbe15d',
133 'note': 'Video is freely available via original URL '
134 'and protected with password when accessed via http://vimeo.com/75629013',
138 'title': 'Key & Peele: Terrorist Interrogation',
139 'description': 'md5:8678b246399b070816b12313e8b4eb5c',
140 'uploader_id': 'atencio',
141 'uploader': 'Peter Atencio',
146 'url': 'http://vimeo.com/76979871',
147 'md5': '3363dd6ffebe3784d56f4132317fd446',
148 'note': 'Video with subtitles',
152 'title': 'The New Vimeo Player (You Know, For Videos)',
153 'description': 'md5:2ec900bf97c3f389378a96aee11260ea',
154 'upload_date': '20131015',
155 'uploader_id': 'staff',
156 'uploader': 'Vimeo Staff',
161 # from https://www.ouya.tv/game/Pier-Solar-and-the-Great-Architects/
162 'url': 'https://player.vimeo.com/video/98044508',
163 'note': 'The js code contains assignments to the same variable as the config',
167 'title': 'Pier Solar OUYA Official Trailer',
168 'uploader': 'Tulio Gonçalves',
169 'uploader_id': 'user28849593',
174 def _verify_video_password(self
, url
, video_id
, webpage
):
175 password
= self
._downloader
.params
.get('videopassword', None)
177 raise ExtractorError('This video is protected by a password, use the --video-password option')
178 token
= self
._search
_regex
(r
'xsrft: \'(.*?
)\'', webpage, 'login token
')
179 data = compat_urllib_parse.urlencode({
180 'password
': password,
183 # I didn't manage to use the password
with https
184 if url
.startswith('https'):
185 pass_url
= url
.replace('https', 'http')
188 password_request
= compat_urllib_request
.Request(pass_url
+ '/password', data
)
189 password_request
.add_header('Content-Type', 'application/x-www-form-urlencoded')
190 password_request
.add_header('Cookie', 'xsrft=%s' % token
)
191 self
._download
_webpage
(password_request
, video_id
,
192 'Verifying the password',
195 def _verify_player_video_password(self
, url
, video_id
):
196 password
= self
._downloader
.params
.get('videopassword', None)
198 raise ExtractorError('This video is protected by a password, use the --video-password option')
199 data
= compat_urllib_parse
.urlencode({'password': password
})
200 pass_url
= url
+ '/check-password'
201 password_request
= compat_urllib_request
.Request(pass_url
, data
)
202 password_request
.add_header('Content-Type', 'application/x-www-form-urlencoded')
203 return self
._download
_json
(
204 password_request
, video_id
,
205 'Verifying the password',
208 def _real_initialize(self
):
211 def _real_extract(self
, url
):
212 url
, data
= unsmuggle_url(url
)
213 headers
= std_headers
215 headers
= headers
.copy()
217 if 'Referer' not in headers
:
218 headers
['Referer'] = url
220 # Extract ID from URL
221 mobj
= re
.match(self
._VALID
_URL
, url
)
222 video_id
= mobj
.group('id')
224 if mobj
.group('pro') or mobj
.group('player'):
225 url
= 'http://player.vimeo.com/video/' + video_id
227 # Retrieve video webpage to extract further information
228 request
= compat_urllib_request
.Request(url
, None, headers
)
230 webpage
= self
._download
_webpage
(request
, video_id
)
231 except ExtractorError
as ee
:
232 if isinstance(ee
.cause
, compat_HTTPError
) and ee
.cause
.code
== 403:
233 errmsg
= ee
.cause
.read()
234 if b
'Because of its privacy settings, this video cannot be played here' in errmsg
:
235 raise ExtractorError(
236 'Cannot download embed-only video without embedding '
237 'URL. Please call youtube-dl with the URL of the page '
238 'that embeds this video.',
242 # Now we begin extracting as much information as we can from what we
243 # retrieved. First we extract the information common to all extractors,
244 # and latter we extract those that are Vimeo specific.
245 self
.report_extraction(video_id
)
247 # Extract the config JSON
250 config_url
= self
._html
_search
_regex
(
251 r
' data-config-url="(.+?)"', webpage
, 'config URL')
252 config_json
= self
._download
_webpage
(config_url
, video_id
)
253 config
= json
.loads(config_json
)
254 except RegexNotFoundError
:
255 # For pro videos or player.vimeo.com urls
256 # We try to find out to which variable is assigned the config dic
257 m_variable_name
= re
.search('(\w)\.video\.id', webpage
)
258 if m_variable_name
is not None:
259 config_re
= r
'%s=({[^}].+?});' % re
.escape(m_variable_name
.group(1))
261 config_re
= [r
' = {config:({.+?}),assets:', r
'(?:[abc])=({.+?});']
262 config
= self
._search
_regex
(config_re
, webpage
, 'info section',
264 config
= json
.loads(config
)
265 except Exception as e
:
266 if re
.search('The creator of this video has not given you permission to embed it on this domain.', webpage
):
267 raise ExtractorError('The author has restricted the access to this video, try with the "--referer" option')
269 if re
.search('<form[^>]+?id="pw_form"', webpage
) is not None:
270 self
._verify
_video
_password
(url
, video_id
, webpage
)
271 return self
._real
_extract
(url
)
273 raise ExtractorError('Unable to extract info section',
276 if config
.get('view') == 4:
277 config
= self
._verify
_player
_video
_password
(url
, video_id
)
280 video_title
= config
["video"]["title"]
282 # Extract uploader and uploader_id
283 video_uploader
= config
["video"]["owner"]["name"]
284 video_uploader_id
= config
["video"]["owner"]["url"].split('/')[-1] if config
["video"]["owner"]["url"] else None
286 # Extract video thumbnail
287 video_thumbnail
= config
["video"].get("thumbnail")
288 if video_thumbnail
is None:
289 video_thumbs
= config
["video"].get("thumbs")
290 if video_thumbs
and isinstance(video_thumbs
, dict):
291 _
, video_thumbnail
= sorted((int(width
if width
.isdigit() else 0), t_url
) for (width
, t_url
) in video_thumbs
.items())[-1]
293 # Extract video description
295 video_description
= self
._html
_search
_regex
(
296 r
'(?s)<div\s+class="[^"]*description[^"]*"[^>]*>(.*?)</div>',
297 webpage
, 'description', default
=None)
298 if not video_description
:
299 video_description
= self
._html
_search
_meta
(
300 'description', webpage
, default
=None)
301 if not video_description
and mobj
.group('pro'):
302 orig_webpage
= self
._download
_webpage
(
304 note
='Downloading webpage for description',
307 video_description
= self
._html
_search
_meta
(
308 'description', orig_webpage
, default
=None)
309 if not video_description
and not mobj
.group('player'):
310 self
._downloader
.report_warning('Cannot find video description')
312 # Extract video duration
313 video_duration
= int_or_none(config
["video"].get("duration"))
315 # Extract upload date
316 video_upload_date
= None
317 mobj
= re
.search(r
'<meta itemprop="dateCreated" content="(\d{4})-(\d{2})-(\d{2})T', webpage
)
319 video_upload_date
= mobj
.group(1) + mobj
.group(2) + mobj
.group(3)
322 view_count
= int(self
._search
_regex
(r
'UserPlays:(\d+)', webpage
, 'view count'))
323 like_count
= int(self
._search
_regex
(r
'UserLikes:(\d+)', webpage
, 'like count'))
324 comment_count
= int(self
._search
_regex
(r
'UserComments:(\d+)', webpage
, 'comment count'))
325 except RegexNotFoundError
:
326 # This info is only available in vimeo.com/{id} urls
331 # Vimeo specific: extract request signature and timestamp
332 sig
= config
['request']['signature']
333 timestamp
= config
['request']['timestamp']
335 # Vimeo specific: extract video codec and quality information
336 # First consider quality, then codecs, then take everything
337 codecs
= [('vp6', 'flv'), ('vp8', 'flv'), ('h264', 'mp4')]
338 files
= {'hd': [], 'sd': [], 'other': []}
339 config_files
= config
["video"].get("files") or config
["request"].get("files")
340 for codec_name
, codec_extension
in codecs
:
341 for quality
in config_files
.get(codec_name
, []):
342 format_id
= '-'.join((codec_name
, quality
)).lower()
343 key
= quality
if quality
in files
else 'other'
345 if isinstance(config_files
[codec_name
], dict):
346 file_info
= config_files
[codec_name
][quality
]
347 video_url
= file_info
.get('url')
350 if video_url
is None:
351 video_url
= "http://player.vimeo.com/play_redirect?clip_id=%s&sig=%s&time=%s&quality=%s&codecs=%s&type=moogaloop_local&embed_location=" \
352 % (video_id
, sig
, timestamp
, quality
, codec_name
.upper())
355 'ext': codec_extension
,
357 'format_id': format_id
,
358 'width': file_info
.get('width'),
359 'height': file_info
.get('height'),
362 for key
in ('other', 'sd', 'hd'):
363 formats
+= files
[key
]
364 if len(formats
) == 0:
365 raise ExtractorError('No known codec found')
368 text_tracks
= config
['request'].get('text_tracks')
370 for tt
in text_tracks
:
371 subtitles
[tt
['lang']] = 'http://vimeo.com' + tt
['url']
373 video_subtitles
= self
.extract_subtitles(video_id
, subtitles
)
374 if self
._downloader
.params
.get('listsubtitles', False):
375 self
._list
_available
_subtitles
(video_id
, subtitles
)
380 'uploader': video_uploader
,
381 'uploader_id': video_uploader_id
,
382 'upload_date': video_upload_date
,
383 'title': video_title
,
384 'thumbnail': video_thumbnail
,
385 'description': video_description
,
386 'duration': video_duration
,
389 'view_count': view_count
,
390 'like_count': like_count
,
391 'comment_count': comment_count
,
392 'subtitles': video_subtitles
,
396 class VimeoChannelIE(InfoExtractor
):
397 IE_NAME
= 'vimeo:channel'
398 _VALID_URL
= r
'https?://vimeo\.com/channels/(?P<id>[^/?#]+)/?(?:$|[?#])'
399 _MORE_PAGES_INDICATOR
= r
'<a.+?rel="next"'
400 _TITLE_RE
= r
'<link rel="alternate"[^>]+?title="(.*?)"'
402 'url': 'http://vimeo.com/channels/tributes',
404 'title': 'Vimeo Tributes',
406 'playlist_mincount': 25,
409 def _page_url(self
, base_url
, pagenum
):
410 return '%s/videos/page:%d/' % (base_url
, pagenum
)
412 def _extract_list_title(self
, webpage
):
413 return self
._html
_search
_regex
(self
._TITLE
_RE
, webpage
, 'list title')
415 def _extract_videos(self
, list_id
, base_url
):
417 for pagenum
in itertools
.count(1):
418 webpage
= self
._download
_webpage
(
419 self
._page
_url
(base_url
, pagenum
), list_id
,
420 'Downloading page %s' % pagenum
)
421 video_ids
.extend(re
.findall(r
'id="clip_(\d+?)"', webpage
))
422 if re
.search(self
._MORE
_PAGES
_INDICATOR
, webpage
, re
.DOTALL
) is None:
425 entries
= [self
.url_result('http://vimeo.com/%s' % video_id
, 'Vimeo')
426 for video_id
in video_ids
]
427 return {'_type': 'playlist',
429 'title': self
._extract
_list
_title
(webpage
),
433 def _real_extract(self
, url
):
434 mobj
= re
.match(self
._VALID
_URL
, url
)
435 channel_id
= mobj
.group('id')
436 return self
._extract
_videos
(channel_id
, 'http://vimeo.com/channels/%s' % channel_id
)
439 class VimeoUserIE(VimeoChannelIE
):
440 IE_NAME
= 'vimeo:user'
441 _VALID_URL
= r
'https?://vimeo\.com/(?![0-9]+(?:$|[?#/]))(?P<name>[^/]+)(?:/videos|[#?]|$)'
442 _TITLE_RE
= r
'<a[^>]+?class="user">([^<>]+?)</a>'
444 'url': 'http://vimeo.com/nkistudio/videos',
448 'playlist_mincount': 66,
451 def _real_extract(self
, url
):
452 mobj
= re
.match(self
._VALID
_URL
, url
)
453 name
= mobj
.group('name')
454 return self
._extract
_videos
(name
, 'http://vimeo.com/%s' % name
)
457 class VimeoAlbumIE(VimeoChannelIE
):
458 IE_NAME
= 'vimeo:album'
459 _VALID_URL
= r
'https?://vimeo\.com/album/(?P<id>\d+)'
460 _TITLE_RE
= r
'<header id="page_header">\n\s*<h1>(.*?)</h1>'
462 'url': 'http://vimeo.com/album/2632481',
464 'title': 'Staff Favorites: November 2013',
466 'playlist_mincount': 13,
469 def _page_url(self
, base_url
, pagenum
):
470 return '%s/page:%d/' % (base_url
, pagenum
)
472 def _real_extract(self
, url
):
473 mobj
= re
.match(self
._VALID
_URL
, url
)
474 album_id
= mobj
.group('id')
475 return self
._extract
_videos
(album_id
, 'http://vimeo.com/album/%s' % album_id
)
478 class VimeoGroupsIE(VimeoAlbumIE
):
479 IE_NAME
= 'vimeo:group'
480 _VALID_URL
= r
'(?:https?://)?vimeo\.com/groups/(?P<name>[^/]+)'
482 'url': 'http://vimeo.com/groups/rolexawards',
484 'title': 'Rolex Awards for Enterprise',
486 'playlist_mincount': 73,
489 def _extract_list_title(self
, webpage
):
490 return self
._og
_search
_title
(webpage
)
492 def _real_extract(self
, url
):
493 mobj
= re
.match(self
._VALID
_URL
, url
)
494 name
= mobj
.group('name')
495 return self
._extract
_videos
(name
, 'http://vimeo.com/groups/%s' % name
)
498 class VimeoReviewIE(InfoExtractor
):
499 IE_NAME
= 'vimeo:review'
500 IE_DESC
= 'Review pages on vimeo'
501 _VALID_URL
= r
'https?://vimeo\.com/[^/]+/review/(?P<id>[^/]+)'
503 'url': 'https://vimeo.com/user21297594/review/75524534/3c257a1b5d',
504 'md5': 'c507a72f780cacc12b2248bb4006d253',
508 'title': "DICK HARDWICK 'Comedian'",
509 'uploader': 'Richard Hardwick',
512 'note': 'video player needs Referer',
513 'url': 'http://vimeo.com/user22258446/review/91613211/13f927e053',
514 'md5': '6295fdab8f4bf6a002d058b2c6dce276',
518 'title': 're:(?i)^Death by dogma versus assembling agile . Sander Hoogendoorn',
519 'uploader': 'DevWeek Events',
521 'thumbnail': 're:^https?://.*\.jpg$',
525 def _real_extract(self
, url
):
526 mobj
= re
.match(self
._VALID
_URL
, url
)
527 video_id
= mobj
.group('id')
528 player_url
= 'https://player.vimeo.com/player/' + video_id
529 return self
.url_result(player_url
, 'Vimeo', video_id
)
532 class VimeoWatchLaterIE(VimeoBaseInfoExtractor
, VimeoChannelIE
):
533 IE_NAME
= 'vimeo:watchlater'
534 IE_DESC
= 'Vimeo watch later list, "vimeowatchlater" keyword (requires authentication)'
535 _VALID_URL
= r
'https?://vimeo\.com/home/watchlater|:vimeowatchlater'
536 _LOGIN_REQUIRED
= True
537 _TITLE_RE
= r
'href="/home/watchlater".*?>(.*?)<'
539 'url': 'http://vimeo.com/home/watchlater',
540 'only_matching': True,
543 def _real_initialize(self
):
546 def _page_url(self
, base_url
, pagenum
):
547 url
= '%s/page:%d/' % (base_url
, pagenum
)
548 request
= compat_urllib_request
.Request(url
)
549 # Set the header to get a partial html page with the ids,
550 # the normal page doesn't contain them.
551 request
.add_header('X-Requested-With', 'XMLHttpRequest')
554 def _real_extract(self
, url
):
555 return self
._extract
_videos
('watchlater', 'https://vimeo.com/home/watchlater')
558 class VimeoLikesIE(InfoExtractor
):
559 _VALID_URL
= r
'https?://(?:www\.)?vimeo\.com/user(?P<id>[0-9]+)/likes/?(?:$|[?#]|sort:)'
560 IE_NAME
= 'vimeo:likes'
561 IE_DESC
= 'Vimeo user likes'
563 'url': 'https://vimeo.com/user755559/likes/',
564 'playlist_mincount': 293,
566 "description": "See all the videos urza likes",
567 "title": 'Videos urza likes',
571 def _real_extract(self
, url
):
572 user_id
= self
._match
_id
(url
)
573 webpage
= self
._download
_webpage
(url
, user_id
)
574 page_count
= self
._int
(
576 r
'''(?x)<li><a\s+href="[^"]+"\s+data-page="([0-9]+)">
577 .*?</a></li>\s*<li\s+class="pagination_next">
578 ''', webpage
, 'page count'),
579 'page count', fatal
=True)
581 title
= self
._html
_search
_regex
(
582 r
'(?s)<h1>(.+?)</h1>', webpage
, 'title', fatal
=False)
583 description
= self
._html
_search
_meta
('description', webpage
)
586 page_url
= '%s//vimeo.com/user%s/likes/page:%d/sort:date' % (
587 self
.http_scheme(), user_id
, idx
+ 1)
588 webpage
= self
._download
_webpage
(
590 note
='Downloading page %d/%d' % (idx
+ 1, page_count
))
591 video_list
= self
._search
_regex
(
592 r
'(?s)<ol class="js-browse_list[^"]+"[^>]*>(.*?)</ol>',
593 webpage
, 'video content')
595 r
'<li[^>]*>\s*<a\s+href="([^"]+)"', video_list
)
599 'url': compat_urlparse
.urljoin(page_url
, path
),
602 pl
= InAdvancePagedList(_get_page
, page_count
, PAGE_SIZE
)
606 'id': 'user%s_likes' % user_id
,
608 'description': description
,