2 from __future__
import unicode_literals
8 from .common
import InfoExtractor
12 compat_urllib_request
,
26 class VimeoBaseInfoExtractor(InfoExtractor
):
27 _NETRC_MACHINE
= 'vimeo'
28 _LOGIN_REQUIRED
= False
31 (username
, password
) = self
._get
_login
_info
()
33 if self
._LOGIN
_REQUIRED
:
34 raise ExtractorError('No login info available, needed for using %s.' % self
.IE_NAME
, expected
=True)
37 login_url
= 'https://vimeo.com/log_in'
38 webpage
= self
._download
_webpage
(login_url
, None, False)
39 token
= self
._search
_regex
(r
'xsrft: \'(.*?
)\'', webpage, 'login token
')
40 data = urlencode_postdata({
47 login_request = compat_urllib_request.Request(login_url, data)
48 login_request.add_header('Content
-Type
', 'application
/x
-www
-form
-urlencoded
')
49 login_request.add_header('Cookie
', 'xsrft
=%s' % token)
50 self._download_webpage(login_request, None, False, 'Wrong login info
')
53 class VimeoIE(VimeoBaseInfoExtractor):
54 """Information extractor for vimeo.com."""
56 # _VALID_URL matches Vimeo URLs
59 (?:(?:www|(?P<player>player))\.)?
60 vimeo(?P<pro>pro)?\.com/
61 (?!channels/[^/?#]+/?(?:$|[?#])|album/)
63 (?:(?:play_redirect_hls|moogaloop\.swf)\?clip_id=)?
66 /?(?:[?&].*)?(?:[#].*)?$'''
70 'url
': 'http
://vimeo
.com
/56015672#at=0',
71 'md5': '8879b6cc097e987f02484baf890129e5',
75 "upload_date": "20121220",
76 "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",
77 "uploader_id": "user7108434",
78 "uploader": "Filippo Valsorda",
79 "title": "youtube-dl test video - \u2605 \" ' \u5e78 / \\ \u00e4 \u21ad \U0001d550",
84 'url': 'http://vimeopro.com/openstreetmapus/state-of-the-map-us-2013/video/68093876',
85 'md5': '3b5ca6aa22b60dfeeadf50b72e44ed82',
86 'note': 'Vimeo Pro video (#1197)',
90 'uploader_id': 'openstreetmapus',
91 'uploader': 'OpenStreetMap US',
92 'title': 'Andy Allan - Putting the Carto into OpenStreetMap Cartography',
93 'description': 'md5:380943ec71b89736ff4bf27183233d09',
98 'url': 'http://player.vimeo.com/video/54469442',
99 'md5': '619b811a4417aa4abe78dc653becf511',
100 'note': 'Videos that embed the url in the player page',
104 'title': 'Kathy Sierra: Building the minimum Badass User, Business of Software 2012',
105 'uploader': 'The BLN & Business of Software',
106 'uploader_id': 'theblnbusinessofsoftware',
112 'url': 'http://vimeo.com/68375962',
113 'md5': 'aaf896bdb7ddd6476df50007a0ac0ae7',
114 'note': 'Video protected with password',
118 'title': 'youtube-dl password protected test video',
119 'upload_date': '20130614',
120 'uploader_id': 'user18948128',
121 'uploader': 'Jaime Marquínez Ferrándiz',
123 '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.',
126 'videopassword': 'youtube-dl',
130 'url': 'http://vimeo.com/channels/keypeele/75629013',
131 'md5': '2f86a05afe9d7abc0b9126d229bbe15d',
132 'note': 'Video is freely available via original URL '
133 'and protected with password when accessed via http://vimeo.com/75629013',
137 'title': 'Key & Peele: Terrorist Interrogation',
138 'description': 'md5:8678b246399b070816b12313e8b4eb5c',
139 'uploader_id': 'atencio',
140 'uploader': 'Peter Atencio',
145 'url': 'http://vimeo.com/76979871',
146 'md5': '3363dd6ffebe3784d56f4132317fd446',
147 'note': 'Video with subtitles',
151 'title': 'The New Vimeo Player (You Know, For Videos)',
152 'description': 'md5:2ec900bf97c3f389378a96aee11260ea',
153 'upload_date': '20131015',
154 'uploader_id': 'staff',
155 'uploader': 'Vimeo Staff',
160 # from https://www.ouya.tv/game/Pier-Solar-and-the-Great-Architects/
161 'url': 'https://player.vimeo.com/video/98044508',
162 'note': 'The js code contains assignments to the same variable as the config',
166 'title': 'Pier Solar OUYA Official Trailer',
167 'uploader': 'Tulio Gonçalves',
168 'uploader_id': 'user28849593',
173 def _verify_video_password(self
, url
, video_id
, webpage
):
174 password
= self
._downloader
.params
.get('videopassword', None)
176 raise ExtractorError('This video is protected by a password, use the --video-password option')
177 token
= self
._search
_regex
(r
'xsrft: \'(.*?
)\'', webpage, 'login token
')
178 data = compat_urllib_parse.urlencode({
179 'password
': password,
182 # I didn't manage to use the password
with https
183 if url
.startswith('https'):
184 pass_url
= url
.replace('https', 'http')
187 password_request
= compat_urllib_request
.Request(pass_url
+ '/password', data
)
188 password_request
.add_header('Content-Type', 'application/x-www-form-urlencoded')
189 password_request
.add_header('Cookie', 'xsrft=%s' % token
)
190 return self
._download
_webpage
(
191 password_request
, video_id
,
192 'Verifying the password', 'Wrong password')
194 def _verify_player_video_password(self
, url
, video_id
):
195 password
= self
._downloader
.params
.get('videopassword', None)
197 raise ExtractorError('This video is protected by a password, use the --video-password option')
198 data
= compat_urllib_parse
.urlencode({'password': password}
)
199 pass_url
= url
+ '/check-password'
200 password_request
= compat_urllib_request
.Request(pass_url
, data
)
201 password_request
.add_header('Content-Type', 'application/x-www-form-urlencoded')
202 return self
._download
_json
(
203 password_request
, video_id
,
204 'Verifying the password',
207 def _real_initialize(self
):
210 def _real_extract(self
, url
):
211 url
, data
= unsmuggle_url(url
)
212 headers
= std_headers
214 headers
= headers
.copy()
216 if 'Referer' not in headers
:
217 headers
['Referer'] = url
219 # Extract ID from URL
220 mobj
= re
.match(self
._VALID
_URL
, url
)
221 video_id
= mobj
.group('id')
223 if mobj
.group('pro') or mobj
.group('player'):
224 url
= 'http://player.vimeo.com/video/' + video_id
226 # Retrieve video webpage to extract further information
227 request
= compat_urllib_request
.Request(url
, None, headers
)
229 webpage
= self
._download
_webpage
(request
, video_id
)
230 except ExtractorError
as ee
:
231 if isinstance(ee
.cause
, compat_HTTPError
) and ee
.cause
.code
== 403:
232 errmsg
= ee
.cause
.read()
233 if b
'Because of its privacy settings, this video cannot be played here' in errmsg
:
234 raise ExtractorError(
235 'Cannot download embed-only video without embedding '
236 'URL. Please call youtube-dl with the URL of the page '
237 'that embeds this video.',
241 # Now we begin extracting as much information as we can from what we
242 # retrieved. First we extract the information common to all extractors,
243 # and latter we extract those that are Vimeo specific.
244 self
.report_extraction(video_id
)
246 # Extract the config JSON
249 config_url
= self
._html
_search
_regex
(
250 r
' data-config-url="(.+?)"', webpage
, 'config URL')
251 config_json
= self
._download
_webpage
(config_url
, video_id
)
252 config
= json
.loads(config_json
)
253 except RegexNotFoundError
:
254 # For pro videos or player.vimeo.com urls
255 # We try to find out to which variable is assigned the config dic
256 m_variable_name
= re
.search('(\w)\.video\.id', webpage
)
257 if m_variable_name
is not None:
258 config_re
= r
'%s=({[^}].+?});' % re
.escape(m_variable_name
.group(1))
260 config_re
= [r
' = {config:({.+?}),assets:', r
'(?:[abc])=({.+?});']
261 config
= self
._search
_regex
(config_re
, webpage
, 'info section',
263 config
= json
.loads(config
)
264 except Exception as e
:
265 if re
.search('The creator of this video has not given you permission to embed it on this domain.', webpage
):
266 raise ExtractorError('The author has restricted the access to this video, try with the "--referer" option')
268 if re
.search(r
'<form[^>]+?id="pw_form"', webpage
) is not None:
269 self
._verify
_video
_password
(url
, video_id
, webpage
)
270 return self
._real
_extract
(url
)
272 raise ExtractorError('Unable to extract info section',
275 if config
.get('view') == 4:
276 config
= self
._verify
_player
_video
_password
(url
, video_id
)
279 video_title
= config
["video"]["title"]
281 # Extract uploader and uploader_id
282 video_uploader
= config
["video"]["owner"]["name"]
283 video_uploader_id
= config
["video"]["owner"]["url"].split('/')[-1] if config
["video"]["owner"]["url"] else None
285 # Extract video thumbnail
286 video_thumbnail
= config
["video"].get("thumbnail")
287 if video_thumbnail
is None:
288 video_thumbs
= config
["video"].get("thumbs")
289 if video_thumbs
and isinstance(video_thumbs
, dict):
290 _
, video_thumbnail
= sorted((int(width
if width
.isdigit() else 0), t_url
) for (width
, t_url
) in video_thumbs
.items())[-1]
292 # Extract video description
294 video_description
= self
._html
_search
_regex
(
295 r
'(?s)<div\s+class="[^"]*description[^"]*"[^>]*>(.*?)</div>',
296 webpage
, 'description', default
=None)
297 if not video_description
:
298 video_description
= self
._html
_search
_meta
(
299 'description', webpage
, default
=None)
300 if not video_description
and mobj
.group('pro'):
301 orig_webpage
= self
._download
_webpage
(
303 note
='Downloading webpage for description',
306 video_description
= self
._html
_search
_meta
(
307 'description', orig_webpage
, default
=None)
308 if not video_description
and not mobj
.group('player'):
309 self
._downloader
.report_warning('Cannot find video description')
311 # Extract video duration
312 video_duration
= int_or_none(config
["video"].get("duration"))
314 # Extract upload date
315 video_upload_date
= None
316 mobj
= re
.search(r
'<meta itemprop="dateCreated" content="(\d{4})-(\d{2})-(\d{2})T', webpage
)
318 video_upload_date
= mobj
.group(1) + mobj
.group(2) + mobj
.group(3)
321 view_count
= int(self
._search
_regex
(r
'UserPlays:(\d+)', webpage
, 'view count'))
322 like_count
= int(self
._search
_regex
(r
'UserLikes:(\d+)', webpage
, 'like count'))
323 comment_count
= int(self
._search
_regex
(r
'UserComments:(\d+)', webpage
, 'comment count'))
324 except RegexNotFoundError
:
325 # This info is only available in vimeo.com/{id} urls
330 # Vimeo specific: extract request signature and timestamp
331 sig
= config
['request']['signature']
332 timestamp
= config
['request']['timestamp']
334 # Vimeo specific: extract video codec and quality information
335 # First consider quality, then codecs, then take everything
336 codecs
= [('vp6', 'flv'), ('vp8', 'flv'), ('h264', 'mp4')]
337 files
= {'hd': [], 'sd': [], 'other': []}
338 config_files
= config
["video"].get("files") or config
["request"].get("files")
339 for codec_name
, codec_extension
in codecs
:
340 for quality
in config_files
.get(codec_name
, []):
341 format_id
= '-'.join((codec_name
, quality
)).lower()
342 key
= quality
if quality
in files
else 'other'
344 if isinstance(config_files
[codec_name
], dict):
345 file_info
= config_files
[codec_name
][quality
]
346 video_url
= file_info
.get('url')
349 if video_url
is None:
350 video_url
= "http://player.vimeo.com/play_redirect?clip_id=%s&sig=%s&time=%s&quality=%s&codecs=%s&type=moogaloop_local&embed_location=" \
351 % (video_id
, sig
, timestamp
, quality
, codec_name
.upper())
354 'ext': codec_extension
,
356 'format_id': format_id
,
357 'width': file_info
.get('width'),
358 'height': file_info
.get('height'),
361 for key
in ('other', 'sd', 'hd'):
362 formats
+= files
[key
]
363 if len(formats
) == 0:
364 raise ExtractorError('No known codec found')
367 text_tracks
= config
['request'].get('text_tracks')
369 for tt
in text_tracks
:
370 subtitles
[tt
['lang']] = [{
372 'url': 'http://vimeo.com' + tt
['url'],
377 'uploader': video_uploader
,
378 'uploader_id': video_uploader_id
,
379 'upload_date': video_upload_date
,
380 'title': video_title
,
381 'thumbnail': video_thumbnail
,
382 'description': video_description
,
383 'duration': video_duration
,
386 'view_count': view_count
,
387 'like_count': like_count
,
388 'comment_count': comment_count
,
389 'subtitles': subtitles
,
393 class VimeoChannelIE(InfoExtractor
):
394 IE_NAME
= 'vimeo:channel'
395 _VALID_URL
= r
'https?://vimeo\.com/channels/(?P<id>[^/?#]+)/?(?:$|[?#])'
396 _MORE_PAGES_INDICATOR
= r
'<a.+?rel="next"'
397 _TITLE_RE
= r
'<link rel="alternate"[^>]+?title="(.*?)"'
399 'url': 'http://vimeo.com/channels/tributes',
401 'title': 'Vimeo Tributes',
403 'playlist_mincount': 25,
406 def _page_url(self
, base_url
, pagenum
):
407 return '%s/videos/page:%d/' % (base_url
, pagenum
)
409 def _extract_list_title(self
, webpage
):
410 return self
._html
_search
_regex
(self
._TITLE
_RE
, webpage
, 'list title')
412 def _login_list_password(self
, page_url
, list_id
, webpage
):
413 login_form
= self
._search
_regex
(
414 r
'(?s)<form[^>]+?id="pw_form"(.*?)</form>',
415 webpage
, 'login form', default
=None)
419 password
= self
._downloader
.params
.get('videopassword', None)
421 raise ExtractorError('This album is protected by a password, use the --video-password option', expected
=True)
422 fields
= dict(re
.findall(r
'''(?x)<input\s+
427 token
= self
._search
_regex
(r
'xsrft: \'(.*?
)\'', webpage, 'login token
')
428 fields['token
'] = token
429 fields['password
'] = password
430 post = compat_urllib_parse.urlencode(fields)
431 password_path = self._search_regex(
432 r'action
="([^"]+)"', login_form, 'password URL')
433 password_url = compat_urlparse.urljoin(page_url, password_path)
434 password_request = compat_urllib_request.Request(password_url, post)
435 password_request.add_header('Content-type', 'application/x-www-form-urlencoded')
436 self._set_cookie('vimeo.com', 'xsrft', token)
438 return self._download_webpage(
439 password_request, list_id,
440 'Verifying the password', 'Wrong password')
442 def _extract_videos(self, list_id, base_url):
444 for pagenum in itertools.count(1):
445 page_url = self._page_url(base_url, pagenum)
446 webpage = self._download_webpage(
448 'Downloading page %s' % pagenum)
451 webpage = self._login_list_password(page_url, list_id, webpage)
453 video_ids.extend(re.findall(r'id="clip_(\d
+?
)"', webpage))
454 if re.search(self._MORE_PAGES_INDICATOR, webpage, re.DOTALL) is None:
457 entries = [self.url_result('http://vimeo.com/%s' % video_id, 'Vimeo')
458 for video_id in video_ids]
459 return {'_type': 'playlist',
461 'title': self._extract_list_title(webpage),
465 def _real_extract(self, url):
466 mobj = re.match(self._VALID_URL, url)
467 channel_id = mobj.group('id')
468 return self._extract_videos(channel_id, 'http://vimeo.com/channels/%s' % channel_id)
471 class VimeoUserIE(VimeoChannelIE):
472 IE_NAME = 'vimeo:user'
473 _VALID_URL = r'https?://vimeo\.com/(?![0-9]+(?:$|[?#/]))(?P<name>[^/]+)(?:/videos|[#?]|$)'
474 _TITLE_RE = r'<a[^>]+?class="user
">([^<>]+?)</a>'
476 'url': 'http://vimeo.com/nkistudio/videos',
480 'playlist_mincount': 66,
483 def _real_extract(self, url):
484 mobj = re.match(self._VALID_URL, url)
485 name = mobj.group('name')
486 return self._extract_videos(name, 'http://vimeo.com/%s' % name)
489 class VimeoAlbumIE(VimeoChannelIE):
490 IE_NAME = 'vimeo:album'
491 _VALID_URL = r'https?://vimeo\.com/album/(?P<id>\d+)'
492 _TITLE_RE = r'<header id="page_header
">\n\s*<h1>(.*?)</h1>'
494 'url': 'http://vimeo.com/album/2632481',
496 'title': 'Staff Favorites: November 2013',
498 'playlist_mincount': 13,
500 'note': 'Password-protected album',
501 'url': 'https://vimeo.com/album/3253534',
508 'videopassword': 'youtube-dl',
512 def _page_url(self, base_url, pagenum):
513 return '%s/page:%d/' % (base_url, pagenum)
515 def _real_extract(self, url):
516 album_id = self._match_id(url)
517 return self._extract_videos(album_id, 'http://vimeo.com/album/%s' % album_id)
520 class VimeoGroupsIE(VimeoAlbumIE):
521 IE_NAME = 'vimeo:group'
522 _VALID_URL = r'(?:https?://)?vimeo\.com/groups/(?P<name>[^/]+)'
524 'url': 'http://vimeo.com/groups/rolexawards',
526 'title': 'Rolex Awards for Enterprise',
528 'playlist_mincount': 73,
531 def _extract_list_title(self, webpage):
532 return self._og_search_title(webpage)
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, 'http://vimeo.com/groups/%s' % name)
540 class VimeoReviewIE(InfoExtractor):
541 IE_NAME = 'vimeo:review'
542 IE_DESC = 'Review pages on vimeo'
543 _VALID_URL = r'https?://vimeo\.com/[^/]+/review/(?P<id>[^/]+)'
545 'url': 'https://vimeo.com/user21297594/review/75524534/3c257a1b5d',
546 'md5': 'c507a72f780cacc12b2248bb4006d253',
550 'title': "DICK HARDWICK
'Comedian'",
551 'uploader': 'Richard Hardwick',
554 'note': 'video player needs Referer',
555 'url': 'http://vimeo.com/user22258446/review/91613211/13f927e053',
556 'md5': '6295fdab8f4bf6a002d058b2c6dce276',
560 'title': 're:(?i)^Death by dogma versus assembling agile . Sander Hoogendoorn',
561 'uploader': 'DevWeek Events',
563 'thumbnail': 're:^https?://.*\.jpg$',
567 def _real_extract(self, url):
568 mobj = re.match(self._VALID_URL, url)
569 video_id = mobj.group('id')
570 player_url = 'https://player.vimeo.com/player/' + video_id
571 return self.url_result(player_url, 'Vimeo', video_id)
574 class VimeoWatchLaterIE(VimeoBaseInfoExtractor, VimeoChannelIE):
575 IE_NAME = 'vimeo:watchlater'
576 IE_DESC = 'Vimeo watch later list, "vimeowatchlater
" keyword (requires authentication)'
577 _VALID_URL = r'https?://vimeo\.com/home/watchlater|:vimeowatchlater'
578 _LOGIN_REQUIRED = True
579 _TITLE_RE = r'href="/home
/watchlater
".*?>(.*?)<'
581 'url': 'http://vimeo.com/home/watchlater',
582 'only_matching': True,
585 def _real_initialize(self):
588 def _page_url(self, base_url, pagenum):
589 url = '%s/page:%d/' % (base_url, pagenum)
590 request = compat_urllib_request.Request(url)
591 # Set the header to get a partial html page with the ids,
592 # the normal page doesn't contain them.
593 request.add_header('X-Requested-With', 'XMLHttpRequest')
596 def _real_extract(self, url):
597 return self._extract_videos('watchlater', 'https://vimeo.com/home/watchlater')
600 class VimeoLikesIE(InfoExtractor):
601 _VALID_URL = r'https?://(?:www\.)?vimeo\.com/user(?P<id>[0-9]+)/likes/?(?:$|[?#]|sort:)'
602 IE_NAME = 'vimeo:likes'
603 IE_DESC = 'Vimeo user likes'
605 'url': 'https://vimeo.com/user755559/likes/',
606 'playlist_mincount': 293,
608 "description
": "See all the videos urza likes
",
609 "title
": 'Videos urza likes',
613 def _real_extract(self, url):
614 user_id = self._match_id(url)
615 webpage = self._download_webpage(url, user_id)
616 page_count = self._int(
618 r'''(?x)<li><a\s+href="[^
"]+"\s
+data
-page
="([0-9]+)">
619 .*?
</a
></li
>\s
*<li\s
+class="pagination_next">
620 ''', webpage, 'page count'),
621 'page count', fatal=True)
623 title = self._html_search_regex(
624 r'(?s)<h1>(.+?)</h1>', webpage, 'title', fatal=False)
625 description = self._html_search_meta('description', webpage)
628 page_url = '%s//vimeo.com/user%s/likes/page:%d/sort:date' % (
629 self.http_scheme(), user_id, idx + 1)
630 webpage = self._download_webpage(
632 note='Downloading page %d/%d' % (idx + 1, page_count))
633 video_list = self._search_regex(
634 r'(?s)<ol class="js-browse_list[^"]+"[^>]*>(.*?)</ol>',
635 webpage, 'video content')
637 r'<li[^>]*>\s*<a\s+href="([^"]+)"', video_list)
641 'url': compat_urlparse.urljoin(page_url, path),
644 pl = InAdvancePagedList(_get_page, page_count, PAGE_SIZE)
648 'id': 'user%s_likes' % user_id,
650 'description': description,