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