]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/vimeo.py
Ensure pre-processor errors do not block video download
[yt-dlp.git] / yt_dlp / extractor / vimeo.py
CommitLineData
79fec976 1import base64
eb9c9c74 2import functools
b3d14cbf 3import re
caeefc29 4import itertools
b3d14cbf
PH
5
6from .common import InfoExtractor
8c25f81b 7from ..compat import (
1060425c 8 compat_HTTPError,
6a55bb66 9 compat_str,
9c44d242 10 compat_urlparse,
8c25f81b
PH
11)
12from ..utils import (
681ac7c9 13 clean_html,
d5f071af 14 determine_ext,
b3d14cbf 15 ExtractorError,
58ab5cbc 16 get_element_by_class,
9cb070f9 17 HEADRequest,
ca01d178 18 js_to_json,
9c44d242 19 int_or_none,
ae1c585c 20 merge_dicts,
eb9c9c74 21 OnDemandPagedList,
ca01d178 22 parse_filesize,
cce889b9 23 parse_iso8601,
4dfbf869 24 parse_qs,
67dda517 25 sanitized_Request,
30965ac6 26 smuggle_url,
681ac7c9 27 str_or_none,
c15cd296 28 try_get,
c15cd296 29 unified_timestamp,
9d4660ca 30 unsmuggle_url,
a980bc43 31 urlencode_postdata,
1c45ff55 32 urljoin,
b407e173 33 unescapeHTML,
9cb070f9 34 urlhandle_detect_ext,
b3d14cbf
PH
35)
36
bbafbe20 37
efb7e119
JMF
38class VimeoBaseInfoExtractor(InfoExtractor):
39 _NETRC_MACHINE = 'vimeo'
40 _LOGIN_REQUIRED = False
f6c3664d 41 _LOGIN_URL = 'https://vimeo.com/log_in'
efb7e119 42
aedaa455 43 @staticmethod
44 def _smuggle_referrer(url, referrer_url):
45 return smuggle_url(url, {'http_headers': {'Referer': referrer_url}})
46
47 def _unsmuggle_headers(self, url):
48 """@returns (url, smuggled_data, headers)"""
49 url, data = unsmuggle_url(url, {})
50 headers = self.get_param('http_headers').copy()
51 if 'http_headers' in data:
52 headers.update(data['http_headers'])
53 return url, data, headers
54
52efa4b3 55 def _perform_login(self, username, password):
26ad6bcd
S
56 webpage = self._download_webpage(
57 self._LOGIN_URL, None, 'Downloading login page')
7c845629 58 token, vuid = self._extract_xsrft_and_vuid(webpage)
26ad6bcd 59 data = {
f6c3664d 60 'action': 'login',
efb7e119
JMF
61 'email': username,
62 'password': password,
efb7e119
JMF
63 'service': 'vimeo',
64 'token': token,
26ad6bcd 65 }
9eab37dc 66 self._set_vimeo_cookie('vuid', vuid)
26ad6bcd
S
67 try:
68 self._download_webpage(
69 self._LOGIN_URL, None, 'Logging in',
70 data=urlencode_postdata(data), headers={
71 'Content-Type': 'application/x-www-form-urlencoded',
72 'Referer': self._LOGIN_URL,
73 })
74 except ExtractorError as e:
75 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 418:
76 raise ExtractorError(
77 'Unable to log in: bad username or password',
78 expected=True)
79 raise ExtractorError('Unable to log in')
efb7e119 80
52efa4b3 81 def _real_initialize(self):
82 if self._LOGIN_REQUIRED and not self._get_cookies('https://vimeo.com').get('vuid'):
83 self._raise_login_required()
84
cce889b9 85 def _get_video_password(self):
a06916d9 86 password = self.get_param('videopassword')
c1ff6e1a 87 if password is None:
cce889b9 88 raise ExtractorError(
89 'This video is protected by a password, use the --video-password option',
90 expected=True)
91 return password
92
93 def _verify_video_password(self, url, video_id, password, token, vuid):
c1ff6e1a
YCH
94 if url.startswith('http://'):
95 # vimeo only supports https now, but the user can give an http url
96 url = url.replace('http://', 'https://')
c1ff6e1a
YCH
97 self._set_vimeo_cookie('vuid', vuid)
98 return self._download_webpage(
cce889b9 99 url + '/password', video_id, 'Verifying the password',
100 'Wrong password', data=urlencode_postdata({
101 'password': password,
102 'token': token,
103 }), headers={
104 'Content-Type': 'application/x-www-form-urlencoded',
105 'Referer': url,
106 })
c1ff6e1a 107
7c845629
S
108 def _extract_xsrft_and_vuid(self, webpage):
109 xsrft = self._search_regex(
b826035d 110 r'(?:(?P<q1>["\'])xsrft(?P=q1)\s*:|xsrft\s*[=:])\s*(?P<q>["\'])(?P<xsrft>.+?)(?P=q)',
f6c3664d 111 webpage, 'login token', group='xsrft')
7c845629
S
112 vuid = self._search_regex(
113 r'["\']vuid["\']\s*:\s*(["\'])(?P<vuid>.+?)\1',
114 webpage, 'vuid', group='vuid')
115 return xsrft, vuid
f6c3664d 116
eb9c9c74
RA
117 def _extract_vimeo_config(self, webpage, video_id, *args, **kwargs):
118 vimeo_config = self._search_regex(
119 r'vimeo\.config\s*=\s*(?:({.+?})|_extend\([^,]+,\s+({.+?})\));',
f9934b96 120 webpage, 'vimeo config', *args, **kwargs)
eb9c9c74
RA
121 if vimeo_config:
122 return self._parse_json(vimeo_config, video_id)
123
9eab37dc
S
124 def _set_vimeo_cookie(self, name, value):
125 self._set_cookie('vimeo.com', name, value)
126
531a7496 127 def _vimeo_sort_formats(self, formats):
bc104778 128 # Note: Bitrates are completely broken. Single m3u8 may contain entries in kbps and bps
129 # at the same time without actual units specified.
130 self._sort_formats(formats, ('quality', 'res', 'fps', 'hdr:12', 'source'))
531a7496
YCH
131
132 def _parse_config(self, config, video_id):
d8c507c9 133 video_data = config['video']
24146491 134 video_title = video_data.get('title')
85b6335d
RA
135 live_event = video_data.get('live_event') or {}
136 is_live = live_event.get('status') == 'started'
58ab5cbc 137 request = config.get('request') or {}
531a7496
YCH
138
139 formats = []
3f047fc4
F
140 subtitles = {}
141
58ab5cbc 142 config_files = video_data.get('files') or request.get('files') or {}
143 for f in (config_files.get('progressive') or []):
531a7496
YCH
144 video_url = f.get('url')
145 if not video_url:
146 continue
147 formats.append({
148 'url': video_url,
149 'format_id': 'http-%s' % f.get('quality'),
bc104778 150 'source_preference': 10,
531a7496
YCH
151 'width': int_or_none(f.get('width')),
152 'height': int_or_none(f.get('height')),
153 'fps': int_or_none(f.get('fps')),
154 'tbr': int_or_none(f.get('bitrate')),
155 })
d8c507c9 156
85b6335d 157 # TODO: fix handling of 308 status code returned for live archive manifest requests
52c50a10 158 sep_pattern = r'/sep/video/'
d8c507c9 159 for files_type in ('hls', 'dash'):
58ab5cbc 160 for cdn_name, cdn_data in (try_get(config_files, lambda x: x[files_type]['cdns']) or {}).items():
d8c507c9
RA
161 manifest_url = cdn_data.get('url')
162 if not manifest_url:
163 continue
164 format_id = '%s-%s' % (files_type, cdn_name)
52c50a10
RA
165 sep_manifest_urls = []
166 if re.search(sep_pattern, manifest_url):
167 for suffix, repl in (('', 'video'), ('_sep', 'sep/video')):
168 sep_manifest_urls.append((format_id + suffix, re.sub(
169 sep_pattern, '/%s/' % repl, manifest_url)))
170 else:
171 sep_manifest_urls = [(format_id, manifest_url)]
172 for f_id, m_url in sep_manifest_urls:
173 if files_type == 'hls':
3f047fc4 174 fmts, subs = self._extract_m3u8_formats_and_subtitles(
a5c0c202 175 m_url, video_id, 'mp4', live=is_live, m3u8_id=f_id,
52c50a10 176 note='Downloading %s m3u8 information' % cdn_name,
3f047fc4
F
177 fatal=False)
178 formats.extend(fmts)
179 self._merge_subtitles(subs, target=subtitles)
52c50a10 180 elif files_type == 'dash':
c25720ef
RA
181 if 'json=1' in m_url:
182 real_m_url = (self._download_json(m_url, video_id, fatal=False) or {}).get('url')
183 if real_m_url:
184 m_url = real_m_url
3f047fc4 185 fmts, subs = self._extract_mpd_formats_and_subtitles(
ae9a173b
RA
186 m_url.replace('/master.json', '/master.mpd'), video_id, f_id,
187 'Downloading %s MPD information' % cdn_name,
e834f044 188 fatal=False)
3f047fc4
F
189 formats.extend(fmts)
190 self._merge_subtitles(subs, target=subtitles)
531a7496 191
85b6335d
RA
192 live_archive = live_event.get('archive') or {}
193 live_archive_source_url = live_archive.get('source_url')
194 if live_archive_source_url and live_archive.get('status') == 'done':
195 formats.append({
196 'format_id': 'live-archive-source',
197 'url': live_archive_source_url,
f983b875 198 'quality': 10,
85b6335d
RA
199 })
200
58ab5cbc 201 for tt in (request.get('text_tracks') or []):
3f047fc4 202 subtitles.setdefault(tt['lang'], []).append({
58ab5cbc 203 'ext': 'vtt',
204 'url': urljoin('https://vimeo.com', tt['url']),
3f047fc4 205 })
531a7496 206
c25720ef
RA
207 thumbnails = []
208 if not is_live:
58ab5cbc 209 for key, thumb in (video_data.get('thumbs') or {}).items():
c25720ef
RA
210 thumbnails.append({
211 'id': key,
212 'width': int_or_none(key),
213 'url': thumb,
214 })
215 thumbnail = video_data.get('thumbnail')
216 if thumbnail:
217 thumbnails.append({
218 'url': thumbnail,
219 })
220
221 owner = video_data.get('owner') or {}
222 video_uploader_url = owner.get('url')
223
818faa3a 224 duration = int_or_none(video_data.get('duration'))
225 chapter_data = try_get(config, lambda x: x['embed']['chapters']) or []
226 chapters = [{
227 'title': current_chapter.get('title'),
228 'start_time': current_chapter.get('timecode'),
229 'end_time': next_chapter.get('timecode'),
230 } for current_chapter, next_chapter in zip(chapter_data, chapter_data[1:] + [{'timecode': duration}])]
231 if chapters and chapters[0]['start_time']: # Chapters may not start from 0
232 chapters[:0] = [{'title': '<Untitled>', 'start_time': 0, 'end_time': chapters[0]['start_time']}]
233
531a7496 234 return {
681ac7c9 235 'id': str_or_none(video_data.get('id')) or video_id,
39ca3b5c 236 'title': video_title,
c25720ef
RA
237 'uploader': owner.get('name'),
238 'uploader_id': video_uploader_url.split('/')[-1] if video_uploader_url else None,
531a7496 239 'uploader_url': video_uploader_url,
c25720ef 240 'thumbnails': thumbnails,
818faa3a 241 'duration': duration,
242 'chapters': chapters or None,
531a7496
YCH
243 'formats': formats,
244 'subtitles': subtitles,
c25720ef 245 'is_live': is_live,
531a7496
YCH
246 }
247
bc2ca1bb 248 def _extract_original_format(self, url, video_id, unlisted_hash=None):
249 query = {'action': 'load_download_config'}
250 if unlisted_hash:
251 query['unlisted_hash'] = unlisted_hash
27655037 252 download_data = self._download_json(
bc2ca1bb 253 url, video_id, fatal=False, query=query,
9cb070f9 254 headers={'X-Requested-With': 'XMLHttpRequest'},
255 expected_status=(403, 404)) or {}
256 source_file = download_data.get('source_file')
257 download_url = try_get(source_file, lambda x: x['download_url'])
258 if download_url and not source_file.get('is_cold') and not source_file.get('is_defrosting'):
259 source_name = source_file.get('public_name', 'Original')
260 if self._is_valid_url(download_url, video_id, '%s video' % source_name):
261 ext = (try_get(
262 source_file, lambda x: x['extension'],
263 compat_str) or determine_ext(
264 download_url, None) or 'mp4').lower()
265 return {
266 'url': download_url,
267 'ext': ext,
268 'width': int_or_none(source_file.get('width')),
269 'height': int_or_none(source_file.get('height')),
270 'filesize': parse_filesize(source_file.get('size')),
271 'format_id': source_name,
272 'quality': 1,
273 }
27655037 274
605cad0b
A
275 jwt_response = self._download_json(
276 'https://vimeo.com/_rv/viewer', video_id, note='Downloading jwt token', fatal=False) or {}
277 if not jwt_response.get('jwt'):
278 return
279 headers = {'Authorization': 'jwt %s' % jwt_response['jwt']}
280 original_response = self._download_json(
281 f'https://api.vimeo.com/videos/{video_id}', video_id,
9cb070f9 282 headers=headers, fatal=False, expected_status=(403, 404)) or {}
283 for download_data in original_response.get('download') or []:
605cad0b
A
284 download_url = download_data.get('link')
285 if not download_url or download_data.get('quality') != 'source':
286 continue
9cb070f9 287 ext = determine_ext(parse_qs(download_url).get('filename', [''])[0].lower(), default_ext=None)
288 if not ext:
289 urlh = self._request_webpage(
290 HEADRequest(download_url), video_id, fatal=False, note='Determining source extension')
291 ext = urlh and urlhandle_detect_ext(urlh)
605cad0b
A
292 return {
293 'url': download_url,
9cb070f9 294 'ext': ext or 'unknown_video',
605cad0b
A
295 'format_id': download_data.get('public_name', 'Original'),
296 'width': int_or_none(download_data.get('width')),
297 'height': int_or_none(download_data.get('height')),
298 'fps': int_or_none(download_data.get('fps')),
299 'filesize': int_or_none(download_data.get('size')),
300 'quality': 1,
301 }
302
efb7e119 303
65469a7f 304class VimeoIE(VimeoBaseInfoExtractor):
b3d14cbf
PH
305 """Information extractor for vimeo.com."""
306
307 # _VALID_URL matches Vimeo URLs
bbafbe20 308 _VALID_URL = r'''(?x)
74278def
S
309 https?://
310 (?:
311 (?:
312 www|
681ac7c9 313 player
74278def
S
314 )
315 \.
316 )?
681ac7c9 317 vimeo(?:pro)?\.com/
eb9c9c74 318 (?!(?:channels|album|showcase)/[^/?#]+/?(?:$|[?#])|[^/]+/review/|ondemand/)
2a6f8475 319 (?:[^/]+/)*?
74278def
S
320 (?:
321 (?:
322 play_redirect_hls|
323 moogaloop\.swf)\?clip_id=
324 )?
325 (?:videos?/)?
326 (?P<id>[0-9]+)
cce889b9 327 (?:/(?P<unlisted_hash>[\da-f]{10}))?
74278def
S
328 /?(?:[?&].*)?(?:[#].*)?$
329 '''
9148eb00 330 IE_NAME = 'vimeo'
a91b954b
JMF
331 _TESTS = [
332 {
9148eb00 333 'url': 'http://vimeo.com/56015672#at=0',
9148eb00
PH
334 'md5': '8879b6cc097e987f02484baf890129e5',
335 'info_dict': {
ad5976b4
PH
336 'id': '56015672',
337 'ext': 'mp4',
b9c7b1e9 338 'title': "youtube-dl test video '' ä↭𝕐-BaW jenozKc",
681ac7c9 339 'description': 'md5:2d3305bad981a06ff79f027f19865021',
c15cd296 340 'timestamp': 1355990239,
68f3b61f 341 'upload_date': '20121220',
ec85ded8 342 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/user7108434',
68f3b61f
S
343 'uploader_id': 'user7108434',
344 'uploader': 'Filippo Valsorda',
345 'duration': 10,
c38a67bc 346 'license': 'by-sa',
a91b954b 347 },
681ac7c9
RA
348 'params': {
349 'format': 'best[protocol=https]',
350 },
b9c7b1e9 351 'skip': 'No longer available'
a91b954b
JMF
352 },
353 {
9148eb00 354 'url': 'http://vimeopro.com/openstreetmapus/state-of-the-map-us-2013/video/68093876',
9148eb00
PH
355 'md5': '3b5ca6aa22b60dfeeadf50b72e44ed82',
356 'note': 'Vimeo Pro video (#1197)',
357 'info_dict': {
4f3e9430
JMF
358 'id': '68093876',
359 'ext': 'mp4',
ec85ded8 360 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/openstreetmapus',
9148eb00
PH
361 'uploader_id': 'openstreetmapus',
362 'uploader': 'OpenStreetMap US',
363 'title': 'Andy Allan - Putting the Carto into OpenStreetMap Cartography',
681ac7c9 364 'description': 'md5:2c362968038d4499f4d79f88458590c1',
69c8fb9e 365 'duration': 1595,
681ac7c9
RA
366 'upload_date': '20130610',
367 'timestamp': 1370893156,
58ab5cbc 368 'license': 'by',
b9c7b1e9 369 'thumbnail': 'https://i.vimeocdn.com/video/440260469-19b0d92fca3bd84066623b53f1eb8aaa3980c6c809e2d67b6b39ab7b4a77a344-d_960',
370 'view_count': int,
371 'comment_count': int,
372 'like_count': int,
681ac7c9
RA
373 },
374 'params': {
375 'format': 'best[protocol=https]',
a91b954b
JMF
376 },
377 },
aa32314d 378 {
9148eb00 379 'url': 'http://player.vimeo.com/video/54469442',
b9c7b1e9 380 'md5': 'b3e7f4d2cbb53bd7dc3bb6ff4ed5cfbd',
9148eb00
PH
381 'note': 'Videos that embed the url in the player page',
382 'info_dict': {
4f3e9430
JMF
383 'id': '54469442',
384 'ext': 'mp4',
0e6ebc13 385 'title': 'Kathy Sierra: Building the minimum Badass User, Business of Software 2012',
cce889b9 386 'uploader': 'Business of Software',
387 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/businessofsoftware',
388 'uploader_id': 'businessofsoftware',
69c8fb9e 389 'duration': 3610,
58ea7ec8 390 'description': None,
b9c7b1e9 391 'thumbnail': 'https://i.vimeocdn.com/video/376682406-f34043e7b766af6bef2af81366eacd6724f3fc3173179a11a97a1e26587c9529-d_1280',
aa32314d 392 },
681ac7c9
RA
393 'params': {
394 'format': 'best[protocol=https]',
395 },
93b22c78
JMF
396 },
397 {
9148eb00 398 'url': 'http://vimeo.com/68375962',
9148eb00
PH
399 'md5': 'aaf896bdb7ddd6476df50007a0ac0ae7',
400 'note': 'Video protected with password',
401 'info_dict': {
4f3e9430
JMF
402 'id': '68375962',
403 'ext': 'mp4',
3867038a 404 'title': 'youtube-dl password protected test video',
c15cd296 405 'timestamp': 1371200155,
9148eb00 406 'upload_date': '20130614',
ec85ded8 407 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/user18948128',
9148eb00
PH
408 'uploader_id': 'user18948128',
409 'uploader': 'Jaime Marquínez Ferrándiz',
69c8fb9e 410 'duration': 10,
365d136b 411 'description': 'md5:dca3ea23adb29ee387127bc4ddfce63f',
b9c7b1e9 412 'thumbnail': 'https://i.vimeocdn.com/video/440665496-b2c5aee2b61089442c794f64113a8e8f7d5763c3e6b3ebfaf696ae6413f8b1f4-d_960',
413 'view_count': int,
414 'comment_count': int,
415 'like_count': int,
93b22c78 416 },
9148eb00 417 'params': {
681ac7c9 418 'format': 'best[protocol=https]',
3867038a 419 'videopassword': 'youtube-dl',
93b22c78
JMF
420 },
421 },
548f31d9
S
422 {
423 'url': 'http://vimeo.com/channels/keypeele/75629013',
424 'md5': '2f86a05afe9d7abc0b9126d229bbe15d',
548f31d9
S
425 'info_dict': {
426 'id': '75629013',
427 'ext': 'mp4',
428 'title': 'Key & Peele: Terrorist Interrogation',
429 'description': 'md5:8678b246399b070816b12313e8b4eb5c',
ec85ded8 430 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/atencio',
548f31d9
S
431 'uploader_id': 'atencio',
432 'uploader': 'Peter Atencio',
d03beddf
S
433 'channel_id': 'keypeele',
434 'channel_url': r're:https?://(?:www\.)?vimeo\.com/channels/keypeele',
c15cd296
S
435 'timestamp': 1380339469,
436 'upload_date': '20130928',
548f31d9 437 'duration': 187,
b9c7b1e9 438 'thumbnail': 'https://i.vimeocdn.com/video/450239872-a05512d9b1e55d707a7c04365c10980f327b06d966351bc403a5d5d65c95e572-d_1280',
439 'view_count': int,
440 'comment_count': int,
441 'like_count': int,
548f31d9 442 },
9cb070f9 443 'params': {'format': 'http-1080p'},
548f31d9 444 },
1eac553e
S
445 {
446 'url': 'http://vimeo.com/76979871',
1eac553e
S
447 'note': 'Video with subtitles',
448 'info_dict': {
449 'id': '76979871',
b9c7b1e9 450 'ext': 'mov',
1eac553e
S
451 'title': 'The New Vimeo Player (You Know, For Videos)',
452 'description': 'md5:2ec900bf97c3f389378a96aee11260ea',
c15cd296 453 'timestamp': 1381846109,
1eac553e 454 'upload_date': '20131015',
ec85ded8 455 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/staff',
1eac553e
S
456 'uploader_id': 'staff',
457 'uploader': 'Vimeo Staff',
69c8fb9e 458 'duration': 62,
58ab5cbc 459 'subtitles': {
460 'de': [{'ext': 'vtt'}],
461 'en': [{'ext': 'vtt'}],
462 'es': [{'ext': 'vtt'}],
463 'fr': [{'ext': 'vtt'}],
464 },
9cb070f9 465 },
466 'expected_warnings': ['Ignoring subtitle tracks found in the HLS manifest'],
1eac553e 467 },
4698f0d8
JMF
468 {
469 # from https://www.ouya.tv/game/Pier-Solar-and-the-Great-Architects/
470 'url': 'https://player.vimeo.com/video/98044508',
471 'note': 'The js code contains assignments to the same variable as the config',
472 'info_dict': {
473 'id': '98044508',
474 'ext': 'mp4',
475 'title': 'Pier Solar OUYA Official Trailer',
476 'uploader': 'Tulio Gonçalves',
ec85ded8 477 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/user28849593',
4698f0d8 478 'uploader_id': 'user28849593',
b9c7b1e9 479 'duration': 118,
480 'thumbnail': 'https://i.vimeocdn.com/video/478636036-c18440305ef3df9decfb6bf207a61fe39d2d17fa462a96f6f2d93d30492b037d-d_1280',
4698f0d8
JMF
481 },
482 },
323f82a7 483 {
484 # contains original format
485 'url': 'https://vimeo.com/33951933',
365d136b 486 'md5': '53c688fa95a55bf4b7293d37a89c5c53',
323f82a7 487 'info_dict': {
488 'id': '33951933',
489 'ext': 'mp4',
490 'title': 'FOX CLASSICS - Forever Classic ID - A Full Minute',
491 'uploader': 'The DMCI',
ec85ded8 492 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/dmci',
323f82a7 493 'uploader_id': 'dmci',
c15cd296 494 'timestamp': 1324343742,
323f82a7 495 'upload_date': '20111220',
496 'description': 'md5:ae23671e82d05415868f7ad1aec21147',
b9c7b1e9 497 'duration': 60,
498 'comment_count': int,
499 'view_count': int,
500 'thumbnail': 'https://i.vimeocdn.com/video/231174622-dd07f015e9221ff529d451e1cc31c982b5d87bfafa48c4189b1da72824ee289a-d_1280',
501 'like_count': int,
323f82a7 502 },
503 },
605cad0b
A
504 {
505 'note': 'Contains original format not accessible in webpage',
506 'url': 'https://vimeo.com/393756517',
507 'md5': 'c464af248b592190a5ffbb5d33f382b0',
508 'info_dict': {
509 'id': '393756517',
510 'ext': 'mov',
511 'timestamp': 1582642091,
512 'uploader_id': 'frameworkla',
513 'title': 'Straight To Hell - Sabrina: Netflix',
514 'uploader': 'Framework Studio',
515 'description': 'md5:f2edc61af3ea7a5592681ddbb683db73',
516 'upload_date': '20200225',
b9c7b1e9 517 'duration': 176,
518 'thumbnail': 'https://i.vimeocdn.com/video/859377297-836494a4ef775e9d4edbace83937d9ad34dc846c688c0c419c0e87f7ab06c4b3-d_1280',
519 'uploader_url': 'https://vimeo.com/frameworkla',
605cad0b 520 },
605cad0b 521 },
c143ddce
S
522 {
523 # only available via https://vimeo.com/channels/tributes/6213729 and
524 # not via https://vimeo.com/6213729
525 'url': 'https://vimeo.com/channels/tributes/6213729',
526 'info_dict': {
527 'id': '6213729',
d03beddf 528 'ext': 'mp4',
c143ddce
S
529 'title': 'Vimeo Tribute: The Shining',
530 'uploader': 'Casey Donahue',
ec85ded8 531 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/caseydonahue',
c143ddce 532 'uploader_id': 'caseydonahue',
d03beddf
S
533 'channel_url': r're:https?://(?:www\.)?vimeo\.com/channels/tributes',
534 'channel_id': 'tributes',
c15cd296 535 'timestamp': 1250886430,
c143ddce
S
536 'upload_date': '20090821',
537 'description': 'md5:bdbf314014e58713e6e5b66eb252f4a6',
b9c7b1e9 538 'duration': 321,
539 'comment_count': int,
540 'view_count': int,
541 'thumbnail': 'https://i.vimeocdn.com/video/22728298-bfc22146f930de7cf497821c7b0b9f168099201ecca39b00b6bd31fcedfca7a6-d_1280',
542 'like_count': int,
c143ddce
S
543 },
544 'params': {
545 'skip_download': True,
546 },
c143ddce 547 },
f16f8505 548 {
cccd70a2 549 # redirects to ondemand extractor and should be passed through it
f16f8505
S
550 # for successful extraction
551 'url': 'https://vimeo.com/73445910',
552 'info_dict': {
553 'id': '73445910',
554 'ext': 'mp4',
555 'title': 'The Reluctant Revolutionary',
556 'uploader': '10Ft Films',
ec85ded8 557 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/tenfootfilms',
f16f8505 558 'uploader_id': 'tenfootfilms',
681ac7c9
RA
559 'description': 'md5:0fa704e05b04f91f40b7f3ca2e801384',
560 'upload_date': '20130830',
561 'timestamp': 1377853339,
f16f8505
S
562 },
563 'params': {
564 'skip_download': True,
565 },
cce889b9 566 'skip': 'this page is no longer available.',
f16f8505 567 },
79fec976
RA
568 {
569 'url': 'http://player.vimeo.com/video/68375962',
570 'md5': 'aaf896bdb7ddd6476df50007a0ac0ae7',
571 'info_dict': {
572 'id': '68375962',
573 'ext': 'mp4',
3867038a 574 'title': 'youtube-dl password protected test video',
b9c7b1e9 575 'timestamp': 1371200155,
576 'upload_date': '20130614',
79fec976
RA
577 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/user18948128',
578 'uploader_id': 'user18948128',
579 'uploader': 'Jaime Marquínez Ferrándiz',
580 'duration': 10,
b9c7b1e9 581 'description': 'md5:dca3ea23adb29ee387127bc4ddfce63f',
582 'thumbnail': 'https://i.vimeocdn.com/video/440665496-b2c5aee2b61089442c794f64113a8e8f7d5763c3e6b3ebfaf696ae6413f8b1f4-d_960',
583 'view_count': int,
584 'comment_count': int,
585 'like_count': int,
79fec976
RA
586 },
587 'params': {
681ac7c9 588 'format': 'best[protocol=https]',
3867038a 589 'videopassword': 'youtube-dl',
79fec976
RA
590 },
591 },
c143ddce
S
592 {
593 'url': 'http://vimeo.com/moogaloop.swf?clip_id=2539741',
594 'only_matching': True,
595 },
8bea039b
LL
596 {
597 'url': 'https://vimeo.com/109815029',
598 'note': 'Video not completely processed, "failed" seed status',
599 'only_matching': True,
600 },
6b7ceee1
S
601 {
602 'url': 'https://vimeo.com/groups/travelhd/videos/22439234',
603 'only_matching': True,
604 },
c8e3e097
S
605 {
606 'url': 'https://vimeo.com/album/2632481/video/79010983',
607 'only_matching': True,
608 },
1f52a09e 609 {
610 'url': 'https://vimeo.com/showcase/3253534/video/119195465',
611 'note': 'A video in a password protected album (showcase)',
612 'info_dict': {
613 'id': '119195465',
614 'ext': 'mp4',
b9c7b1e9 615 'title': "youtube-dl test video '' ä↭𝕐-BaW jenozKc",
1f52a09e 616 'uploader': 'Philipp Hagemeister',
617 'uploader_id': 'user20132939',
618 'description': 'md5:fa7b6c6d8db0bdc353893df2f111855b',
619 'upload_date': '20150209',
620 'timestamp': 1423518307,
b9c7b1e9 621 'thumbnail': 'https://i.vimeocdn.com/video/default_1280',
622 'duration': 10,
623 'like_count': int,
624 'uploader_url': 'https://vimeo.com/user20132939',
625 'view_count': int,
626 'comment_count': int,
1f52a09e 627 },
628 'params': {
629 'format': 'best[protocol=https]',
630 'videopassword': 'youtube-dl',
631 },
632 },
16f1131a
S
633 {
634 # source file returns 403: Forbidden
635 'url': 'https://vimeo.com/7809605',
636 'only_matching': True,
637 },
241a318f 638 {
2a6f8475 639 'note': 'Direct URL with hash',
241a318f 640 'url': 'https://vimeo.com/160743502/abd0e13fb4',
2a6f8475 641 'info_dict': {
642 'id': '160743502',
643 'ext': 'mp4',
644 'uploader': 'Julian Tryba',
645 'uploader_id': 'aliniamedia',
646 'title': 'Harrisville New Hampshire',
647 'timestamp': 1459259666,
648 'upload_date': '20160329',
b9c7b1e9 649 'release_timestamp': 1459259666,
650 'license': 'by-nc',
651 'duration': 159,
652 'comment_count': int,
653 'thumbnail': 'https://i.vimeocdn.com/video/562802436-585eeb13b5020c6ac0f171a2234067938098f84737787df05ff0d767f6d54ee9-d_1280',
654 'like_count': int,
655 'uploader_url': 'https://vimeo.com/aliniamedia',
656 'release_date': '20160329',
2a6f8475 657 },
9cb070f9 658 'params': {'skip_download': True},
659 },
660 {
661 'url': 'https://vimeo.com/138909882',
662 'info_dict': {
663 'id': '138909882',
664 'ext': 'mp4',
665 'title': 'Eastnor Castle 2015 Firework Champions - The Promo!',
666 'description': 'md5:5967e090768a831488f6e74b7821b3c1',
667 'uploader_id': 'fireworkchampions',
668 'uploader': 'Firework Champions',
669 'upload_date': '20150910',
670 'timestamp': 1441901895,
671 },
672 'params': {
673 'skip_download': True,
674 'format': 'Original',
675 },
bc2ca1bb 676 },
1ee34c76 677 {
678 'url': 'https://vimeo.com/channels/staffpicks/143603739',
679 'info_dict': {
680 'id': '143603739',
681 'ext': 'mp4',
682 'uploader': 'Karim Huu Do',
683 'timestamp': 1445846953,
684 'upload_date': '20151026',
685 'title': 'The Shoes - Submarine Feat. Blaine Harrison',
686 'uploader_id': 'karimhd',
687 'description': 'md5:8e2eea76de4504c2e8020a9bcfa1e843',
b9c7b1e9 688 'channel_id': 'staffpicks',
689 'duration': 336,
690 'comment_count': int,
691 'view_count': int,
692 'thumbnail': 'https://i.vimeocdn.com/video/541243181-b593db36a16db2f0096f655da3f5a4dc46b8766d77b0f440df937ecb0c418347-d_1280',
693 'like_count': int,
694 'uploader_url': 'https://vimeo.com/karimhd',
695 'channel_url': 'https://vimeo.com/channels/staffpicks',
1ee34c76 696 },
697 'params': {'skip_download': 'm3u8'},
698 },
bc2ca1bb 699 {
700 # requires passing unlisted_hash(a52724358e) to load_download_config request
701 'url': 'https://vimeo.com/392479337/a52724358e',
702 'only_matching': True,
9cb070f9 703 },
50e93e03 704 {
705 # similar, but all numeric: ID must be 581039021, not 9603038895
706 # issue #29690
707 'url': 'https://vimeo.com/581039021/9603038895',
708 'info_dict': {
709 'id': '581039021',
50e93e03 710 'ext': 'mp4',
711 'timestamp': 1627621014,
b9c7b1e9 712 'release_timestamp': 1627621014,
713 'duration': 976,
714 'comment_count': int,
715 'thumbnail': 'https://i.vimeocdn.com/video/1202249320-4ddb2c30398c0dc0ee059172d1bd5ea481ad12f0e0e3ad01d2266f56c744b015-d_1280',
716 'like_count': int,
717 'uploader_url': 'https://vimeo.com/txwestcapital',
718 'release_date': '20210730',
719 'uploader': 'Christopher Inks',
720 'title': 'Thursday, July 29, 2021 BMA Evening Video Update',
721 'uploader_id': 'txwestcapital',
722 'upload_date': '20210730',
50e93e03 723 },
724 'params': {
725 'skip_download': True,
726 },
727 }
a1a46075
S
728 # https://gettingthingsdone.com/workflowmap/
729 # vimeo embed with check-password page protected by Referer header
a91b954b 730 ]
b3d14cbf 731
b407e173 732 @staticmethod
09b9c45e
S
733 def _extract_urls(url, webpage):
734 urls = []
b407e173 735 # Look for embedded (iframe) Vimeo player
09b9c45e 736 for mobj in re.finditer(
7c1f4193 737 r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/\d+.*?)\1',
f475e881 738 webpage):
09b9c45e
S
739 urls.append(VimeoIE._smuggle_referrer(unescapeHTML(mobj.group('url')), url))
740 PLAIN_EMBED_RE = (
741 # Look for embedded (swf embed) Vimeo player
742 r'<embed[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?vimeo\.com/moogaloop\.swf.+?)\1',
743 # Look more for non-standard embedded Vimeo player
744 r'<video[^>]+src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?vimeo\.com/[0-9]+)\1',
745 )
746 for embed_re in PLAIN_EMBED_RE:
747 for mobj in re.finditer(embed_re, webpage):
748 urls.append(mobj.group('url'))
749 return urls
750
751 @staticmethod
752 def _extract_url(url, webpage):
753 urls = VimeoIE._extract_urls(url, webpage)
754 return urls[0] if urls else None
b407e173 755
a1a46075 756 def _verify_player_video_password(self, url, video_id, headers):
cce889b9 757 password = self._get_video_password()
79fec976
RA
758 data = urlencode_postdata({
759 'password': base64.b64encode(password.encode()),
760 })
a1a46075
S
761 headers = merge_dicts(headers, {
762 'Content-Type': 'application/x-www-form-urlencoded',
763 })
764 checked = self._download_json(
aedaa455 765 f'{compat_urlparse.urlsplit(url)._replace(query=None).geturl()}/check-password',
766 video_id, 'Verifying the password', data=data, headers=headers)
a1a46075
S
767 if checked is False:
768 raise ExtractorError('Wrong video password', expected=True)
769 return checked
0eecc6a4 770
58ab5cbc 771 def _extract_from_api(self, video_id, unlisted_hash=None):
772 token = self._download_json(
773 'https://vimeo.com/_rv/jwt', video_id, headers={
774 'X-Requested-With': 'XMLHttpRequest'
775 })['token']
776 api_url = 'https://api.vimeo.com/videos/' + video_id
777 if unlisted_hash:
778 api_url += ':' + unlisted_hash
779 video = self._download_json(
780 api_url, video_id, headers={
781 'Authorization': 'jwt ' + token,
782 }, query={
783 'fields': 'config_url,created_time,description,license,metadata.connections.comments.total,metadata.connections.likes.total,release_time,stats.plays',
784 })
785 info = self._parse_config(self._download_json(
786 video['config_url'], video_id), video_id)
787 self._vimeo_sort_formats(info['formats'])
788 get_timestamp = lambda x: parse_iso8601(video.get(x + '_time'))
789 info.update({
790 'description': video.get('description'),
791 'license': video.get('license'),
792 'release_timestamp': get_timestamp('release'),
793 'timestamp': get_timestamp('created'),
794 'view_count': int_or_none(try_get(video, lambda x: x['stats']['plays'])),
795 })
796 connections = try_get(
797 video, lambda x: x['metadata']['connections'], dict) or {}
798 for k in ('comment', 'like'):
799 info[k + '_count'] = int_or_none(try_get(connections, lambda x: x[k + 's']['total']))
800 return info
801
1f52a09e 802 def _try_album_password(self, url):
803 album_id = self._search_regex(
804 r'vimeo\.com/(?:album|showcase)/([^/]+)', url, 'album id', default=None)
805 if not album_id:
806 return
807 viewer = self._download_json(
808 'https://vimeo.com/_rv/viewer', album_id, fatal=False)
809 if not viewer:
810 webpage = self._download_webpage(url, album_id)
811 viewer = self._parse_json(self._search_regex(
812 r'bootstrap_data\s*=\s*({.+?})</script>',
813 webpage, 'bootstrap data'), album_id)['viewer']
814 jwt = viewer['jwt']
815 album = self._download_json(
816 'https://api.vimeo.com/albums/' + album_id,
817 album_id, headers={'Authorization': 'jwt ' + jwt},
818 query={'fields': 'description,name,privacy'})
819 if try_get(album, lambda x: x['privacy']['view']) == 'password':
a06916d9 820 password = self.get_param('videopassword')
1f52a09e 821 if not password:
822 raise ExtractorError(
823 'This album is protected by a password, use the --video-password option',
824 expected=True)
825 self._set_vimeo_cookie('vuid', viewer['vuid'])
826 try:
827 self._download_json(
828 'https://vimeo.com/showcase/%s/auth' % album_id,
829 album_id, 'Verifying the password', data=urlencode_postdata({
830 'password': password,
831 'token': viewer['xsrft'],
832 }), headers={
833 'X-Requested-With': 'XMLHttpRequest',
834 })
835 except ExtractorError as e:
836 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 401:
837 raise ExtractorError('Wrong password', expected=True)
838 raise
839
a0088bdf 840 def _real_extract(self, url):
aedaa455 841 url, data, headers = self._unsmuggle_headers(url)
ba5d51b3
PH
842 if 'Referer' not in headers:
843 headers['Referer'] = url
9d4660ca 844
b3d14cbf 845 # Extract ID from URL
2a6f8475 846 mobj = self._match_valid_url(url).groupdict()
847 video_id, unlisted_hash = mobj['id'], mobj.get('unlisted_hash')
cce889b9 848 if unlisted_hash:
58ab5cbc 849 return self._extract_from_api(video_id, unlisted_hash)
cce889b9 850
58ea7ec8 851 orig_url = url
681ac7c9 852 is_pro = 'vimeopro.com/' in url
681ac7c9 853 if is_pro:
06242d44 854 # some videos require portfolio_id to be present in player url
067aa17e 855 # https://github.com/ytdl-org/youtube-dl/issues/20070
06242d44 856 url = self._extract_url(url, self._download_webpage(url, video_id))
681ac7c9
RA
857 if not url:
858 url = 'https://vimeo.com/' + video_id
40b6495d 859 elif any(p in url for p in ('play_redirect_hls', 'moogaloop.swf')):
10831b5e 860 url = 'https://vimeo.com/' + video_id
b3d14cbf 861
1f52a09e 862 self._try_album_password(url)
1060425c 863 try:
681ac7c9
RA
864 # Retrieve video webpage to extract further information
865 webpage, urlh = self._download_webpage_handle(
866 url, video_id, headers=headers)
7947a1f7 867 redirect_url = urlh.geturl()
1060425c
PH
868 except ExtractorError as ee:
869 if isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 403:
870 errmsg = ee.cause.read()
871 if b'Because of its privacy settings, this video cannot be played here' in errmsg:
872 raise ExtractorError(
873 'Cannot download embed-only video without embedding '
7a5c1cfe 874 'URL. Please call yt-dlp with the URL of the page '
1060425c
PH
875 'that embeds this video.',
876 expected=True)
877 raise
b3d14cbf 878
58ab5cbc 879 if '://player.vimeo.com/video/' in url:
880 config = self._parse_json(self._search_regex(
881 r'\bconfig\s*=\s*({.+?})\s*;', webpage, 'info section'), video_id)
882 if config.get('view') == 4:
883 config = self._verify_player_video_password(
884 redirect_url, video_id, headers)
885 info = self._parse_config(config, video_id)
886 self._vimeo_sort_formats(info['formats'])
887 return info
888
889 if re.search(r'<form[^>]+?id="pw_form"', webpage):
890 video_password = self._get_video_password()
891 token, vuid = self._extract_xsrft_and_vuid(webpage)
892 webpage = self._verify_video_password(
893 redirect_url, video_id, video_password, token, vuid)
b3d14cbf 894
eb9c9c74 895 vimeo_config = self._extract_vimeo_config(webpage, video_id, default=None)
998e6cdb 896 if vimeo_config:
58ab5cbc 897 seed_status = vimeo_config.get('seed_status') or {}
998e6cdb
S
898 if seed_status.get('state') == 'failed':
899 raise ExtractorError(
b6aa99af 900 '%s said: %s' % (self.IE_NAME, seed_status['title']),
998e6cdb
S
901 expected=True)
902
c38a67bc 903 cc_license = None
c15cd296 904 timestamp = None
681ac7c9 905 video_description = None
58ab5cbc 906 info_dict = {}
1ee34c76 907 config_url = None
c38a67bc 908
58ab5cbc 909 channel_id = self._search_regex(
910 r'vimeo\.com/channels/([^/]+)', url, 'channel id', default=None)
911 if channel_id:
912 config_url = self._html_search_regex(
1ee34c76 913 r'\bdata-config-url="([^"]+)"', webpage, 'config URL', default=None)
58ab5cbc 914 video_description = clean_html(get_element_by_class('description', webpage))
915 info_dict.update({
916 'channel_id': channel_id,
917 'channel_url': 'https://vimeo.com/channels/' + channel_id,
918 })
1ee34c76 919 if not config_url:
58ab5cbc 920 page_config = self._parse_json(self._search_regex(
921 r'vimeo\.(?:clip|vod_title)_page_config\s*=\s*({.+?});',
922 webpage, 'page config', default='{}'), video_id, fatal=False)
923 if not page_config:
924 return self._extract_from_api(video_id)
925 config_url = page_config['player']['config_url']
926 cc_license = page_config.get('cc_license')
927 clip = page_config.get('clip') or {}
928 timestamp = clip.get('uploaded_on')
929 video_description = clean_html(
930 clip.get('description') or page_config.get('description_html_escaped'))
931 config = self._download_json(config_url, video_id)
bc2ca1bb 932 video = config.get('video') or {}
933 vod = video.get('vod') or {}
8b40c927 934
6a55bb66
S
935 def is_rented():
936 if '>You rented this title.<' in webpage:
937 return True
58ab5cbc 938 if try_get(config, lambda x: x['user']['purchased']):
6a55bb66 939 return True
58ab5cbc 940 for purchase_option in (vod.get('purchase_options') or []):
8b40c927
RA
941 if purchase_option.get('purchased'):
942 return True
943 label = purchase_option.get('label_string')
944 if label and (label.startswith('You rented this') or label.endswith(' remaining')):
945 return True
6a55bb66
S
946 return False
947
8b40c927
RA
948 if is_rented() and vod.get('is_trailer'):
949 feature_id = vod.get('feature_id')
5dbe81a1
S
950 if feature_id and not data.get('force_feature_id', False):
951 return self.url_result(smuggle_url(
952 'https://player.vimeo.com/player/%s' % feature_id,
953 {'force_feature_id': True}), 'Vimeo')
954
681ac7c9
RA
955 if not video_description:
956 video_description = self._html_search_regex(
957 r'(?s)<div\s+class="[^"]*description[^"]*"[^>]*>(.*?)</div>',
958 webpage, 'description', default=None)
58ea7ec8
PH
959 if not video_description:
960 video_description = self._html_search_meta(
58ab5cbc 961 ['description', 'og:description', 'twitter:description'],
962 webpage, default=None)
681ac7c9 963 if not video_description and is_pro:
58ea7ec8
PH
964 orig_webpage = self._download_webpage(
965 orig_url, video_id,
966 note='Downloading webpage for description',
967 fatal=False)
968 if orig_webpage:
969 video_description = self._html_search_meta(
970 'description', orig_webpage, default=None)
58ab5cbc 971 if not video_description:
6a39ee13 972 self.report_warning('Cannot find video description')
b3d14cbf 973
c15cd296
S
974 if not timestamp:
975 timestamp = self._search_regex(
976 r'<time[^>]+datetime="([^"]+)"', webpage,
977 'timestamp', default=None)
b3d14cbf 978
58ab5cbc 979 view_count = int_or_none(self._search_regex(r'UserPlays:(\d+)', webpage, 'view count', default=None))
980 like_count = int_or_none(self._search_regex(r'UserLikes:(\d+)', webpage, 'like count', default=None))
981 comment_count = int_or_none(self._search_regex(r'UserComments:(\d+)', webpage, 'comment count', default=None))
4e761794 982
a6387bfd 983 formats = []
27655037
RA
984
985 source_format = self._extract_original_format(
bc2ca1bb 986 'https://vimeo.com/' + video_id, video_id, video.get('unlisted_hash'))
27655037
RA
987 if source_format:
988 formats.append(source_format)
1eac553e 989
ae1c585c
S
990 info_dict_config = self._parse_config(config, video_id)
991 formats.extend(info_dict_config['formats'])
531a7496 992 self._vimeo_sort_formats(formats)
c38a67bc 993
ae1c585c
S
994 json_ld = self._search_json_ld(webpage, video_id, default={})
995
c38a67bc
S
996 if not cc_license:
997 cc_license = self._search_regex(
998 r'<link[^>]+rel=["\']license["\'][^>]+href=(["\'])(?P<license>(?:(?!\1).)+)\1',
999 webpage, 'license', default=None, group='license')
1000
58ab5cbc 1001 info_dict.update({
531a7496 1002 'formats': formats,
c15cd296 1003 'timestamp': unified_timestamp(timestamp),
b0268cb6 1004 'description': video_description,
9103bbc5 1005 'webpage_url': url,
4e761794
JMF
1006 'view_count': view_count,
1007 'like_count': like_count,
1008 'comment_count': comment_count,
c38a67bc 1009 'license': cc_license,
58ab5cbc 1010 })
531a7496 1011
58ab5cbc 1012 return merge_dicts(info_dict, info_dict_config, json_ld)
caeefc29
JMF
1013
1014
681ac7c9 1015class VimeoOndemandIE(VimeoIE):
1e501364 1016 IE_NAME = 'vimeo:ondemand'
58ab5cbc 1017 _VALID_URL = r'https?://(?:www\.)?vimeo\.com/ondemand/(?:[^/]+/)?(?P<id>[^/?#&]+)'
74278def
S
1018 _TESTS = [{
1019 # ondemand video not available via https://vimeo.com/id
1020 'url': 'https://vimeo.com/ondemand/20704',
1021 'md5': 'c424deda8c7f73c1dfb3edd7630e2f35',
1022 'info_dict': {
1023 'id': '105442900',
1024 'ext': 'mp4',
1025 'title': 'המעבדה - במאי יותם פלדמן',
1026 'uploader': 'גם סרטים',
ec85ded8 1027 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/gumfilms',
74278def 1028 'uploader_id': 'gumfilms',
b9c7b1e9 1029 'description': 'md5:aeeba3dbd4d04b0fa98a4fdc9c639998',
681ac7c9
RA
1030 'upload_date': '20140906',
1031 'timestamp': 1410032453,
b9c7b1e9 1032 'thumbnail': 'https://i.vimeocdn.com/video/488238335-d7bf151c364cff8d467f1b73784668fe60aae28a54573a35d53a1210ae283bd8-d_1280',
1033 'comment_count': int,
1034 'license': 'https://creativecommons.org/licenses/by-nc-nd/3.0/',
1035 'duration': 53,
1036 'view_count': int,
1037 'like_count': int,
74278def 1038 },
1fd0fc42
S
1039 'params': {
1040 'format': 'best[protocol=https]',
1041 },
681ac7c9 1042 'expected_warnings': ['Unable to download JSON metadata'],
d002e919
S
1043 }, {
1044 # requires Referer to be passed along with og:video:url
1045 'url': 'https://vimeo.com/ondemand/36938/126682985',
1046 'info_dict': {
681ac7c9 1047 'id': '126584684',
d002e919
S
1048 'ext': 'mp4',
1049 'title': 'Rävlock, rätt läte på rätt plats',
1050 'uploader': 'Lindroth & Norin',
681ac7c9
RA
1051 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/lindrothnorin',
1052 'uploader_id': 'lindrothnorin',
1053 'description': 'md5:c3c46a90529612c8279fb6af803fc0df',
1054 'upload_date': '20150502',
1055 'timestamp': 1430586422,
b9c7b1e9 1056 'duration': 121,
1057 'comment_count': int,
1058 'view_count': int,
1059 'thumbnail': 'https://i.vimeocdn.com/video/517077723-7066ae1d9a79d3eb361334fb5d58ec13c8f04b52f8dd5eadfbd6fb0bcf11f613-d_1280',
1060 'like_count': int,
d002e919
S
1061 },
1062 'params': {
1063 'skip_download': True,
1064 },
681ac7c9 1065 'expected_warnings': ['Unable to download JSON metadata'],
74278def
S
1066 }, {
1067 'url': 'https://vimeo.com/ondemand/nazmaalik',
1068 'only_matching': True,
1069 }, {
1070 'url': 'https://vimeo.com/ondemand/141692381',
1071 'only_matching': True,
1072 }, {
1073 'url': 'https://vimeo.com/ondemand/thelastcolony/150274832',
1074 'only_matching': True,
1075 }]
1076
74278def 1077
f6c3664d 1078class VimeoChannelIE(VimeoBaseInfoExtractor):
9148eb00 1079 IE_NAME = 'vimeo:channel'
3946864c 1080 _VALID_URL = r'https://vimeo\.com/channels/(?P<id>[^/?#]+)/?(?:$|[?#])'
caeefc29 1081 _MORE_PAGES_INDICATOR = r'<a.+?rel="next"'
84458766 1082 _TITLE = None
55a10eab 1083 _TITLE_RE = r'<link rel="alternate"[^>]+?title="(.*?)"'
2929b3e7 1084 _TESTS = [{
3946864c 1085 'url': 'https://vimeo.com/channels/tributes',
2929b3e7 1086 'info_dict': {
a3fa5da4 1087 'id': 'tributes',
2929b3e7
PH
1088 'title': 'Vimeo Tributes',
1089 },
b9c7b1e9 1090 'playlist_mincount': 22,
2929b3e7 1091 }]
681ac7c9 1092 _BASE_URL_TEMPL = 'https://vimeo.com/channels/%s'
caeefc29 1093
5cc14c2f
JMF
1094 def _page_url(self, base_url, pagenum):
1095 return '%s/videos/page:%d/' % (base_url, pagenum)
1096
fb30ec22 1097 def _extract_list_title(self, webpage):
2605043d
S
1098 return self._TITLE or self._html_search_regex(
1099 self._TITLE_RE, webpage, 'list title', fatal=False)
fb30ec22 1100
2c94198e 1101 def _title_and_entries(self, list_id, base_url):
caeefc29 1102 for pagenum in itertools.count(1):
bf8f082a 1103 page_url = self._page_url(base_url, pagenum)
55a10eab 1104 webpage = self._download_webpage(
bf8f082a 1105 page_url, list_id,
9148eb00 1106 'Downloading page %s' % pagenum)
bf8f082a
PH
1107
1108 if pagenum == 1:
2c94198e
S
1109 yield self._extract_list_title(webpage)
1110
c8e3e097
S
1111 # Try extracting href first since not all videos are available via
1112 # short https://vimeo.com/id URL (e.g. https://vimeo.com/channels/tributes/6213729)
1113 clips = re.findall(
04a3d4d2 1114 r'id="clip_(\d+)"[^>]*>\s*<a[^>]+href="(/(?:[^/]+/)*\1)(?:[^>]+\btitle="([^"]+)")?', webpage)
c8e3e097 1115 if clips:
04a3d4d2 1116 for video_id, video_url, video_title in clips:
c8e3e097
S
1117 yield self.url_result(
1118 compat_urlparse.urljoin(base_url, video_url),
04a3d4d2 1119 VimeoIE.ie_key(), video_id=video_id, video_title=video_title)
c8e3e097
S
1120 # More relaxed fallback
1121 else:
1122 for video_id in re.findall(r'id=["\']clip_(\d+)', webpage):
1123 yield self.url_result(
1124 'https://vimeo.com/%s' % video_id,
1125 VimeoIE.ie_key(), video_id=video_id)
bf8f082a 1126
caeefc29
JMF
1127 if re.search(self._MORE_PAGES_INDICATOR, webpage, re.DOTALL) is None:
1128 break
1129
2c94198e
S
1130 def _extract_videos(self, list_id, base_url):
1131 title_and_entries = self._title_and_entries(list_id, base_url)
1132 list_title = next(title_and_entries)
1133 return self.playlist_result(title_and_entries, list_id, list_title)
55a10eab
JMF
1134
1135 def _real_extract(self, url):
681ac7c9
RA
1136 channel_id = self._match_id(url)
1137 return self._extract_videos(channel_id, self._BASE_URL_TEMPL % channel_id)
55a10eab
JMF
1138
1139
1140class VimeoUserIE(VimeoChannelIE):
9148eb00 1141 IE_NAME = 'vimeo:user'
681ac7c9 1142 _VALID_URL = r'https://vimeo\.com/(?!(?:[0-9]+|watchlater)(?:$|[?#/]))(?P<id>[^/]+)(?:/videos|[#?]|$)'
55a10eab 1143 _TITLE_RE = r'<a[^>]+?class="user">([^<>]+?)</a>'
2929b3e7 1144 _TESTS = [{
3946864c 1145 'url': 'https://vimeo.com/nkistudio/videos',
2929b3e7
PH
1146 'info_dict': {
1147 'title': 'Nki',
a3fa5da4 1148 'id': 'nkistudio',
2929b3e7
PH
1149 },
1150 'playlist_mincount': 66,
1151 }]
681ac7c9 1152 _BASE_URL_TEMPL = 'https://vimeo.com/%s'
5cc14c2f
JMF
1153
1154
51c7f40c 1155class VimeoAlbumIE(VimeoBaseInfoExtractor):
9148eb00 1156 IE_NAME = 'vimeo:album'
eb9c9c74 1157 _VALID_URL = r'https://vimeo\.com/(?:album|showcase)/(?P<id>\d+)(?:$|[?#]|/(?!video))'
5cc14c2f 1158 _TITLE_RE = r'<header id="page_header">\n\s*<h1>(.*?)</h1>'
2929b3e7 1159 _TESTS = [{
d1508cd6 1160 'url': 'https://vimeo.com/album/2632481',
2929b3e7 1161 'info_dict': {
a3fa5da4 1162 'id': '2632481',
2929b3e7
PH
1163 'title': 'Staff Favorites: November 2013',
1164 },
1165 'playlist_mincount': 13,
bf8f082a
PH
1166 }, {
1167 'note': 'Password-protected album',
1168 'url': 'https://vimeo.com/album/3253534',
1169 'info_dict': {
1170 'title': 'test',
1171 'id': '3253534',
1172 },
1173 'playlist_count': 1,
1174 'params': {
3867038a 1175 'videopassword': 'youtube-dl',
bf8f082a 1176 }
2929b3e7 1177 }]
eb9c9c74
RA
1178 _PAGE_SIZE = 100
1179
a0566bbf 1180 def _fetch_page(self, album_id, authorization, hashed_pass, page):
eb9c9c74
RA
1181 api_page = page + 1
1182 query = {
974311b5 1183 'fields': 'link,uri',
eb9c9c74
RA
1184 'page': api_page,
1185 'per_page': self._PAGE_SIZE,
1186 }
1187 if hashed_pass:
1188 query['_hashed_pass'] = hashed_pass
421a4595 1189 try:
1190 videos = self._download_json(
1191 'https://api.vimeo.com/albums/%s/videos' % album_id,
1192 album_id, 'Downloading page %d' % api_page, query=query, headers={
1193 'Authorization': 'jwt ' + authorization,
1194 })['data']
1195 except ExtractorError as e:
1196 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 400:
1197 return
eb9c9c74
RA
1198 for video in videos:
1199 link = video.get('link')
1200 if not link:
1201 continue
974311b5
RA
1202 uri = video.get('uri')
1203 video_id = self._search_regex(r'/videos/(\d+)', uri, 'video_id', default=None) if uri else None
1204 yield self.url_result(link, VimeoIE.ie_key(), video_id)
5cc14c2f
JMF
1205
1206 def _real_extract(self, url):
bf8f082a 1207 album_id = self._match_id(url)
8bdd16b4 1208 viewer = self._download_json(
1209 'https://vimeo.com/_rv/viewer', album_id, fatal=False)
1210 if not viewer:
1211 webpage = self._download_webpage(url, album_id)
1212 viewer = self._parse_json(self._search_regex(
1213 r'bootstrap_data\s*=\s*({.+?})</script>',
1214 webpage, 'bootstrap data'), album_id)['viewer']
51c7f40c
RA
1215 jwt = viewer['jwt']
1216 album = self._download_json(
1217 'https://api.vimeo.com/albums/' + album_id,
1218 album_id, headers={'Authorization': 'jwt ' + jwt},
1219 query={'fields': 'description,name,privacy'})
1220 hashed_pass = None
1221 if try_get(album, lambda x: x['privacy']['view']) == 'password':
a06916d9 1222 password = self.get_param('videopassword')
51c7f40c
RA
1223 if not password:
1224 raise ExtractorError(
1225 'This album is protected by a password, use the --video-password option',
1226 expected=True)
1227 self._set_vimeo_cookie('vuid', viewer['vuid'])
1228 try:
1229 hashed_pass = self._download_json(
1230 'https://vimeo.com/showcase/%s/auth' % album_id,
1231 album_id, 'Verifying the password', data=urlencode_postdata({
1232 'password': password,
1233 'token': viewer['xsrft'],
1234 }), headers={
1235 'X-Requested-With': 'XMLHttpRequest',
1236 })['hashed_pass']
1237 except ExtractorError as e:
1238 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 401:
1239 raise ExtractorError('Wrong password', expected=True)
1240 raise
eb9c9c74 1241 entries = OnDemandPagedList(functools.partial(
51c7f40c
RA
1242 self._fetch_page, album_id, jwt, hashed_pass), self._PAGE_SIZE)
1243 return self.playlist_result(
1244 entries, album_id, album.get('name'), album.get('description'))
fb30ec22
JMF
1245
1246
681ac7c9 1247class VimeoGroupsIE(VimeoChannelIE):
9148eb00 1248 IE_NAME = 'vimeo:group'
681ac7c9 1249 _VALID_URL = r'https://vimeo\.com/groups/(?P<id>[^/]+)(?:/(?!videos?/\d+)|$)'
2929b3e7 1250 _TESTS = [{
9cb070f9 1251 'url': 'https://vimeo.com/groups/meetup',
2929b3e7 1252 'info_dict': {
9cb070f9 1253 'id': 'meetup',
1254 'title': 'Vimeo Meetup!',
2929b3e7 1255 },
681ac7c9 1256 'playlist_mincount': 27,
2929b3e7 1257 }]
681ac7c9 1258 _BASE_URL_TEMPL = 'https://vimeo.com/groups/%s'
fcea44c6
PH
1259
1260
531a7496 1261class VimeoReviewIE(VimeoBaseInfoExtractor):
9148eb00
PH
1262 IE_NAME = 'vimeo:review'
1263 IE_DESC = 'Review pages on vimeo'
27655037 1264 _VALID_URL = r'(?P<url>https://vimeo\.com/[^/]+/review/(?P<id>[^/]+)/[0-9a-f]{10})'
d36d3f42 1265 _TESTS = [{
fcea44c6 1266 'url': 'https://vimeo.com/user21297594/review/75524534/3c257a1b5d',
fcea44c6
PH
1267 'md5': 'c507a72f780cacc12b2248bb4006d253',
1268 'info_dict': {
fc09240e
PH
1269 'id': '75524534',
1270 'ext': 'mp4',
fcea44c6
PH
1271 'title': "DICK HARDWICK 'Comedian'",
1272 'uploader': 'Richard Hardwick',
531a7496 1273 'uploader_id': 'user21297594',
681ac7c9 1274 'description': "Comedian Dick Hardwick's five minute demo filmed in front of a live theater audience.\nEdit by Doug Mattocks",
b9c7b1e9 1275 'duration': 304,
1276 'thumbnail': 'https://i.vimeocdn.com/video/450115033-43303819d9ebe24c2630352e18b7056d25197d09b3ae901abdac4c4f1d68de71-d_1280',
1277 'uploader_url': 'https://vimeo.com/user21297594',
681ac7c9 1278 },
d36d3f42
PH
1279 }, {
1280 'note': 'video player needs Referer',
3946864c 1281 'url': 'https://vimeo.com/user22258446/review/91613211/13f927e053',
d36d3f42
PH
1282 'md5': '6295fdab8f4bf6a002d058b2c6dce276',
1283 'info_dict': {
1284 'id': '91613211',
1285 'ext': 'mp4',
9dec9930 1286 'title': 're:(?i)^Death by dogma versus assembling agile . Sander Hoogendoorn',
d36d3f42
PH
1287 'uploader': 'DevWeek Events',
1288 'duration': 2773,
ec85ded8 1289 'thumbnail': r're:^https?://.*\.jpg$',
531a7496 1290 'uploader_id': 'user22258446',
681ac7c9
RA
1291 },
1292 'skip': 'video gone',
c1ff6e1a
YCH
1293 }, {
1294 'note': 'Password protected',
1295 'url': 'https://vimeo.com/user37284429/review/138823582/c4d865efde',
1296 'info_dict': {
1297 'id': '138823582',
1298 'ext': 'mp4',
1299 'title': 'EFFICIENT PICKUP MASTERCLASS MODULE 1',
1300 'uploader': 'TMB',
1301 'uploader_id': 'user37284429',
1302 },
1303 'params': {
1304 'videopassword': 'holygrail',
1305 },
a093cfc7 1306 'skip': 'video gone',
d36d3f42 1307 }]
fcea44c6
PH
1308
1309 def _real_extract(self, url):
5ad28e7f 1310 page_url, video_id = self._match_valid_url(url).groups()
cce889b9 1311 data = self._download_json(
1312 page_url.replace('/review/', '/review/data/'), video_id)
1313 if data.get('isLocked') is True:
1314 video_password = self._get_video_password()
1315 viewer = self._download_json(
1316 'https://vimeo.com/_rv/viewer', video_id)
1317 webpage = self._verify_video_password(
1318 'https://vimeo.com/' + video_id, video_id,
1319 video_password, viewer['xsrft'], viewer['vuid'])
1320 clip_page_config = self._parse_json(self._search_regex(
1321 r'window\.vimeo\.clip_page_config\s*=\s*({.+?});',
1322 webpage, 'clip page config'), video_id)
1323 config_url = clip_page_config['player']['config_url']
1324 clip_data = clip_page_config.get('clip') or {}
1325 else:
1326 clip_data = data['clipData']
1327 config_url = clip_data['configUrl']
c1ff6e1a 1328 config = self._download_json(config_url, video_id)
531a7496 1329 info_dict = self._parse_config(config, video_id)
681ac7c9
RA
1330 source_format = self._extract_original_format(
1331 page_url + '/action', video_id)
27655037
RA
1332 if source_format:
1333 info_dict['formats'].append(source_format)
531a7496 1334 self._vimeo_sort_formats(info_dict['formats'])
681ac7c9 1335 info_dict['description'] = clean_html(clip_data.get('description'))
531a7496 1336 return info_dict
efb7e119
JMF
1337
1338
f6c3664d 1339class VimeoWatchLaterIE(VimeoChannelIE):
efb7e119 1340 IE_NAME = 'vimeo:watchlater'
8dcce6a8 1341 IE_DESC = 'Vimeo watch later list, ":vimeowatchlater" keyword (requires authentication)'
84458766
S
1342 _VALID_URL = r'https://vimeo\.com/(?:home/)?watchlater|:vimeowatchlater'
1343 _TITLE = 'Watch Later'
efb7e119 1344 _LOGIN_REQUIRED = True
2929b3e7 1345 _TESTS = [{
84458766 1346 'url': 'https://vimeo.com/watchlater',
2929b3e7
PH
1347 'only_matching': True,
1348 }]
efb7e119 1349
efb7e119
JMF
1350 def _page_url(self, base_url, pagenum):
1351 url = '%s/page:%d/' % (base_url, pagenum)
67dda517 1352 request = sanitized_Request(url)
efb7e119
JMF
1353 # Set the header to get a partial html page with the ids,
1354 # the normal page doesn't contain them.
1355 request.add_header('X-Requested-With', 'XMLHttpRequest')
1356 return request
1357
1358 def _real_extract(self, url):
84458766 1359 return self._extract_videos('watchlater', 'https://vimeo.com/watchlater')
d6e6a422
PH
1360
1361
091c9b43 1362class VimeoLikesIE(VimeoChannelIE):
361a965b 1363 _VALID_URL = r'https://(?:www\.)?vimeo\.com/(?P<id>[^/]+)/likes/?(?:$|[?#]|sort:)'
d6e6a422
PH
1364 IE_NAME = 'vimeo:likes'
1365 IE_DESC = 'Vimeo user likes'
361a965b 1366 _TESTS = [{
9c44d242
PH
1367 'url': 'https://vimeo.com/user755559/likes/',
1368 'playlist_mincount': 293,
611c1dd9 1369 'info_dict': {
091c9b43
S
1370 'id': 'user755559',
1371 'title': 'urza’s Likes',
d6e6a422 1372 },
361a965b
S
1373 }, {
1374 'url': 'https://vimeo.com/stormlapse/likes',
1375 'only_matching': True,
1376 }]
d6e6a422 1377
091c9b43
S
1378 def _page_url(self, base_url, pagenum):
1379 return '%s/page:%d/' % (base_url, pagenum)
1380
d6e6a422
PH
1381 def _real_extract(self, url):
1382 user_id = self._match_id(url)
091c9b43 1383 return self._extract_videos(user_id, 'https://vimeo.com/%s/likes' % user_id)
ca01d178
RA
1384
1385
a1ee23e9 1386class VHXEmbedIE(VimeoBaseInfoExtractor):
ca01d178
RA
1387 IE_NAME = 'vhx:embed'
1388 _VALID_URL = r'https?://embed\.vhx\.tv/videos/(?P<id>\d+)'
1389
29f7c58a 1390 @staticmethod
aedaa455 1391 def _extract_url(url, webpage):
29f7c58a 1392 mobj = re.search(
1393 r'<iframe[^>]+src="(https?://embed\.vhx\.tv/videos/\d+[^"]*)"', webpage)
aedaa455 1394 return VimeoIE._smuggle_referrer(unescapeHTML(mobj.group(1)), url) if mobj else None
29f7c58a 1395
ca01d178
RA
1396 def _real_extract(self, url):
1397 video_id = self._match_id(url)
aedaa455 1398 url, _, headers = self._unsmuggle_headers(url)
1399 webpage = self._download_webpage(url, video_id, headers=headers)
a1ee23e9
RA
1400 config_url = self._parse_json(self._search_regex(
1401 r'window\.OTTData\s*=\s*({.+})', webpage,
1402 'ott data'), video_id, js_to_json)['config_url']
1403 config = self._download_json(config_url, video_id)
1404 info = self._parse_config(config, video_id)
29f7c58a 1405 info['id'] = video_id
a1ee23e9
RA
1406 self._vimeo_sort_formats(info['formats'])
1407 return info