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