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