You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

752 lines
30 KiB

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