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