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