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.

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