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