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.

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