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