]>
Commit | Line | Data |
---|---|---|
93b22c78 | 1 | # encoding: utf-8 |
9148eb00 PH |
2 | from __future__ import unicode_literals |
3 | ||
b3d14cbf PH |
4 | import json |
5 | import re | |
caeefc29 | 6 | import itertools |
b3d14cbf PH |
7 | |
8 | from .common import InfoExtractor | |
8c25f81b | 9 | from ..compat import ( |
1060425c | 10 | compat_HTTPError, |
9c44d242 | 11 | compat_urlparse, |
8c25f81b PH |
12 | ) |
13 | from ..utils import ( | |
d5f071af | 14 | determine_ext, |
852fad92 | 15 | encode_dict, |
b3d14cbf | 16 | ExtractorError, |
9c44d242 PH |
17 | InAdvancePagedList, |
18 | int_or_none, | |
55b3e45b | 19 | RegexNotFoundError, |
67dda517 | 20 | sanitized_Request, |
30965ac6 | 21 | smuggle_url, |
b3d14cbf | 22 | std_headers, |
3c6f2450 | 23 | unified_strdate, |
9d4660ca | 24 | unsmuggle_url, |
a980bc43 | 25 | urlencode_postdata, |
b407e173 | 26 | unescapeHTML, |
eb4f2740 | 27 | parse_filesize, |
b3d14cbf PH |
28 | ) |
29 | ||
bbafbe20 | 30 | |
efb7e119 JMF |
31 | class VimeoBaseInfoExtractor(InfoExtractor): |
32 | _NETRC_MACHINE = 'vimeo' | |
33 | _LOGIN_REQUIRED = False | |
f6c3664d | 34 | _LOGIN_URL = 'https://vimeo.com/log_in' |
efb7e119 JMF |
35 | |
36 | def _login(self): | |
37 | (username, password) = self._get_login_info() | |
38 | if username is None: | |
39 | if self._LOGIN_REQUIRED: | |
4f3e9430 | 40 | raise ExtractorError('No login info available, needed for using %s.' % self.IE_NAME, expected=True) |
efb7e119 JMF |
41 | return |
42 | self.report_login() | |
f6c3664d | 43 | webpage = self._download_webpage(self._LOGIN_URL, None, False) |
7c845629 | 44 | token, vuid = self._extract_xsrft_and_vuid(webpage) |
3fa3ff1b | 45 | data = urlencode_postdata(encode_dict({ |
f6c3664d | 46 | 'action': 'login', |
efb7e119 JMF |
47 | 'email': username, |
48 | 'password': password, | |
efb7e119 JMF |
49 | 'service': 'vimeo', |
50 | 'token': token, | |
3fa3ff1b | 51 | })) |
67dda517 | 52 | login_request = sanitized_Request(self._LOGIN_URL, data) |
efb7e119 | 53 | login_request.add_header('Content-Type', 'application/x-www-form-urlencoded') |
f6c3664d | 54 | login_request.add_header('Referer', self._LOGIN_URL) |
9eab37dc | 55 | self._set_vimeo_cookie('vuid', vuid) |
efb7e119 JMF |
56 | self._download_webpage(login_request, None, False, 'Wrong login info') |
57 | ||
7c845629 S |
58 | def _extract_xsrft_and_vuid(self, webpage): |
59 | xsrft = self._search_regex( | |
b826035d | 60 | r'(?:(?P<q1>["\'])xsrft(?P=q1)\s*:|xsrft\s*[=:])\s*(?P<q>["\'])(?P<xsrft>.+?)(?P=q)', |
f6c3664d | 61 | webpage, 'login token', group='xsrft') |
7c845629 S |
62 | vuid = self._search_regex( |
63 | r'["\']vuid["\']\s*:\s*(["\'])(?P<vuid>.+?)\1', | |
64 | webpage, 'vuid', group='vuid') | |
65 | return xsrft, vuid | |
f6c3664d | 66 | |
9eab37dc S |
67 | def _set_vimeo_cookie(self, name, value): |
68 | self._set_cookie('vimeo.com', name, value) | |
69 | ||
efb7e119 | 70 | |
65469a7f | 71 | class VimeoIE(VimeoBaseInfoExtractor): |
b3d14cbf PH |
72 | """Information extractor for vimeo.com.""" |
73 | ||
74 | # _VALID_URL matches Vimeo URLs | |
bbafbe20 | 75 | _VALID_URL = r'''(?x) |
74278def S |
76 | https?:// |
77 | (?: | |
78 | (?: | |
79 | www| | |
80 | (?P<player>player) | |
81 | ) | |
82 | \. | |
83 | )? | |
84 | vimeo(?P<pro>pro)?\.com/ | |
85 | (?!channels/[^/?#]+/?(?:$|[?#])|(?:album|ondemand)/) | |
86 | (?:.*?/)? | |
87 | (?: | |
88 | (?: | |
89 | play_redirect_hls| | |
90 | moogaloop\.swf)\?clip_id= | |
91 | )? | |
92 | (?:videos?/)? | |
93 | (?P<id>[0-9]+) | |
94 | /?(?:[?&].*)?(?:[#].*)?$ | |
95 | ''' | |
9148eb00 | 96 | IE_NAME = 'vimeo' |
a91b954b JMF |
97 | _TESTS = [ |
98 | { | |
9148eb00 | 99 | 'url': 'http://vimeo.com/56015672#at=0', |
9148eb00 PH |
100 | 'md5': '8879b6cc097e987f02484baf890129e5', |
101 | 'info_dict': { | |
ad5976b4 PH |
102 | 'id': '56015672', |
103 | 'ext': 'mp4', | |
68f3b61f S |
104 | 'title': "youtube-dl test video - \u2605 \" ' \u5e78 / \\ \u00e4 \u21ad \U0001d550", |
105 | 'description': 'md5:2d3305bad981a06ff79f027f19865021', | |
106 | 'upload_date': '20121220', | |
a2d7797c | 107 | 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/user7108434', |
68f3b61f S |
108 | 'uploader_id': 'user7108434', |
109 | 'uploader': 'Filippo Valsorda', | |
110 | 'duration': 10, | |
a91b954b JMF |
111 | }, |
112 | }, | |
113 | { | |
9148eb00 | 114 | 'url': 'http://vimeopro.com/openstreetmapus/state-of-the-map-us-2013/video/68093876', |
9148eb00 PH |
115 | 'md5': '3b5ca6aa22b60dfeeadf50b72e44ed82', |
116 | 'note': 'Vimeo Pro video (#1197)', | |
117 | 'info_dict': { | |
4f3e9430 JMF |
118 | 'id': '68093876', |
119 | 'ext': 'mp4', | |
a2d7797c | 120 | 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/openstreetmapus', |
9148eb00 PH |
121 | 'uploader_id': 'openstreetmapus', |
122 | 'uploader': 'OpenStreetMap US', | |
123 | 'title': 'Andy Allan - Putting the Carto into OpenStreetMap Cartography', | |
68f3b61f | 124 | 'description': 'md5:fd69a7b8d8c34a4e1d2ec2e4afd6ec30', |
69c8fb9e | 125 | 'duration': 1595, |
a91b954b JMF |
126 | }, |
127 | }, | |
aa32314d | 128 | { |
9148eb00 | 129 | 'url': 'http://player.vimeo.com/video/54469442', |
9148eb00 PH |
130 | 'md5': '619b811a4417aa4abe78dc653becf511', |
131 | 'note': 'Videos that embed the url in the player page', | |
132 | 'info_dict': { | |
4f3e9430 JMF |
133 | 'id': '54469442', |
134 | 'ext': 'mp4', | |
0e6ebc13 | 135 | 'title': 'Kathy Sierra: Building the minimum Badass User, Business of Software 2012', |
9148eb00 | 136 | 'uploader': 'The BLN & Business of Software', |
a2d7797c | 137 | 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/theblnbusinessofsoftware', |
9148eb00 | 138 | 'uploader_id': 'theblnbusinessofsoftware', |
69c8fb9e | 139 | 'duration': 3610, |
58ea7ec8 | 140 | 'description': None, |
aa32314d | 141 | }, |
93b22c78 JMF |
142 | }, |
143 | { | |
9148eb00 | 144 | 'url': 'http://vimeo.com/68375962', |
9148eb00 PH |
145 | 'md5': 'aaf896bdb7ddd6476df50007a0ac0ae7', |
146 | 'note': 'Video protected with password', | |
147 | 'info_dict': { | |
4f3e9430 JMF |
148 | 'id': '68375962', |
149 | 'ext': 'mp4', | |
9148eb00 PH |
150 | 'title': 'youtube-dl password protected test video', |
151 | 'upload_date': '20130614', | |
a2d7797c | 152 | 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/user18948128', |
9148eb00 PH |
153 | 'uploader_id': 'user18948128', |
154 | 'uploader': 'Jaime Marquínez Ferrándiz', | |
69c8fb9e | 155 | 'duration': 10, |
8bea039b | 156 | 'description': 'This is "youtube-dl password protected test video" by Jaime Marquínez Ferrándiz on Vimeo, the home for high quality videos and the people\u2026', |
93b22c78 | 157 | }, |
9148eb00 PH |
158 | 'params': { |
159 | 'videopassword': 'youtube-dl', | |
93b22c78 JMF |
160 | }, |
161 | }, | |
548f31d9 S |
162 | { |
163 | 'url': 'http://vimeo.com/channels/keypeele/75629013', | |
164 | 'md5': '2f86a05afe9d7abc0b9126d229bbe15d', | |
165 | 'note': 'Video is freely available via original URL ' | |
166 | 'and protected with password when accessed via http://vimeo.com/75629013', | |
167 | 'info_dict': { | |
168 | 'id': '75629013', | |
169 | 'ext': 'mp4', | |
170 | 'title': 'Key & Peele: Terrorist Interrogation', | |
171 | 'description': 'md5:8678b246399b070816b12313e8b4eb5c', | |
a2d7797c | 172 | 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/atencio', |
548f31d9 S |
173 | 'uploader_id': 'atencio', |
174 | 'uploader': 'Peter Atencio', | |
3c6f2450 | 175 | 'upload_date': '20130927', |
548f31d9 S |
176 | 'duration': 187, |
177 | }, | |
178 | }, | |
1eac553e S |
179 | { |
180 | 'url': 'http://vimeo.com/76979871', | |
1eac553e S |
181 | 'note': 'Video with subtitles', |
182 | 'info_dict': { | |
183 | 'id': '76979871', | |
184 | 'ext': 'mp4', | |
185 | 'title': 'The New Vimeo Player (You Know, For Videos)', | |
186 | 'description': 'md5:2ec900bf97c3f389378a96aee11260ea', | |
187 | 'upload_date': '20131015', | |
a2d7797c | 188 | 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/staff', |
1eac553e S |
189 | 'uploader_id': 'staff', |
190 | 'uploader': 'Vimeo Staff', | |
69c8fb9e | 191 | 'duration': 62, |
1eac553e S |
192 | } |
193 | }, | |
4698f0d8 JMF |
194 | { |
195 | # from https://www.ouya.tv/game/Pier-Solar-and-the-Great-Architects/ | |
196 | 'url': 'https://player.vimeo.com/video/98044508', | |
197 | 'note': 'The js code contains assignments to the same variable as the config', | |
198 | 'info_dict': { | |
199 | 'id': '98044508', | |
200 | 'ext': 'mp4', | |
201 | 'title': 'Pier Solar OUYA Official Trailer', | |
202 | 'uploader': 'Tulio Gonçalves', | |
a2d7797c | 203 | 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/user28849593', |
4698f0d8 JMF |
204 | 'uploader_id': 'user28849593', |
205 | }, | |
206 | }, | |
323f82a7 | 207 | { |
208 | # contains original format | |
209 | 'url': 'https://vimeo.com/33951933', | |
210 | 'md5': '53c688fa95a55bf4b7293d37a89c5c53', | |
211 | 'info_dict': { | |
212 | 'id': '33951933', | |
213 | 'ext': 'mp4', | |
214 | 'title': 'FOX CLASSICS - Forever Classic ID - A Full Minute', | |
215 | 'uploader': 'The DMCI', | |
a2d7797c | 216 | 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/dmci', |
323f82a7 | 217 | 'uploader_id': 'dmci', |
218 | 'upload_date': '20111220', | |
219 | 'description': 'md5:ae23671e82d05415868f7ad1aec21147', | |
220 | }, | |
221 | }, | |
8bea039b LL |
222 | { |
223 | 'url': 'https://vimeo.com/109815029', | |
224 | 'note': 'Video not completely processed, "failed" seed status', | |
225 | 'only_matching': True, | |
226 | }, | |
6b7ceee1 S |
227 | { |
228 | 'url': 'https://vimeo.com/groups/travelhd/videos/22439234', | |
229 | 'only_matching': True, | |
230 | }, | |
16f1131a S |
231 | { |
232 | # source file returns 403: Forbidden | |
233 | 'url': 'https://vimeo.com/7809605', | |
234 | 'only_matching': True, | |
235 | }, | |
a91b954b | 236 | ] |
b3d14cbf | 237 | |
b407e173 YCH |
238 | @staticmethod |
239 | def _extract_vimeo_url(url, webpage): | |
240 | # Look for embedded (iframe) Vimeo player | |
241 | mobj = re.search( | |
242 | r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/.+?)\1', webpage) | |
243 | if mobj: | |
244 | player_url = unescapeHTML(mobj.group('url')) | |
5dbe81a1 | 245 | surl = smuggle_url(player_url, {'http_headers': {'Referer': url}}) |
b407e173 YCH |
246 | return surl |
247 | # Look for embedded (swf embed) Vimeo player | |
248 | mobj = re.search( | |
249 | r'<embed[^>]+?src="((?:https?:)?//(?:www\.)?vimeo\.com/moogaloop\.swf.+?)"', webpage) | |
250 | if mobj: | |
251 | return mobj.group(1) | |
252 | ||
b3d14cbf | 253 | def _verify_video_password(self, url, video_id, webpage): |
d800609c | 254 | password = self._downloader.params.get('videopassword') |
b3d14cbf | 255 | if password is None: |
93a16ba2 | 256 | raise ExtractorError('This video is protected by a password, use the --video-password option', expected=True) |
7c845629 | 257 | token, vuid = self._extract_xsrft_and_vuid(webpage) |
852fad92 | 258 | data = urlencode_postdata(encode_dict({ |
4f3e9430 JMF |
259 | 'password': password, |
260 | 'token': token, | |
852fad92 | 261 | })) |
9c85b537 JMF |
262 | if url.startswith('http://'): |
263 | # vimeo only supports https now, but the user can give an http url | |
264 | url = url.replace('http://', 'https://') | |
67dda517 | 265 | password_request = sanitized_Request(url + '/password', data) |
b3d14cbf | 266 | password_request.add_header('Content-Type', 'application/x-www-form-urlencoded') |
12bb392a | 267 | password_request.add_header('Referer', url) |
9eab37dc | 268 | self._set_vimeo_cookie('vuid', vuid) |
bf8f082a PH |
269 | return self._download_webpage( |
270 | password_request, video_id, | |
271 | 'Verifying the password', 'Wrong password') | |
b3d14cbf | 272 | |
0eecc6a4 | 273 | def _verify_player_video_password(self, url, video_id): |
d800609c | 274 | password = self._downloader.params.get('videopassword') |
0eecc6a4 PH |
275 | if password is None: |
276 | raise ExtractorError('This video is protected by a password, use the --video-password option') | |
0a0110fc | 277 | data = urlencode_postdata(encode_dict({'password': password})) |
0eecc6a4 | 278 | pass_url = url + '/check-password' |
67dda517 | 279 | password_request = sanitized_Request(pass_url, data) |
0eecc6a4 PH |
280 | password_request.add_header('Content-Type', 'application/x-www-form-urlencoded') |
281 | return self._download_json( | |
282 | password_request, video_id, | |
283 | 'Verifying the password', | |
284 | 'Wrong password') | |
285 | ||
fc79158d JMF |
286 | def _real_initialize(self): |
287 | self._login() | |
288 | ||
a0088bdf | 289 | def _real_extract(self, url): |
5dbe81a1 | 290 | url, data = unsmuggle_url(url, {}) |
0f56a4b4 | 291 | headers = std_headers.copy() |
5dbe81a1 | 292 | if 'http_headers' in data: |
5dbe81a1 | 293 | headers.update(data['http_headers']) |
ba5d51b3 PH |
294 | if 'Referer' not in headers: |
295 | headers['Referer'] = url | |
9d4660ca | 296 | |
b3d14cbf PH |
297 | # Extract ID from URL |
298 | mobj = re.match(self._VALID_URL, url) | |
b3d14cbf | 299 | video_id = mobj.group('id') |
58ea7ec8 | 300 | orig_url = url |
9103bbc5 | 301 | if mobj.group('pro') or mobj.group('player'): |
61e00a97 | 302 | url = 'https://player.vimeo.com/video/' + video_id |
10831b5e | 303 | else: |
304 | url = 'https://vimeo.com/' + video_id | |
b3d14cbf PH |
305 | |
306 | # Retrieve video webpage to extract further information | |
0f56a4b4 | 307 | request = sanitized_Request(url, headers=headers) |
1060425c PH |
308 | try: |
309 | webpage = self._download_webpage(request, video_id) | |
310 | except ExtractorError as ee: | |
311 | if isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 403: | |
312 | errmsg = ee.cause.read() | |
313 | if b'Because of its privacy settings, this video cannot be played here' in errmsg: | |
314 | raise ExtractorError( | |
315 | 'Cannot download embed-only video without embedding ' | |
316 | 'URL. Please call youtube-dl with the URL of the page ' | |
317 | 'that embeds this video.', | |
318 | expected=True) | |
319 | raise | |
b3d14cbf PH |
320 | |
321 | # Now we begin extracting as much information as we can from what we | |
322 | # retrieved. First we extract the information common to all extractors, | |
323 | # and latter we extract those that are Vimeo specific. | |
324 | self.report_extraction(video_id) | |
325 | ||
998e6cdb | 326 | vimeo_config = self._search_regex( |
b6aa99af | 327 | r'vimeo\.config\s*=\s*(?:({.+?})|_extend\([^,]+,\s+({.+?})\));', webpage, |
998e6cdb S |
328 | 'vimeo config', default=None) |
329 | if vimeo_config: | |
330 | seed_status = self._parse_json(vimeo_config, video_id).get('seed_status', {}) | |
331 | if seed_status.get('state') == 'failed': | |
332 | raise ExtractorError( | |
b6aa99af | 333 | '%s said: %s' % (self.IE_NAME, seed_status['title']), |
998e6cdb S |
334 | expected=True) |
335 | ||
b3d14cbf PH |
336 | # Extract the config JSON |
337 | try: | |
93b22c78 JMF |
338 | try: |
339 | config_url = self._html_search_regex( | |
41a7b00f LL |
340 | r' data-config-url="(.+?)"', webpage, |
341 | 'config URL', default=None) | |
342 | if not config_url: | |
dd841752 S |
343 | # Sometimes new react-based page is served instead of old one that require |
344 | # different config URL extraction approach (see | |
345 | # https://github.com/rg3/youtube-dl/pull/7209) | |
41a7b00f LL |
346 | vimeo_clip_page_config = self._search_regex( |
347 | r'vimeo\.clip_page_config\s*=\s*({.+?});', webpage, | |
348 | 'vimeo clip page config') | |
dd841752 S |
349 | config_url = self._parse_json( |
350 | vimeo_clip_page_config, video_id)['player']['config_url'] | |
93b22c78 JMF |
351 | config_json = self._download_webpage(config_url, video_id) |
352 | config = json.loads(config_json) | |
353 | except RegexNotFoundError: | |
354 | # For pro videos or player.vimeo.com urls | |
48ad51b2 JMF |
355 | # We try to find out to which variable is assigned the config dic |
356 | m_variable_name = re.search('(\w)\.video\.id', webpage) | |
357 | if m_variable_name is not None: | |
4698f0d8 | 358 | config_re = r'%s=({[^}].+?});' % re.escape(m_variable_name.group(1)) |
48ad51b2 JMF |
359 | else: |
360 | config_re = [r' = {config:({.+?}),assets:', r'(?:[abc])=({.+?});'] | |
9148eb00 | 361 | config = self._search_regex(config_re, webpage, 'info section', |
9e1a5b84 | 362 | flags=re.DOTALL) |
93b22c78 | 363 | config = json.loads(config) |
71907db3 | 364 | except Exception as e: |
b3d14cbf | 365 | if re.search('The creator of this video has not given you permission to embed it on this domain.', webpage): |
9148eb00 | 366 | raise ExtractorError('The author has restricted the access to this video, try with the "--referer" option') |
b3d14cbf | 367 | |
bf8f082a | 368 | if re.search(r'<form[^>]+?id="pw_form"', webpage) is not None: |
5dbe81a1 | 369 | if '_video_password_verified' in data: |
30965ac6 | 370 | raise ExtractorError('video password verification failed!') |
b3d14cbf | 371 | self._verify_video_password(url, video_id, webpage) |
30965ac6 PH |
372 | return self._real_extract( |
373 | smuggle_url(url, {'_video_password_verified': 'verified'})) | |
b3d14cbf | 374 | else: |
9148eb00 | 375 | raise ExtractorError('Unable to extract info section', |
71907db3 | 376 | cause=e) |
559e370f PH |
377 | else: |
378 | if config.get('view') == 4: | |
0eecc6a4 | 379 | config = self._verify_player_video_password(url, video_id) |
b3d14cbf | 380 | |
5dbe81a1 S |
381 | if '>You rented this title.<' in webpage: |
382 | feature_id = config.get('video', {}).get('vod', {}).get('feature_id') | |
383 | if feature_id and not data.get('force_feature_id', False): | |
384 | return self.url_result(smuggle_url( | |
385 | 'https://player.vimeo.com/player/%s' % feature_id, | |
386 | {'force_feature_id': True}), 'Vimeo') | |
387 | ||
b3d14cbf | 388 | # Extract title |
611c1dd9 | 389 | video_title = config['video']['title'] |
b3d14cbf | 390 | |
a2d7797c S |
391 | # Extract uploader, uploader_url and uploader_id |
392 | video_uploader = config['video'].get('owner', {}).get('name') | |
393 | video_uploader_url = config['video'].get('owner', {}).get('url') | |
394 | video_uploader_id = video_uploader_url.split('/')[-1] if video_uploader_url else None | |
b3d14cbf PH |
395 | |
396 | # Extract video thumbnail | |
611c1dd9 | 397 | video_thumbnail = config['video'].get('thumbnail') |
c0e5d856 | 398 | if video_thumbnail is None: |
611c1dd9 | 399 | video_thumbs = config['video'].get('thumbs') |
c0e5d856 | 400 | if video_thumbs and isinstance(video_thumbs, dict): |
3e510af3 | 401 | _, video_thumbnail = sorted((int(width if width.isdigit() else 0), t_url) for (width, t_url) in video_thumbs.items())[-1] |
b3d14cbf PH |
402 | |
403 | # Extract video description | |
58ea7ec8 | 404 | |
25930395 | 405 | video_description = self._html_search_regex( |
58ea7ec8 PH |
406 | r'(?s)<div\s+class="[^"]*description[^"]*"[^>]*>(.*?)</div>', |
407 | webpage, 'description', default=None) | |
408 | if not video_description: | |
409 | video_description = self._html_search_meta( | |
410 | 'description', webpage, default=None) | |
411 | if not video_description and mobj.group('pro'): | |
412 | orig_webpage = self._download_webpage( | |
413 | orig_url, video_id, | |
414 | note='Downloading webpage for description', | |
415 | fatal=False) | |
416 | if orig_webpage: | |
417 | video_description = self._html_search_meta( | |
418 | 'description', orig_webpage, default=None) | |
419 | if not video_description and not mobj.group('player'): | |
420 | self._downloader.report_warning('Cannot find video description') | |
b3d14cbf | 421 | |
69c8fb9e | 422 | # Extract video duration |
611c1dd9 | 423 | video_duration = int_or_none(config['video'].get('duration')) |
69c8fb9e | 424 | |
b3d14cbf PH |
425 | # Extract upload date |
426 | video_upload_date = None | |
3c6f2450 | 427 | mobj = re.search(r'<time[^>]+datetime="([^"]+)"', webpage) |
b3d14cbf | 428 | if mobj is not None: |
3c6f2450 | 429 | video_upload_date = unified_strdate(mobj.group(1)) |
b3d14cbf | 430 | |
4e761794 | 431 | try: |
9148eb00 PH |
432 | view_count = int(self._search_regex(r'UserPlays:(\d+)', webpage, 'view count')) |
433 | like_count = int(self._search_regex(r'UserLikes:(\d+)', webpage, 'like count')) | |
434 | comment_count = int(self._search_regex(r'UserComments:(\d+)', webpage, 'comment count')) | |
4e761794 JMF |
435 | except RegexNotFoundError: |
436 | # This info is only available in vimeo.com/{id} urls | |
437 | view_count = None | |
438 | like_count = None | |
439 | comment_count = None | |
440 | ||
a6387bfd | 441 | formats = [] |
eb4f2740 | 442 | download_request = sanitized_Request('https://vimeo.com/%s?action=load_download_config' % video_id, headers={ |
443 | 'X-Requested-With': 'XMLHttpRequest'}) | |
444 | download_data = self._download_json(download_request, video_id, fatal=False) | |
445 | if download_data: | |
446 | source_file = download_data.get('source_file') | |
d5f071af S |
447 | if isinstance(source_file, dict): |
448 | download_url = source_file.get('download_url') | |
449 | if download_url and not source_file.get('is_cold') and not source_file.get('is_defrosting'): | |
450 | source_name = source_file.get('public_name', 'Original') | |
451 | if self._is_valid_url(download_url, video_id, '%s video' % source_name): | |
4519c1f4 | 452 | ext = source_file.get('extension', determine_ext(download_url)).lower() |
d5f071af S |
453 | formats.append({ |
454 | 'url': download_url, | |
455 | 'ext': ext, | |
456 | 'width': int_or_none(source_file.get('width')), | |
457 | 'height': int_or_none(source_file.get('height')), | |
458 | 'filesize': parse_filesize(source_file.get('size')), | |
459 | 'format_id': source_name, | |
460 | 'preference': 1, | |
461 | }) | |
fcd817a3 S |
462 | config_files = config['video'].get('files') or config['request'].get('files', {}) |
463 | for f in config_files.get('progressive', []): | |
464 | video_url = f.get('url') | |
465 | if not video_url: | |
466 | continue | |
467 | formats.append({ | |
468 | 'url': video_url, | |
469 | 'format_id': 'http-%s' % f.get('quality'), | |
470 | 'width': int_or_none(f.get('width')), | |
471 | 'height': int_or_none(f.get('height')), | |
472 | 'fps': int_or_none(f.get('fps')), | |
473 | 'tbr': int_or_none(f.get('bitrate')), | |
474 | }) | |
475 | m3u8_url = config_files.get('hls', {}).get('url') | |
35a3ff1d | 476 | if m3u8_url: |
7e5edcfd S |
477 | formats.extend(self._extract_m3u8_formats( |
478 | m3u8_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False)) | |
fcd817a3 S |
479 | # Bitrates are completely broken. Single m3u8 may contain entries in kbps and bps |
480 | # at the same time without actual units specified. This lead to wrong sorting. | |
8534bf1f | 481 | self._sort_formats(formats, field_preference=('preference', 'height', 'width', 'fps', 'format_id')) |
b3d14cbf | 482 | |
1eac553e S |
483 | subtitles = {} |
484 | text_tracks = config['request'].get('text_tracks') | |
485 | if text_tracks: | |
486 | for tt in text_tracks: | |
65469a7f JMF |
487 | subtitles[tt['lang']] = [{ |
488 | 'ext': 'vtt', | |
3946864c | 489 | 'url': 'https://vimeo.com' + tt['url'], |
65469a7f | 490 | }] |
1eac553e | 491 | |
9103bbc5 | 492 | return { |
b0268cb6 | 493 | 'id': video_id, |
b3d14cbf | 494 | 'uploader': video_uploader, |
a2d7797c | 495 | 'uploader_url': video_uploader_url, |
b3d14cbf | 496 | 'uploader_id': video_uploader_id, |
b0268cb6 S |
497 | 'upload_date': video_upload_date, |
498 | 'title': video_title, | |
499 | 'thumbnail': video_thumbnail, | |
500 | 'description': video_description, | |
69c8fb9e | 501 | 'duration': video_duration, |
a6387bfd | 502 | 'formats': formats, |
9103bbc5 | 503 | 'webpage_url': url, |
4e761794 JMF |
504 | 'view_count': view_count, |
505 | 'like_count': like_count, | |
506 | 'comment_count': comment_count, | |
65469a7f | 507 | 'subtitles': subtitles, |
9103bbc5 | 508 | } |
caeefc29 JMF |
509 | |
510 | ||
74278def | 511 | class VimeoOndemandIE(VimeoBaseInfoExtractor): |
1e501364 | 512 | IE_NAME = 'vimeo:ondemand' |
74278def S |
513 | _VALID_URL = r'https?://(?:www\.)?vimeo\.com/ondemand/(?P<id>[^/?#&]+)' |
514 | _TESTS = [{ | |
515 | # ondemand video not available via https://vimeo.com/id | |
516 | 'url': 'https://vimeo.com/ondemand/20704', | |
517 | 'md5': 'c424deda8c7f73c1dfb3edd7630e2f35', | |
518 | 'info_dict': { | |
519 | 'id': '105442900', | |
520 | 'ext': 'mp4', | |
521 | 'title': 'המעבדה - במאי יותם פלדמן', | |
522 | 'uploader': 'גם סרטים', | |
523 | 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/gumfilms', | |
524 | 'uploader_id': 'gumfilms', | |
525 | }, | |
526 | }, { | |
527 | 'url': 'https://vimeo.com/ondemand/nazmaalik', | |
528 | 'only_matching': True, | |
529 | }, { | |
530 | 'url': 'https://vimeo.com/ondemand/141692381', | |
531 | 'only_matching': True, | |
532 | }, { | |
533 | 'url': 'https://vimeo.com/ondemand/thelastcolony/150274832', | |
534 | 'only_matching': True, | |
535 | }] | |
536 | ||
537 | def _real_extract(self, url): | |
538 | video_id = self._match_id(url) | |
539 | webpage = self._download_webpage(url, video_id) | |
540 | return self.url_result(self._og_search_video_url(webpage), VimeoIE.ie_key()) | |
541 | ||
542 | ||
f6c3664d | 543 | class VimeoChannelIE(VimeoBaseInfoExtractor): |
9148eb00 | 544 | IE_NAME = 'vimeo:channel' |
3946864c | 545 | _VALID_URL = r'https://vimeo\.com/channels/(?P<id>[^/?#]+)/?(?:$|[?#])' |
caeefc29 | 546 | _MORE_PAGES_INDICATOR = r'<a.+?rel="next"' |
84458766 | 547 | _TITLE = None |
55a10eab | 548 | _TITLE_RE = r'<link rel="alternate"[^>]+?title="(.*?)"' |
2929b3e7 | 549 | _TESTS = [{ |
3946864c | 550 | 'url': 'https://vimeo.com/channels/tributes', |
2929b3e7 | 551 | 'info_dict': { |
a3fa5da4 | 552 | 'id': 'tributes', |
2929b3e7 PH |
553 | 'title': 'Vimeo Tributes', |
554 | }, | |
555 | 'playlist_mincount': 25, | |
556 | }] | |
caeefc29 | 557 | |
5cc14c2f JMF |
558 | def _page_url(self, base_url, pagenum): |
559 | return '%s/videos/page:%d/' % (base_url, pagenum) | |
560 | ||
fb30ec22 | 561 | def _extract_list_title(self, webpage): |
84458766 | 562 | return self._TITLE or self._html_search_regex(self._TITLE_RE, webpage, 'list title') |
fb30ec22 | 563 | |
bf8f082a PH |
564 | def _login_list_password(self, page_url, list_id, webpage): |
565 | login_form = self._search_regex( | |
566 | r'(?s)<form[^>]+?id="pw_form"(.*?)</form>', | |
567 | webpage, 'login form', default=None) | |
568 | if not login_form: | |
569 | return webpage | |
570 | ||
d800609c | 571 | password = self._downloader.params.get('videopassword') |
bf8f082a PH |
572 | if password is None: |
573 | raise ExtractorError('This album is protected by a password, use the --video-password option', expected=True) | |
f8da79f8 | 574 | fields = self._hidden_inputs(login_form) |
7c845629 | 575 | token, vuid = self._extract_xsrft_and_vuid(webpage) |
bf8f082a PH |
576 | fields['token'] = token |
577 | fields['password'] = password | |
bfdf891f | 578 | post = urlencode_postdata(encode_dict(fields)) |
bf8f082a PH |
579 | password_path = self._search_regex( |
580 | r'action="([^"]+)"', login_form, 'password URL') | |
581 | password_url = compat_urlparse.urljoin(page_url, password_path) | |
67dda517 | 582 | password_request = sanitized_Request(password_url, post) |
bf8f082a | 583 | password_request.add_header('Content-type', 'application/x-www-form-urlencoded') |
9eab37dc S |
584 | self._set_vimeo_cookie('vuid', vuid) |
585 | self._set_vimeo_cookie('xsrft', token) | |
bf8f082a PH |
586 | |
587 | return self._download_webpage( | |
588 | password_request, list_id, | |
589 | 'Verifying the password', 'Wrong password') | |
590 | ||
2c94198e | 591 | def _title_and_entries(self, list_id, base_url): |
caeefc29 | 592 | for pagenum in itertools.count(1): |
bf8f082a | 593 | page_url = self._page_url(base_url, pagenum) |
55a10eab | 594 | webpage = self._download_webpage( |
bf8f082a | 595 | page_url, list_id, |
9148eb00 | 596 | 'Downloading page %s' % pagenum) |
bf8f082a PH |
597 | |
598 | if pagenum == 1: | |
599 | webpage = self._login_list_password(page_url, list_id, webpage) | |
2c94198e S |
600 | yield self._extract_list_title(webpage) |
601 | ||
602 | for video_id in re.findall(r'id="clip_(\d+?)"', webpage): | |
603 | yield self.url_result('https://vimeo.com/%s' % video_id, 'Vimeo') | |
bf8f082a | 604 | |
caeefc29 JMF |
605 | if re.search(self._MORE_PAGES_INDICATOR, webpage, re.DOTALL) is None: |
606 | break | |
607 | ||
2c94198e S |
608 | def _extract_videos(self, list_id, base_url): |
609 | title_and_entries = self._title_and_entries(list_id, base_url) | |
610 | list_title = next(title_and_entries) | |
611 | return self.playlist_result(title_and_entries, list_id, list_title) | |
55a10eab JMF |
612 | |
613 | def _real_extract(self, url): | |
614 | mobj = re.match(self._VALID_URL, url) | |
4f3e9430 | 615 | channel_id = mobj.group('id') |
3946864c | 616 | return self._extract_videos(channel_id, 'https://vimeo.com/channels/%s' % channel_id) |
55a10eab JMF |
617 | |
618 | ||
619 | class VimeoUserIE(VimeoChannelIE): | |
9148eb00 | 620 | IE_NAME = 'vimeo:user' |
b29440ae | 621 | _VALID_URL = r'https://vimeo\.com/(?!(?:[0-9]+|watchlater)(?:$|[?#/]))(?P<name>[^/]+)(?:/videos|[#?]|$)' |
55a10eab | 622 | _TITLE_RE = r'<a[^>]+?class="user">([^<>]+?)</a>' |
2929b3e7 | 623 | _TESTS = [{ |
3946864c | 624 | 'url': 'https://vimeo.com/nkistudio/videos', |
2929b3e7 PH |
625 | 'info_dict': { |
626 | 'title': 'Nki', | |
a3fa5da4 | 627 | 'id': 'nkistudio', |
2929b3e7 PH |
628 | }, |
629 | 'playlist_mincount': 66, | |
630 | }] | |
55a10eab JMF |
631 | |
632 | def _real_extract(self, url): | |
633 | mobj = re.match(self._VALID_URL, url) | |
634 | name = mobj.group('name') | |
3946864c | 635 | return self._extract_videos(name, 'https://vimeo.com/%s' % name) |
5cc14c2f JMF |
636 | |
637 | ||
638 | class VimeoAlbumIE(VimeoChannelIE): | |
9148eb00 | 639 | IE_NAME = 'vimeo:album' |
d1508cd6 | 640 | _VALID_URL = r'https://vimeo\.com/album/(?P<id>\d+)' |
5cc14c2f | 641 | _TITLE_RE = r'<header id="page_header">\n\s*<h1>(.*?)</h1>' |
2929b3e7 | 642 | _TESTS = [{ |
d1508cd6 | 643 | 'url': 'https://vimeo.com/album/2632481', |
2929b3e7 | 644 | 'info_dict': { |
a3fa5da4 | 645 | 'id': '2632481', |
2929b3e7 PH |
646 | 'title': 'Staff Favorites: November 2013', |
647 | }, | |
648 | 'playlist_mincount': 13, | |
bf8f082a PH |
649 | }, { |
650 | 'note': 'Password-protected album', | |
651 | 'url': 'https://vimeo.com/album/3253534', | |
652 | 'info_dict': { | |
653 | 'title': 'test', | |
654 | 'id': '3253534', | |
655 | }, | |
656 | 'playlist_count': 1, | |
657 | 'params': { | |
658 | 'videopassword': 'youtube-dl', | |
659 | } | |
2929b3e7 | 660 | }] |
5cc14c2f JMF |
661 | |
662 | def _page_url(self, base_url, pagenum): | |
663 | return '%s/page:%d/' % (base_url, pagenum) | |
664 | ||
665 | def _real_extract(self, url): | |
bf8f082a | 666 | album_id = self._match_id(url) |
d1508cd6 | 667 | return self._extract_videos(album_id, 'https://vimeo.com/album/%s' % album_id) |
fb30ec22 JMF |
668 | |
669 | ||
670 | class VimeoGroupsIE(VimeoAlbumIE): | |
9148eb00 | 671 | IE_NAME = 'vimeo:group' |
fdb20a27 | 672 | _VALID_URL = r'https://vimeo\.com/groups/(?P<name>[^/]+)(?:/(?!videos?/\d+)|$)' |
2929b3e7 | 673 | _TESTS = [{ |
3946864c | 674 | 'url': 'https://vimeo.com/groups/rolexawards', |
2929b3e7 | 675 | 'info_dict': { |
a3fa5da4 | 676 | 'id': 'rolexawards', |
2929b3e7 PH |
677 | 'title': 'Rolex Awards for Enterprise', |
678 | }, | |
679 | 'playlist_mincount': 73, | |
680 | }] | |
fb30ec22 JMF |
681 | |
682 | def _extract_list_title(self, webpage): | |
683 | return self._og_search_title(webpage) | |
684 | ||
685 | def _real_extract(self, url): | |
686 | mobj = re.match(self._VALID_URL, url) | |
687 | name = mobj.group('name') | |
3946864c | 688 | return self._extract_videos(name, 'https://vimeo.com/groups/%s' % name) |
fcea44c6 PH |
689 | |
690 | ||
691 | class VimeoReviewIE(InfoExtractor): | |
9148eb00 PH |
692 | IE_NAME = 'vimeo:review' |
693 | IE_DESC = 'Review pages on vimeo' | |
3946864c | 694 | _VALID_URL = r'https://vimeo\.com/[^/]+/review/(?P<id>[^/]+)' |
d36d3f42 | 695 | _TESTS = [{ |
fcea44c6 | 696 | 'url': 'https://vimeo.com/user21297594/review/75524534/3c257a1b5d', |
fcea44c6 PH |
697 | 'md5': 'c507a72f780cacc12b2248bb4006d253', |
698 | 'info_dict': { | |
fc09240e PH |
699 | 'id': '75524534', |
700 | 'ext': 'mp4', | |
fcea44c6 PH |
701 | 'title': "DICK HARDWICK 'Comedian'", |
702 | 'uploader': 'Richard Hardwick', | |
703 | } | |
d36d3f42 PH |
704 | }, { |
705 | 'note': 'video player needs Referer', | |
3946864c | 706 | 'url': 'https://vimeo.com/user22258446/review/91613211/13f927e053', |
d36d3f42 PH |
707 | 'md5': '6295fdab8f4bf6a002d058b2c6dce276', |
708 | 'info_dict': { | |
709 | 'id': '91613211', | |
710 | 'ext': 'mp4', | |
9dec9930 | 711 | 'title': 're:(?i)^Death by dogma versus assembling agile . Sander Hoogendoorn', |
d36d3f42 PH |
712 | 'uploader': 'DevWeek Events', |
713 | 'duration': 2773, | |
714 | 'thumbnail': 're:^https?://.*\.jpg$', | |
715 | } | |
716 | }] | |
fcea44c6 PH |
717 | |
718 | def _real_extract(self, url): | |
719 | mobj = re.match(self._VALID_URL, url) | |
720 | video_id = mobj.group('id') | |
721 | player_url = 'https://player.vimeo.com/player/' + video_id | |
722 | return self.url_result(player_url, 'Vimeo', video_id) | |
efb7e119 JMF |
723 | |
724 | ||
f6c3664d | 725 | class VimeoWatchLaterIE(VimeoChannelIE): |
efb7e119 JMF |
726 | IE_NAME = 'vimeo:watchlater' |
727 | IE_DESC = 'Vimeo watch later list, "vimeowatchlater" keyword (requires authentication)' | |
84458766 S |
728 | _VALID_URL = r'https://vimeo\.com/(?:home/)?watchlater|:vimeowatchlater' |
729 | _TITLE = 'Watch Later' | |
efb7e119 | 730 | _LOGIN_REQUIRED = True |
2929b3e7 | 731 | _TESTS = [{ |
84458766 | 732 | 'url': 'https://vimeo.com/watchlater', |
2929b3e7 PH |
733 | 'only_matching': True, |
734 | }] | |
efb7e119 JMF |
735 | |
736 | def _real_initialize(self): | |
737 | self._login() | |
738 | ||
739 | def _page_url(self, base_url, pagenum): | |
740 | url = '%s/page:%d/' % (base_url, pagenum) | |
67dda517 | 741 | request = sanitized_Request(url) |
efb7e119 JMF |
742 | # Set the header to get a partial html page with the ids, |
743 | # the normal page doesn't contain them. | |
744 | request.add_header('X-Requested-With', 'XMLHttpRequest') | |
745 | return request | |
746 | ||
747 | def _real_extract(self, url): | |
84458766 | 748 | return self._extract_videos('watchlater', 'https://vimeo.com/watchlater') |
d6e6a422 PH |
749 | |
750 | ||
751 | class VimeoLikesIE(InfoExtractor): | |
3946864c | 752 | _VALID_URL = r'https://(?:www\.)?vimeo\.com/user(?P<id>[0-9]+)/likes/?(?:$|[?#]|sort:)' |
d6e6a422 PH |
753 | IE_NAME = 'vimeo:likes' |
754 | IE_DESC = 'Vimeo user likes' | |
755 | _TEST = { | |
9c44d242 PH |
756 | 'url': 'https://vimeo.com/user755559/likes/', |
757 | 'playlist_mincount': 293, | |
611c1dd9 | 758 | 'info_dict': { |
a3fa5da4 | 759 | 'id': 'user755559_likes', |
611c1dd9 S |
760 | 'description': 'See all the videos urza likes', |
761 | 'title': 'Videos urza likes', | |
d6e6a422 PH |
762 | }, |
763 | } | |
764 | ||
765 | def _real_extract(self, url): | |
766 | user_id = self._match_id(url) | |
9c44d242 PH |
767 | webpage = self._download_webpage(url, user_id) |
768 | page_count = self._int( | |
769 | self._search_regex( | |
770 | r'''(?x)<li><a\s+href="[^"]+"\s+data-page="([0-9]+)"> | |
771 | .*?</a></li>\s*<li\s+class="pagination_next"> | |
772 | ''', webpage, 'page count'), | |
773 | 'page count', fatal=True) | |
774 | PAGE_SIZE = 12 | |
775 | title = self._html_search_regex( | |
776 | r'(?s)<h1>(.+?)</h1>', webpage, 'title', fatal=False) | |
777 | description = self._html_search_meta('description', webpage) | |
778 | ||
779 | def _get_page(idx): | |
3946864c JMF |
780 | page_url = 'https://vimeo.com/user%s/likes/page:%d/sort:date' % ( |
781 | user_id, idx + 1) | |
9c44d242 PH |
782 | webpage = self._download_webpage( |
783 | page_url, user_id, | |
784 | note='Downloading page %d/%d' % (idx + 1, page_count)) | |
785 | video_list = self._search_regex( | |
786 | r'(?s)<ol class="js-browse_list[^"]+"[^>]*>(.*?)</ol>', | |
787 | webpage, 'video content') | |
788 | paths = re.findall( | |
789 | r'<li[^>]*>\s*<a\s+href="([^"]+)"', video_list) | |
790 | for path in paths: | |
791 | yield { | |
792 | '_type': 'url', | |
793 | 'url': compat_urlparse.urljoin(page_url, path), | |
794 | } | |
795 | ||
796 | pl = InAdvancePagedList(_get_page, page_count, PAGE_SIZE) | |
d6e6a422 PH |
797 | |
798 | return { | |
9c44d242 PH |
799 | '_type': 'playlist', |
800 | 'id': 'user%s_likes' % user_id, | |
801 | 'title': title, | |
802 | 'description': description, | |
803 | 'entries': pl, | |
d6e6a422 | 804 | } |