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