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