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