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