2 from __future__
import unicode_literals
8 from .common
import InfoExtractor
9 from .subtitles
import SubtitlesInfoExtractor
13 compat_urllib_request
,
15 get_element_by_attribute
,
25 class VimeoBaseInfoExtractor(InfoExtractor
):
26 _NETRC_MACHINE
= 'vimeo'
27 _LOGIN_REQUIRED
= False
30 (username
, password
) = self
._get
_login
_info
()
32 if self
._LOGIN
_REQUIRED
:
33 raise ExtractorError('No login info available, needed for using %s.' % self
.IE_NAME
, expected
=True)
36 login_url
= 'https://vimeo.com/log_in'
37 webpage
= self
._download
_webpage
(login_url
, None, False)
38 token
= self
._search
_regex
(r
'xsrft: \'(.*?
)\'', webpage, 'login token
')
39 data = urlencode_postdata({
46 login_request = compat_urllib_request.Request(login_url, data)
47 login_request.add_header('Content
-Type
', 'application
/x
-www
-form
-urlencoded
')
48 login_request.add_header('Cookie
', 'xsrft
=%s' % token)
49 self._download_webpage(login_request, None, False, 'Wrong login info
')
52 class VimeoIE(VimeoBaseInfoExtractor, SubtitlesInfoExtractor):
53 """Information extractor for vimeo.com."""
55 # _VALID_URL matches Vimeo URLs
57 (?P<proto>(?:https?:)?//)?
58 (?:(?:www|(?P<player>player))\.)?
59 vimeo(?P<pro>pro)?\.com/
60 (?!channels/[^/?#]+/?(?:$|[?#])|album/)
62 (?:(?:play_redirect_hls|moogaloop\.swf)\?clip_id=)?
65 /?(?:[?&].*)?(?:[#].*)?$'''
69 'url
': 'http
://vimeo
.com
/56015672#at=0',
70 'md5': '8879b6cc097e987f02484baf890129e5',
74 "upload_date": "20121220",
75 "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",
76 "uploader_id": "user7108434",
77 "uploader": "Filippo Valsorda",
78 "title": "youtube-dl test video - \u2605 \" ' \u5e78 / \\ \u00e4 \u21ad \U0001d550",
83 'url': 'http://vimeopro.com/openstreetmapus/state-of-the-map-us-2013/video/68093876',
84 'md5': '3b5ca6aa22b60dfeeadf50b72e44ed82',
85 'note': 'Vimeo Pro video (#1197)',
89 'uploader_id': 'openstreetmapus',
90 'uploader': 'OpenStreetMap US',
91 'title': 'Andy Allan - Putting the Carto into OpenStreetMap Cartography',
96 'url': 'http://player.vimeo.com/video/54469442',
97 'md5': '619b811a4417aa4abe78dc653becf511',
98 'note': 'Videos that embed the url in the player page',
102 'title': 'Kathy Sierra: Building the minimum Badass User, Business of Software 2012',
103 'uploader': 'The BLN & Business of Software',
104 'uploader_id': 'theblnbusinessofsoftware',
109 'url': 'http://vimeo.com/68375962',
110 'md5': 'aaf896bdb7ddd6476df50007a0ac0ae7',
111 'note': 'Video protected with password',
115 'title': 'youtube-dl password protected test video',
116 'upload_date': '20130614',
117 'uploader_id': 'user18948128',
118 'uploader': 'Jaime Marquínez Ferrándiz',
122 'videopassword': 'youtube-dl',
126 'url': 'http://vimeo.com/channels/keypeele/75629013',
127 'md5': '2f86a05afe9d7abc0b9126d229bbe15d',
128 'note': 'Video is freely available via original URL '
129 'and protected with password when accessed via http://vimeo.com/75629013',
133 'title': 'Key & Peele: Terrorist Interrogation',
134 'description': 'md5:8678b246399b070816b12313e8b4eb5c',
135 'uploader_id': 'atencio',
136 'uploader': 'Peter Atencio',
141 'url': 'http://vimeo.com/76979871',
142 'md5': '3363dd6ffebe3784d56f4132317fd446',
143 'note': 'Video with subtitles',
147 'title': 'The New Vimeo Player (You Know, For Videos)',
148 'description': 'md5:2ec900bf97c3f389378a96aee11260ea',
149 'upload_date': '20131015',
150 'uploader_id': 'staff',
151 'uploader': 'Vimeo Staff',
157 def _verify_video_password(self
, url
, video_id
, webpage
):
158 password
= self
._downloader
.params
.get('videopassword', None)
160 raise ExtractorError('This video is protected by a password, use the --video-password option')
161 token
= self
._search
_regex
(r
'xsrft: \'(.*?
)\'', webpage, 'login token
')
162 data = compat_urllib_parse.urlencode({
163 'password
': password,
166 # I didn't manage to use the password
with https
167 if url
.startswith('https'):
168 pass_url
= url
.replace('https', 'http')
171 password_request
= compat_urllib_request
.Request(pass_url
+ '/password', data
)
172 password_request
.add_header('Content-Type', 'application/x-www-form-urlencoded')
173 password_request
.add_header('Cookie', 'xsrft=%s' % token
)
174 self
._download
_webpage
(password_request
, video_id
,
175 'Verifying the password',
178 def _verify_player_video_password(self
, url
, video_id
):
179 password
= self
._downloader
.params
.get('videopassword', None)
181 raise ExtractorError('This video is protected by a password, use the --video-password option')
182 data
= compat_urllib_parse
.urlencode({'password': password}
)
183 pass_url
= url
+ '/check-password'
184 password_request
= compat_urllib_request
.Request(pass_url
, data
)
185 password_request
.add_header('Content-Type', 'application/x-www-form-urlencoded')
186 return self
._download
_json
(
187 password_request
, video_id
,
188 'Verifying the password',
191 def _real_initialize(self
):
194 def _real_extract(self
, url
):
195 url
, data
= unsmuggle_url(url
)
196 headers
= std_headers
198 headers
= headers
.copy()
200 if 'Referer' not in headers
:
201 headers
['Referer'] = url
203 # Extract ID from URL
204 mobj
= re
.match(self
._VALID
_URL
, url
)
205 video_id
= mobj
.group('id')
206 if mobj
.group('pro') or mobj
.group('player'):
207 url
= 'http://player.vimeo.com/video/' + video_id
209 # Retrieve video webpage to extract further information
210 request
= compat_urllib_request
.Request(url
, None, headers
)
212 webpage
= self
._download
_webpage
(request
, video_id
)
213 except ExtractorError
as ee
:
214 if isinstance(ee
.cause
, compat_HTTPError
) and ee
.cause
.code
== 403:
215 errmsg
= ee
.cause
.read()
216 if b
'Because of its privacy settings, this video cannot be played here' in errmsg
:
217 raise ExtractorError(
218 'Cannot download embed-only video without embedding '
219 'URL. Please call youtube-dl with the URL of the page '
220 'that embeds this video.',
224 # Now we begin extracting as much information as we can from what we
225 # retrieved. First we extract the information common to all extractors,
226 # and latter we extract those that are Vimeo specific.
227 self
.report_extraction(video_id
)
229 # Extract the config JSON
232 config_url
= self
._html
_search
_regex
(
233 r
' data-config-url="(.+?)"', webpage
, 'config URL')
234 config_json
= self
._download
_webpage
(config_url
, video_id
)
235 config
= json
.loads(config_json
)
236 except RegexNotFoundError
:
237 # For pro videos or player.vimeo.com urls
238 # We try to find out to which variable is assigned the config dic
239 m_variable_name
= re
.search('(\w)\.video\.id', webpage
)
240 if m_variable_name
is not None:
241 config_re
= r
'%s=({.+?});' % re
.escape(m_variable_name
.group(1))
243 config_re
= [r
' = {config:({.+?}),assets:', r
'(?:[abc])=({.+?});']
244 config
= self
._search
_regex
(config_re
, webpage
, 'info section',
246 config
= json
.loads(config
)
247 except Exception as e
:
248 if re
.search('The creator of this video has not given you permission to embed it on this domain.', webpage
):
249 raise ExtractorError('The author has restricted the access to this video, try with the "--referer" option')
251 if re
.search('<form[^>]+?id="pw_form"', webpage
) is not None:
252 self
._verify
_video
_password
(url
, video_id
, webpage
)
253 return self
._real
_extract
(url
)
255 raise ExtractorError('Unable to extract info section',
258 if config
.get('view') == 4:
259 config
= self
._verify
_player
_video
_password
(url
, video_id
)
262 video_title
= config
["video"]["title"]
264 # Extract uploader and uploader_id
265 video_uploader
= config
["video"]["owner"]["name"]
266 video_uploader_id
= config
["video"]["owner"]["url"].split('/')[-1] if config
["video"]["owner"]["url"] else None
268 # Extract video thumbnail
269 video_thumbnail
= config
["video"].get("thumbnail")
270 if video_thumbnail
is None:
271 video_thumbs
= config
["video"].get("thumbs")
272 if video_thumbs
and isinstance(video_thumbs
, dict):
273 _
, video_thumbnail
= sorted((int(width
if width
.isdigit() else 0), t_url
) for (width
, t_url
) in video_thumbs
.items())[-1]
275 # Extract video description
276 video_description
= None
278 video_description
= get_element_by_attribute("class", "description_wrapper", webpage
)
279 if video_description
:
280 video_description
= clean_html(video_description
)
281 except AssertionError as err
:
282 # On some pages like (http://player.vimeo.com/video/54469442) the
283 # html tags are not closed, python 2.6 cannot handle it
284 if err
.args
[0] == 'we should not get here!':
289 # Extract video duration
290 video_duration
= int_or_none(config
["video"].get("duration"))
292 # Extract upload date
293 video_upload_date
= None
294 mobj
= re
.search(r
'<meta itemprop="dateCreated" content="(\d{4})-(\d{2})-(\d{2})T', webpage
)
296 video_upload_date
= mobj
.group(1) + mobj
.group(2) + mobj
.group(3)
299 view_count
= int(self
._search
_regex
(r
'UserPlays:(\d+)', webpage
, 'view count'))
300 like_count
= int(self
._search
_regex
(r
'UserLikes:(\d+)', webpage
, 'like count'))
301 comment_count
= int(self
._search
_regex
(r
'UserComments:(\d+)', webpage
, 'comment count'))
302 except RegexNotFoundError
:
303 # This info is only available in vimeo.com/{id} urls
308 # Vimeo specific: extract request signature and timestamp
309 sig
= config
['request']['signature']
310 timestamp
= config
['request']['timestamp']
312 # Vimeo specific: extract video codec and quality information
313 # First consider quality, then codecs, then take everything
314 codecs
= [('vp6', 'flv'), ('vp8', 'flv'), ('h264', 'mp4')]
315 files
= {'hd': [], 'sd': [], 'other': []}
316 config_files
= config
["video"].get("files") or config
["request"].get("files")
317 for codec_name
, codec_extension
in codecs
:
318 for quality
in config_files
.get(codec_name
, []):
319 format_id
= '-'.join((codec_name
, quality
)).lower()
320 key
= quality
if quality
in files
else 'other'
322 if isinstance(config_files
[codec_name
], dict):
323 file_info
= config_files
[codec_name
][quality
]
324 video_url
= file_info
.get('url')
327 if video_url
is None:
328 video_url
= "http://player.vimeo.com/play_redirect?clip_id=%s&sig=%s&time=%s&quality=%s&codecs=%s&type=moogaloop_local&embed_location=" \
329 % (video_id
, sig
, timestamp
, quality
, codec_name
.upper())
332 'ext': codec_extension
,
334 'format_id': format_id
,
335 'width': file_info
.get('width'),
336 'height': file_info
.get('height'),
339 for key
in ('other', 'sd', 'hd'):
340 formats
+= files
[key
]
341 if len(formats
) == 0:
342 raise ExtractorError('No known codec found')
345 text_tracks
= config
['request'].get('text_tracks')
347 for tt
in text_tracks
:
348 subtitles
[tt
['lang']] = 'http://vimeo.com' + tt
['url']
350 video_subtitles
= self
.extract_subtitles(video_id
, subtitles
)
351 if self
._downloader
.params
.get('listsubtitles', False):
352 self
._list
_available
_subtitles
(video_id
, subtitles
)
357 'uploader': video_uploader
,
358 'uploader_id': video_uploader_id
,
359 'upload_date': video_upload_date
,
360 'title': video_title
,
361 'thumbnail': video_thumbnail
,
362 'description': video_description
,
363 'duration': video_duration
,
366 'view_count': view_count
,
367 'like_count': like_count
,
368 'comment_count': comment_count
,
369 'subtitles': video_subtitles
,
373 class VimeoChannelIE(InfoExtractor
):
374 IE_NAME
= 'vimeo:channel'
375 _VALID_URL
= r
'https?://vimeo\.com/channels/(?P<id>[^/?#]+)/?(?:$|[?#])'
376 _MORE_PAGES_INDICATOR
= r
'<a.+?rel="next"'
377 _TITLE_RE
= r
'<link rel="alternate"[^>]+?title="(.*?)"'
379 'url': 'http://vimeo.com/channels/tributes',
381 'title': 'Vimeo Tributes',
383 'playlist_mincount': 25,
386 def _page_url(self
, base_url
, pagenum
):
387 return '%s/videos/page:%d/' % (base_url
, pagenum
)
389 def _extract_list_title(self
, webpage
):
390 return self
._html
_search
_regex
(self
._TITLE
_RE
, webpage
, 'list title')
392 def _extract_videos(self
, list_id
, base_url
):
394 for pagenum
in itertools
.count(1):
395 webpage
= self
._download
_webpage
(
396 self
._page
_url
(base_url
, pagenum
), list_id
,
397 'Downloading page %s' % pagenum
)
398 video_ids
.extend(re
.findall(r
'id="clip_(\d+?)"', webpage
))
399 if re
.search(self
._MORE
_PAGES
_INDICATOR
, webpage
, re
.DOTALL
) is None:
402 entries
= [self
.url_result('http://vimeo.com/%s' % video_id
, 'Vimeo')
403 for video_id
in video_ids
]
404 return {'_type': 'playlist',
406 'title': self
._extract
_list
_title
(webpage
),
410 def _real_extract(self
, url
):
411 mobj
= re
.match(self
._VALID
_URL
, url
)
412 channel_id
= mobj
.group('id')
413 return self
._extract
_videos
(channel_id
, 'http://vimeo.com/channels/%s' % channel_id
)
416 class VimeoUserIE(VimeoChannelIE
):
417 IE_NAME
= 'vimeo:user'
418 _VALID_URL
= r
'https?://vimeo\.com/(?![0-9]+(?:$|[?#/]))(?P<name>[^/]+)(?:/videos|[#?]|$)'
419 _TITLE_RE
= r
'<a[^>]+?class="user">([^<>]+?)</a>'
421 'url': 'http://vimeo.com/nkistudio/videos',
425 'playlist_mincount': 66,
428 def _real_extract(self
, url
):
429 mobj
= re
.match(self
._VALID
_URL
, url
)
430 name
= mobj
.group('name')
431 return self
._extract
_videos
(name
, 'http://vimeo.com/%s' % name
)
434 class VimeoAlbumIE(VimeoChannelIE
):
435 IE_NAME
= 'vimeo:album'
436 _VALID_URL
= r
'https?://vimeo\.com/album/(?P<id>\d+)'
437 _TITLE_RE
= r
'<header id="page_header">\n\s*<h1>(.*?)</h1>'
439 'url': 'http://vimeo.com/album/2632481',
441 'title': 'Staff Favorites: November 2013',
443 'playlist_mincount': 13,
446 def _page_url(self
, base_url
, pagenum
):
447 return '%s/page:%d/' % (base_url
, pagenum
)
449 def _real_extract(self
, url
):
450 mobj
= re
.match(self
._VALID
_URL
, url
)
451 album_id
= mobj
.group('id')
452 return self
._extract
_videos
(album_id
, 'http://vimeo.com/album/%s' % album_id
)
455 class VimeoGroupsIE(VimeoAlbumIE
):
456 IE_NAME
= 'vimeo:group'
457 _VALID_URL
= r
'(?:https?://)?vimeo\.com/groups/(?P<name>[^/]+)'
459 'url': 'http://vimeo.com/groups/rolexawards',
461 'title': 'Rolex Awards for Enterprise',
463 'playlist_mincount': 73,
466 def _extract_list_title(self
, webpage
):
467 return self
._og
_search
_title
(webpage
)
469 def _real_extract(self
, url
):
470 mobj
= re
.match(self
._VALID
_URL
, url
)
471 name
= mobj
.group('name')
472 return self
._extract
_videos
(name
, 'http://vimeo.com/groups/%s' % name
)
475 class VimeoReviewIE(InfoExtractor
):
476 IE_NAME
= 'vimeo:review'
477 IE_DESC
= 'Review pages on vimeo'
478 _VALID_URL
= r
'https?://vimeo\.com/[^/]+/review/(?P<id>[^/]+)'
480 'url': 'https://vimeo.com/user21297594/review/75524534/3c257a1b5d',
481 'file': '75524534.mp4',
482 'md5': 'c507a72f780cacc12b2248bb4006d253',
484 'title': "DICK HARDWICK 'Comedian'",
485 'uploader': 'Richard Hardwick',
488 'note': 'video player needs Referer',
489 'url': 'http://vimeo.com/user22258446/review/91613211/13f927e053',
490 'md5': '6295fdab8f4bf6a002d058b2c6dce276',
494 'title': 'Death by dogma versus assembling agile - Sander Hoogendoorn',
495 'uploader': 'DevWeek Events',
497 'thumbnail': 're:^https?://.*\.jpg$',
501 def _real_extract(self
, url
):
502 mobj
= re
.match(self
._VALID
_URL
, url
)
503 video_id
= mobj
.group('id')
504 player_url
= 'https://player.vimeo.com/player/' + video_id
505 return self
.url_result(player_url
, 'Vimeo', video_id
)
508 class VimeoWatchLaterIE(VimeoBaseInfoExtractor
, VimeoChannelIE
):
509 IE_NAME
= 'vimeo:watchlater'
510 IE_DESC
= 'Vimeo watch later list, "vimeowatchlater" keyword (requires authentication)'
511 _VALID_URL
= r
'https?://vimeo\.com/home/watchlater|:vimeowatchlater'
512 _LOGIN_REQUIRED
= True
513 _TITLE_RE
= r
'href="/home/watchlater".*?>(.*?)<'
515 'url': 'http://vimeo.com/home/watchlater',
516 'only_matching': True,
519 def _real_initialize(self
):
522 def _page_url(self
, base_url
, pagenum
):
523 url
= '%s/page:%d/' % (base_url
, pagenum
)
524 request
= compat_urllib_request
.Request(url
)
525 # Set the header to get a partial html page with the ids,
526 # the normal page doesn't contain them.
527 request
.add_header('X-Requested-With', 'XMLHttpRequest')
530 def _real_extract(self
, url
):
531 return self
._extract
_videos
('watchlater', 'https://vimeo.com/home/watchlater')