]>
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 | }, | |
323f82a7 | 188 | { |
189 | # contains original format | |
190 | 'url': 'https://vimeo.com/33951933', | |
191 | 'md5': '53c688fa95a55bf4b7293d37a89c5c53', | |
192 | 'info_dict': { | |
193 | 'id': '33951933', | |
194 | 'ext': 'mp4', | |
195 | 'title': 'FOX CLASSICS - Forever Classic ID - A Full Minute', | |
196 | 'uploader': 'The DMCI', | |
197 | 'uploader_id': 'dmci', | |
198 | 'upload_date': '20111220', | |
199 | 'description': 'md5:ae23671e82d05415868f7ad1aec21147', | |
200 | }, | |
201 | }, | |
8bea039b LL |
202 | { |
203 | 'url': 'https://vimeo.com/109815029', | |
204 | 'note': 'Video not completely processed, "failed" seed status', | |
205 | 'only_matching': True, | |
206 | }, | |
6b7ceee1 S |
207 | { |
208 | 'url': 'https://vimeo.com/groups/travelhd/videos/22439234', | |
209 | 'only_matching': True, | |
210 | }, | |
a91b954b | 211 | ] |
b3d14cbf | 212 | |
b407e173 YCH |
213 | @staticmethod |
214 | def _extract_vimeo_url(url, webpage): | |
215 | # Look for embedded (iframe) Vimeo player | |
216 | mobj = re.search( | |
217 | r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/.+?)\1', webpage) | |
218 | if mobj: | |
219 | player_url = unescapeHTML(mobj.group('url')) | |
220 | surl = smuggle_url(player_url, {'Referer': url}) | |
221 | return surl | |
222 | # Look for embedded (swf embed) Vimeo player | |
223 | mobj = re.search( | |
224 | r'<embed[^>]+?src="((?:https?:)?//(?:www\.)?vimeo\.com/moogaloop\.swf.+?)"', webpage) | |
225 | if mobj: | |
226 | return mobj.group(1) | |
227 | ||
b3d14cbf | 228 | def _verify_video_password(self, url, video_id, webpage): |
c6c19746 | 229 | password = self._downloader.params.get('videopassword', None) |
b3d14cbf | 230 | if password is None: |
93a16ba2 | 231 | raise ExtractorError('This video is protected by a password, use the --video-password option', expected=True) |
7c845629 | 232 | token, vuid = self._extract_xsrft_and_vuid(webpage) |
852fad92 | 233 | data = urlencode_postdata(encode_dict({ |
4f3e9430 JMF |
234 | 'password': password, |
235 | 'token': token, | |
852fad92 | 236 | })) |
9c85b537 JMF |
237 | if url.startswith('http://'): |
238 | # vimeo only supports https now, but the user can give an http url | |
239 | url = url.replace('http://', 'https://') | |
67dda517 | 240 | password_request = sanitized_Request(url + '/password', data) |
b3d14cbf | 241 | password_request.add_header('Content-Type', 'application/x-www-form-urlencoded') |
12bb392a | 242 | password_request.add_header('Referer', url) |
9eab37dc | 243 | self._set_vimeo_cookie('vuid', vuid) |
bf8f082a PH |
244 | return self._download_webpage( |
245 | password_request, video_id, | |
246 | 'Verifying the password', 'Wrong password') | |
b3d14cbf | 247 | |
0eecc6a4 PH |
248 | def _verify_player_video_password(self, url, video_id): |
249 | password = self._downloader.params.get('videopassword', None) | |
250 | if password is None: | |
251 | raise ExtractorError('This video is protected by a password, use the --video-password option') | |
0a0110fc | 252 | data = urlencode_postdata(encode_dict({'password': password})) |
0eecc6a4 | 253 | pass_url = url + '/check-password' |
67dda517 | 254 | password_request = sanitized_Request(pass_url, data) |
0eecc6a4 PH |
255 | password_request.add_header('Content-Type', 'application/x-www-form-urlencoded') |
256 | return self._download_json( | |
257 | password_request, video_id, | |
258 | 'Verifying the password', | |
259 | 'Wrong password') | |
260 | ||
fc79158d JMF |
261 | def _real_initialize(self): |
262 | self._login() | |
263 | ||
a0088bdf | 264 | def _real_extract(self, url): |
9d4660ca PH |
265 | url, data = unsmuggle_url(url) |
266 | headers = std_headers | |
267 | if data is not None: | |
268 | headers = headers.copy() | |
269 | headers.update(data) | |
ba5d51b3 PH |
270 | if 'Referer' not in headers: |
271 | headers['Referer'] = url | |
9d4660ca | 272 | |
b3d14cbf PH |
273 | # Extract ID from URL |
274 | mobj = re.match(self._VALID_URL, url) | |
b3d14cbf | 275 | video_id = mobj.group('id') |
58ea7ec8 | 276 | orig_url = url |
9103bbc5 | 277 | if mobj.group('pro') or mobj.group('player'): |
61e00a97 | 278 | url = 'https://player.vimeo.com/video/' + video_id |
10831b5e | 279 | else: |
280 | url = 'https://vimeo.com/' + video_id | |
b3d14cbf PH |
281 | |
282 | # Retrieve video webpage to extract further information | |
67dda517 | 283 | request = sanitized_Request(url, None, headers) |
1060425c PH |
284 | try: |
285 | webpage = self._download_webpage(request, video_id) | |
286 | except ExtractorError as ee: | |
287 | if isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 403: | |
288 | errmsg = ee.cause.read() | |
289 | if b'Because of its privacy settings, this video cannot be played here' in errmsg: | |
290 | raise ExtractorError( | |
291 | 'Cannot download embed-only video without embedding ' | |
292 | 'URL. Please call youtube-dl with the URL of the page ' | |
293 | 'that embeds this video.', | |
294 | expected=True) | |
295 | raise | |
b3d14cbf PH |
296 | |
297 | # Now we begin extracting as much information as we can from what we | |
298 | # retrieved. First we extract the information common to all extractors, | |
299 | # and latter we extract those that are Vimeo specific. | |
300 | self.report_extraction(video_id) | |
301 | ||
998e6cdb | 302 | vimeo_config = self._search_regex( |
b6aa99af | 303 | r'vimeo\.config\s*=\s*(?:({.+?})|_extend\([^,]+,\s+({.+?})\));', webpage, |
998e6cdb S |
304 | 'vimeo config', default=None) |
305 | if vimeo_config: | |
306 | seed_status = self._parse_json(vimeo_config, video_id).get('seed_status', {}) | |
307 | if seed_status.get('state') == 'failed': | |
308 | raise ExtractorError( | |
b6aa99af | 309 | '%s said: %s' % (self.IE_NAME, seed_status['title']), |
998e6cdb S |
310 | expected=True) |
311 | ||
b3d14cbf PH |
312 | # Extract the config JSON |
313 | try: | |
93b22c78 JMF |
314 | try: |
315 | config_url = self._html_search_regex( | |
41a7b00f LL |
316 | r' data-config-url="(.+?)"', webpage, |
317 | 'config URL', default=None) | |
318 | if not config_url: | |
dd841752 S |
319 | # Sometimes new react-based page is served instead of old one that require |
320 | # different config URL extraction approach (see | |
321 | # https://github.com/rg3/youtube-dl/pull/7209) | |
41a7b00f LL |
322 | vimeo_clip_page_config = self._search_regex( |
323 | r'vimeo\.clip_page_config\s*=\s*({.+?});', webpage, | |
324 | 'vimeo clip page config') | |
dd841752 S |
325 | config_url = self._parse_json( |
326 | vimeo_clip_page_config, video_id)['player']['config_url'] | |
93b22c78 JMF |
327 | config_json = self._download_webpage(config_url, video_id) |
328 | config = json.loads(config_json) | |
329 | except RegexNotFoundError: | |
330 | # For pro videos or player.vimeo.com urls | |
48ad51b2 JMF |
331 | # We try to find out to which variable is assigned the config dic |
332 | m_variable_name = re.search('(\w)\.video\.id', webpage) | |
333 | if m_variable_name is not None: | |
4698f0d8 | 334 | config_re = r'%s=({[^}].+?});' % re.escape(m_variable_name.group(1)) |
48ad51b2 JMF |
335 | else: |
336 | config_re = [r' = {config:({.+?}),assets:', r'(?:[abc])=({.+?});'] | |
9148eb00 | 337 | config = self._search_regex(config_re, webpage, 'info section', |
9e1a5b84 | 338 | flags=re.DOTALL) |
93b22c78 | 339 | config = json.loads(config) |
71907db3 | 340 | except Exception as e: |
b3d14cbf | 341 | if re.search('The creator of this video has not given you permission to embed it on this domain.', webpage): |
9148eb00 | 342 | raise ExtractorError('The author has restricted the access to this video, try with the "--referer" option') |
b3d14cbf | 343 | |
bf8f082a | 344 | if re.search(r'<form[^>]+?id="pw_form"', webpage) is not None: |
30965ac6 PH |
345 | if data and '_video_password_verified' in data: |
346 | raise ExtractorError('video password verification failed!') | |
b3d14cbf | 347 | self._verify_video_password(url, video_id, webpage) |
30965ac6 PH |
348 | return self._real_extract( |
349 | smuggle_url(url, {'_video_password_verified': 'verified'})) | |
b3d14cbf | 350 | else: |
9148eb00 | 351 | raise ExtractorError('Unable to extract info section', |
71907db3 | 352 | cause=e) |
559e370f PH |
353 | else: |
354 | if config.get('view') == 4: | |
0eecc6a4 | 355 | config = self._verify_player_video_password(url, video_id) |
b3d14cbf PH |
356 | |
357 | # Extract title | |
358 | video_title = config["video"]["title"] | |
359 | ||
360 | # Extract uploader and uploader_id | |
361 | video_uploader = config["video"]["owner"]["name"] | |
362 | video_uploader_id = config["video"]["owner"]["url"].split('/')[-1] if config["video"]["owner"]["url"] else None | |
363 | ||
364 | # Extract video thumbnail | |
aa32314d | 365 | video_thumbnail = config["video"].get("thumbnail") |
c0e5d856 S |
366 | if video_thumbnail is None: |
367 | video_thumbs = config["video"].get("thumbs") | |
368 | if video_thumbs and isinstance(video_thumbs, dict): | |
3e510af3 | 369 | _, video_thumbnail = sorted((int(width if width.isdigit() else 0), t_url) for (width, t_url) in video_thumbs.items())[-1] |
b3d14cbf PH |
370 | |
371 | # Extract video description | |
58ea7ec8 | 372 | |
25930395 | 373 | video_description = self._html_search_regex( |
58ea7ec8 PH |
374 | r'(?s)<div\s+class="[^"]*description[^"]*"[^>]*>(.*?)</div>', |
375 | webpage, 'description', default=None) | |
376 | if not video_description: | |
377 | video_description = self._html_search_meta( | |
378 | 'description', webpage, default=None) | |
379 | if not video_description and mobj.group('pro'): | |
380 | orig_webpage = self._download_webpage( | |
381 | orig_url, video_id, | |
382 | note='Downloading webpage for description', | |
383 | fatal=False) | |
384 | if orig_webpage: | |
385 | video_description = self._html_search_meta( | |
386 | 'description', orig_webpage, default=None) | |
387 | if not video_description and not mobj.group('player'): | |
388 | self._downloader.report_warning('Cannot find video description') | |
b3d14cbf | 389 | |
69c8fb9e S |
390 | # Extract video duration |
391 | video_duration = int_or_none(config["video"].get("duration")) | |
392 | ||
b3d14cbf PH |
393 | # Extract upload date |
394 | video_upload_date = None | |
3c6f2450 | 395 | mobj = re.search(r'<time[^>]+datetime="([^"]+)"', webpage) |
b3d14cbf | 396 | if mobj is not None: |
3c6f2450 | 397 | video_upload_date = unified_strdate(mobj.group(1)) |
b3d14cbf | 398 | |
4e761794 | 399 | try: |
9148eb00 PH |
400 | view_count = int(self._search_regex(r'UserPlays:(\d+)', webpage, 'view count')) |
401 | like_count = int(self._search_regex(r'UserLikes:(\d+)', webpage, 'like count')) | |
402 | comment_count = int(self._search_regex(r'UserComments:(\d+)', webpage, 'comment count')) | |
4e761794 JMF |
403 | except RegexNotFoundError: |
404 | # This info is only available in vimeo.com/{id} urls | |
405 | view_count = None | |
406 | like_count = None | |
407 | comment_count = None | |
408 | ||
a6387bfd | 409 | formats = [] |
eb4f2740 | 410 | download_request = sanitized_Request('https://vimeo.com/%s?action=load_download_config' % video_id, headers={ |
411 | 'X-Requested-With': 'XMLHttpRequest'}) | |
412 | download_data = self._download_json(download_request, video_id, fatal=False) | |
413 | if download_data: | |
414 | source_file = download_data.get('source_file') | |
415 | if source_file and not source_file.get('is_cold') and not source_file.get('is_defrosting'): | |
416 | formats.append({ | |
417 | 'url': source_file['download_url'], | |
418 | 'ext': source_file['extension'].lower(), | |
419 | 'width': int_or_none(source_file.get('width')), | |
420 | 'height': int_or_none(source_file.get('height')), | |
421 | 'filesize': parse_filesize(source_file.get('size')), | |
422 | 'format_id': source_file.get('public_name', 'Original'), | |
8534bf1f | 423 | 'preference': 1, |
eb4f2740 | 424 | }) |
fcd817a3 S |
425 | config_files = config['video'].get('files') or config['request'].get('files', {}) |
426 | for f in config_files.get('progressive', []): | |
427 | video_url = f.get('url') | |
428 | if not video_url: | |
429 | continue | |
430 | formats.append({ | |
431 | 'url': video_url, | |
432 | 'format_id': 'http-%s' % f.get('quality'), | |
433 | 'width': int_or_none(f.get('width')), | |
434 | 'height': int_or_none(f.get('height')), | |
435 | 'fps': int_or_none(f.get('fps')), | |
436 | 'tbr': int_or_none(f.get('bitrate')), | |
437 | }) | |
438 | m3u8_url = config_files.get('hls', {}).get('url') | |
35a3ff1d | 439 | if m3u8_url: |
da4daed5 | 440 | m3u8_formats = self._extract_m3u8_formats( |
8534bf1f | 441 | m3u8_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False) |
da4daed5 | 442 | if m3u8_formats: |
73e732eb | 443 | formats.extend(m3u8_formats) |
fcd817a3 S |
444 | # Bitrates are completely broken. Single m3u8 may contain entries in kbps and bps |
445 | # at the same time without actual units specified. This lead to wrong sorting. | |
8534bf1f | 446 | self._sort_formats(formats, field_preference=('preference', 'height', 'width', 'fps', 'format_id')) |
b3d14cbf | 447 | |
1eac553e S |
448 | subtitles = {} |
449 | text_tracks = config['request'].get('text_tracks') | |
450 | if text_tracks: | |
451 | for tt in text_tracks: | |
65469a7f JMF |
452 | subtitles[tt['lang']] = [{ |
453 | 'ext': 'vtt', | |
3946864c | 454 | 'url': 'https://vimeo.com' + tt['url'], |
65469a7f | 455 | }] |
1eac553e | 456 | |
9103bbc5 | 457 | return { |
b0268cb6 | 458 | 'id': video_id, |
b3d14cbf PH |
459 | 'uploader': video_uploader, |
460 | 'uploader_id': video_uploader_id, | |
b0268cb6 S |
461 | 'upload_date': video_upload_date, |
462 | 'title': video_title, | |
463 | 'thumbnail': video_thumbnail, | |
464 | 'description': video_description, | |
69c8fb9e | 465 | 'duration': video_duration, |
a6387bfd | 466 | 'formats': formats, |
9103bbc5 | 467 | 'webpage_url': url, |
4e761794 JMF |
468 | 'view_count': view_count, |
469 | 'like_count': like_count, | |
470 | 'comment_count': comment_count, | |
65469a7f | 471 | 'subtitles': subtitles, |
9103bbc5 | 472 | } |
caeefc29 JMF |
473 | |
474 | ||
f6c3664d | 475 | class VimeoChannelIE(VimeoBaseInfoExtractor): |
9148eb00 | 476 | IE_NAME = 'vimeo:channel' |
3946864c | 477 | _VALID_URL = r'https://vimeo\.com/channels/(?P<id>[^/?#]+)/?(?:$|[?#])' |
caeefc29 | 478 | _MORE_PAGES_INDICATOR = r'<a.+?rel="next"' |
84458766 | 479 | _TITLE = None |
55a10eab | 480 | _TITLE_RE = r'<link rel="alternate"[^>]+?title="(.*?)"' |
2929b3e7 | 481 | _TESTS = [{ |
3946864c | 482 | 'url': 'https://vimeo.com/channels/tributes', |
2929b3e7 | 483 | 'info_dict': { |
a3fa5da4 | 484 | 'id': 'tributes', |
2929b3e7 PH |
485 | 'title': 'Vimeo Tributes', |
486 | }, | |
487 | 'playlist_mincount': 25, | |
488 | }] | |
caeefc29 | 489 | |
5cc14c2f JMF |
490 | def _page_url(self, base_url, pagenum): |
491 | return '%s/videos/page:%d/' % (base_url, pagenum) | |
492 | ||
fb30ec22 | 493 | def _extract_list_title(self, webpage): |
84458766 | 494 | return self._TITLE or self._html_search_regex(self._TITLE_RE, webpage, 'list title') |
fb30ec22 | 495 | |
bf8f082a PH |
496 | def _login_list_password(self, page_url, list_id, webpage): |
497 | login_form = self._search_regex( | |
498 | r'(?s)<form[^>]+?id="pw_form"(.*?)</form>', | |
499 | webpage, 'login form', default=None) | |
500 | if not login_form: | |
501 | return webpage | |
502 | ||
503 | password = self._downloader.params.get('videopassword', None) | |
504 | if password is None: | |
505 | raise ExtractorError('This album is protected by a password, use the --video-password option', expected=True) | |
f8da79f8 | 506 | fields = self._hidden_inputs(login_form) |
7c845629 | 507 | token, vuid = self._extract_xsrft_and_vuid(webpage) |
bf8f082a PH |
508 | fields['token'] = token |
509 | fields['password'] = password | |
bfdf891f | 510 | post = urlencode_postdata(encode_dict(fields)) |
bf8f082a PH |
511 | password_path = self._search_regex( |
512 | r'action="([^"]+)"', login_form, 'password URL') | |
513 | password_url = compat_urlparse.urljoin(page_url, password_path) | |
67dda517 | 514 | password_request = sanitized_Request(password_url, post) |
bf8f082a | 515 | password_request.add_header('Content-type', 'application/x-www-form-urlencoded') |
9eab37dc S |
516 | self._set_vimeo_cookie('vuid', vuid) |
517 | self._set_vimeo_cookie('xsrft', token) | |
bf8f082a PH |
518 | |
519 | return self._download_webpage( | |
520 | password_request, list_id, | |
521 | 'Verifying the password', 'Wrong password') | |
522 | ||
2c94198e | 523 | def _title_and_entries(self, list_id, base_url): |
caeefc29 | 524 | for pagenum in itertools.count(1): |
bf8f082a | 525 | page_url = self._page_url(base_url, pagenum) |
55a10eab | 526 | webpage = self._download_webpage( |
bf8f082a | 527 | page_url, list_id, |
9148eb00 | 528 | 'Downloading page %s' % pagenum) |
bf8f082a PH |
529 | |
530 | if pagenum == 1: | |
531 | webpage = self._login_list_password(page_url, list_id, webpage) | |
2c94198e S |
532 | yield self._extract_list_title(webpage) |
533 | ||
534 | for video_id in re.findall(r'id="clip_(\d+?)"', webpage): | |
535 | yield self.url_result('https://vimeo.com/%s' % video_id, 'Vimeo') | |
bf8f082a | 536 | |
caeefc29 JMF |
537 | if re.search(self._MORE_PAGES_INDICATOR, webpage, re.DOTALL) is None: |
538 | break | |
539 | ||
2c94198e S |
540 | def _extract_videos(self, list_id, base_url): |
541 | title_and_entries = self._title_and_entries(list_id, base_url) | |
542 | list_title = next(title_and_entries) | |
543 | return self.playlist_result(title_and_entries, list_id, list_title) | |
55a10eab JMF |
544 | |
545 | def _real_extract(self, url): | |
546 | mobj = re.match(self._VALID_URL, url) | |
4f3e9430 | 547 | channel_id = mobj.group('id') |
3946864c | 548 | return self._extract_videos(channel_id, 'https://vimeo.com/channels/%s' % channel_id) |
55a10eab JMF |
549 | |
550 | ||
551 | class VimeoUserIE(VimeoChannelIE): | |
9148eb00 | 552 | IE_NAME = 'vimeo:user' |
b29440ae | 553 | _VALID_URL = r'https://vimeo\.com/(?!(?:[0-9]+|watchlater)(?:$|[?#/]))(?P<name>[^/]+)(?:/videos|[#?]|$)' |
55a10eab | 554 | _TITLE_RE = r'<a[^>]+?class="user">([^<>]+?)</a>' |
2929b3e7 | 555 | _TESTS = [{ |
3946864c | 556 | 'url': 'https://vimeo.com/nkistudio/videos', |
2929b3e7 PH |
557 | 'info_dict': { |
558 | 'title': 'Nki', | |
a3fa5da4 | 559 | 'id': 'nkistudio', |
2929b3e7 PH |
560 | }, |
561 | 'playlist_mincount': 66, | |
562 | }] | |
55a10eab JMF |
563 | |
564 | def _real_extract(self, url): | |
565 | mobj = re.match(self._VALID_URL, url) | |
566 | name = mobj.group('name') | |
3946864c | 567 | return self._extract_videos(name, 'https://vimeo.com/%s' % name) |
5cc14c2f JMF |
568 | |
569 | ||
570 | class VimeoAlbumIE(VimeoChannelIE): | |
9148eb00 | 571 | IE_NAME = 'vimeo:album' |
d1508cd6 | 572 | _VALID_URL = r'https://vimeo\.com/album/(?P<id>\d+)' |
5cc14c2f | 573 | _TITLE_RE = r'<header id="page_header">\n\s*<h1>(.*?)</h1>' |
2929b3e7 | 574 | _TESTS = [{ |
d1508cd6 | 575 | 'url': 'https://vimeo.com/album/2632481', |
2929b3e7 | 576 | 'info_dict': { |
a3fa5da4 | 577 | 'id': '2632481', |
2929b3e7 PH |
578 | 'title': 'Staff Favorites: November 2013', |
579 | }, | |
580 | 'playlist_mincount': 13, | |
bf8f082a PH |
581 | }, { |
582 | 'note': 'Password-protected album', | |
583 | 'url': 'https://vimeo.com/album/3253534', | |
584 | 'info_dict': { | |
585 | 'title': 'test', | |
586 | 'id': '3253534', | |
587 | }, | |
588 | 'playlist_count': 1, | |
589 | 'params': { | |
590 | 'videopassword': 'youtube-dl', | |
591 | } | |
2929b3e7 | 592 | }] |
5cc14c2f JMF |
593 | |
594 | def _page_url(self, base_url, pagenum): | |
595 | return '%s/page:%d/' % (base_url, pagenum) | |
596 | ||
597 | def _real_extract(self, url): | |
bf8f082a | 598 | album_id = self._match_id(url) |
d1508cd6 | 599 | return self._extract_videos(album_id, 'https://vimeo.com/album/%s' % album_id) |
fb30ec22 JMF |
600 | |
601 | ||
602 | class VimeoGroupsIE(VimeoAlbumIE): | |
9148eb00 | 603 | IE_NAME = 'vimeo:group' |
fdb20a27 | 604 | _VALID_URL = r'https://vimeo\.com/groups/(?P<name>[^/]+)(?:/(?!videos?/\d+)|$)' |
2929b3e7 | 605 | _TESTS = [{ |
3946864c | 606 | 'url': 'https://vimeo.com/groups/rolexawards', |
2929b3e7 | 607 | 'info_dict': { |
a3fa5da4 | 608 | 'id': 'rolexawards', |
2929b3e7 PH |
609 | 'title': 'Rolex Awards for Enterprise', |
610 | }, | |
611 | 'playlist_mincount': 73, | |
612 | }] | |
fb30ec22 JMF |
613 | |
614 | def _extract_list_title(self, webpage): | |
615 | return self._og_search_title(webpage) | |
616 | ||
617 | def _real_extract(self, url): | |
618 | mobj = re.match(self._VALID_URL, url) | |
619 | name = mobj.group('name') | |
3946864c | 620 | return self._extract_videos(name, 'https://vimeo.com/groups/%s' % name) |
fcea44c6 PH |
621 | |
622 | ||
623 | class VimeoReviewIE(InfoExtractor): | |
9148eb00 PH |
624 | IE_NAME = 'vimeo:review' |
625 | IE_DESC = 'Review pages on vimeo' | |
3946864c | 626 | _VALID_URL = r'https://vimeo\.com/[^/]+/review/(?P<id>[^/]+)' |
d36d3f42 | 627 | _TESTS = [{ |
fcea44c6 | 628 | 'url': 'https://vimeo.com/user21297594/review/75524534/3c257a1b5d', |
fcea44c6 PH |
629 | 'md5': 'c507a72f780cacc12b2248bb4006d253', |
630 | 'info_dict': { | |
fc09240e PH |
631 | 'id': '75524534', |
632 | 'ext': 'mp4', | |
fcea44c6 PH |
633 | 'title': "DICK HARDWICK 'Comedian'", |
634 | 'uploader': 'Richard Hardwick', | |
635 | } | |
d36d3f42 PH |
636 | }, { |
637 | 'note': 'video player needs Referer', | |
3946864c | 638 | 'url': 'https://vimeo.com/user22258446/review/91613211/13f927e053', |
d36d3f42 PH |
639 | 'md5': '6295fdab8f4bf6a002d058b2c6dce276', |
640 | 'info_dict': { | |
641 | 'id': '91613211', | |
642 | 'ext': 'mp4', | |
9dec9930 | 643 | 'title': 're:(?i)^Death by dogma versus assembling agile . Sander Hoogendoorn', |
d36d3f42 PH |
644 | 'uploader': 'DevWeek Events', |
645 | 'duration': 2773, | |
646 | 'thumbnail': 're:^https?://.*\.jpg$', | |
647 | } | |
648 | }] | |
fcea44c6 PH |
649 | |
650 | def _real_extract(self, url): | |
651 | mobj = re.match(self._VALID_URL, url) | |
652 | video_id = mobj.group('id') | |
653 | player_url = 'https://player.vimeo.com/player/' + video_id | |
654 | return self.url_result(player_url, 'Vimeo', video_id) | |
efb7e119 JMF |
655 | |
656 | ||
f6c3664d | 657 | class VimeoWatchLaterIE(VimeoChannelIE): |
efb7e119 JMF |
658 | IE_NAME = 'vimeo:watchlater' |
659 | IE_DESC = 'Vimeo watch later list, "vimeowatchlater" keyword (requires authentication)' | |
84458766 S |
660 | _VALID_URL = r'https://vimeo\.com/(?:home/)?watchlater|:vimeowatchlater' |
661 | _TITLE = 'Watch Later' | |
efb7e119 | 662 | _LOGIN_REQUIRED = True |
2929b3e7 | 663 | _TESTS = [{ |
84458766 | 664 | 'url': 'https://vimeo.com/watchlater', |
2929b3e7 PH |
665 | 'only_matching': True, |
666 | }] | |
efb7e119 JMF |
667 | |
668 | def _real_initialize(self): | |
669 | self._login() | |
670 | ||
671 | def _page_url(self, base_url, pagenum): | |
672 | url = '%s/page:%d/' % (base_url, pagenum) | |
67dda517 | 673 | request = sanitized_Request(url) |
efb7e119 JMF |
674 | # Set the header to get a partial html page with the ids, |
675 | # the normal page doesn't contain them. | |
676 | request.add_header('X-Requested-With', 'XMLHttpRequest') | |
677 | return request | |
678 | ||
679 | def _real_extract(self, url): | |
84458766 | 680 | return self._extract_videos('watchlater', 'https://vimeo.com/watchlater') |
d6e6a422 PH |
681 | |
682 | ||
683 | class VimeoLikesIE(InfoExtractor): | |
3946864c | 684 | _VALID_URL = r'https://(?:www\.)?vimeo\.com/user(?P<id>[0-9]+)/likes/?(?:$|[?#]|sort:)' |
d6e6a422 PH |
685 | IE_NAME = 'vimeo:likes' |
686 | IE_DESC = 'Vimeo user likes' | |
687 | _TEST = { | |
9c44d242 PH |
688 | 'url': 'https://vimeo.com/user755559/likes/', |
689 | 'playlist_mincount': 293, | |
d6e6a422 | 690 | "info_dict": { |
a3fa5da4 | 691 | 'id': 'user755559_likes', |
9c44d242 PH |
692 | "description": "See all the videos urza likes", |
693 | "title": 'Videos urza likes', | |
d6e6a422 PH |
694 | }, |
695 | } | |
696 | ||
697 | def _real_extract(self, url): | |
698 | user_id = self._match_id(url) | |
9c44d242 PH |
699 | webpage = self._download_webpage(url, user_id) |
700 | page_count = self._int( | |
701 | self._search_regex( | |
702 | r'''(?x)<li><a\s+href="[^"]+"\s+data-page="([0-9]+)"> | |
703 | .*?</a></li>\s*<li\s+class="pagination_next"> | |
704 | ''', webpage, 'page count'), | |
705 | 'page count', fatal=True) | |
706 | PAGE_SIZE = 12 | |
707 | title = self._html_search_regex( | |
708 | r'(?s)<h1>(.+?)</h1>', webpage, 'title', fatal=False) | |
709 | description = self._html_search_meta('description', webpage) | |
710 | ||
711 | def _get_page(idx): | |
3946864c JMF |
712 | page_url = 'https://vimeo.com/user%s/likes/page:%d/sort:date' % ( |
713 | user_id, idx + 1) | |
9c44d242 PH |
714 | webpage = self._download_webpage( |
715 | page_url, user_id, | |
716 | note='Downloading page %d/%d' % (idx + 1, page_count)) | |
717 | video_list = self._search_regex( | |
718 | r'(?s)<ol class="js-browse_list[^"]+"[^>]*>(.*?)</ol>', | |
719 | webpage, 'video content') | |
720 | paths = re.findall( | |
721 | r'<li[^>]*>\s*<a\s+href="([^"]+)"', video_list) | |
722 | for path in paths: | |
723 | yield { | |
724 | '_type': 'url', | |
725 | 'url': compat_urlparse.urljoin(page_url, path), | |
726 | } | |
727 | ||
728 | pl = InAdvancePagedList(_get_page, page_count, PAGE_SIZE) | |
d6e6a422 PH |
729 | |
730 | return { | |
9c44d242 PH |
731 | '_type': 'playlist', |
732 | 'id': 'user%s_likes' % user_id, | |
733 | 'title': title, | |
734 | 'description': description, | |
735 | 'entries': pl, | |
d6e6a422 | 736 | } |