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