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