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