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.

940 lines
38 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 _smuggle_referrer(url, referrer_url):
  335. return smuggle_url(url, {'http_headers': {'Referer': referrer_url}})
  336. @staticmethod
  337. def _extract_vimeo_url(url, webpage):
  338. # Look for embedded (iframe) Vimeo player
  339. mobj = re.search(
  340. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/.+?)\1', webpage)
  341. if mobj:
  342. player_url = unescapeHTML(mobj.group('url'))
  343. return VimeoIE._smuggle_referrer(player_url, url)
  344. # Look for embedded (swf embed) Vimeo player
  345. mobj = re.search(
  346. r'<embed[^>]+?src="((?:https?:)?//(?:www\.)?vimeo\.com/moogaloop\.swf.+?)"', webpage)
  347. if mobj:
  348. return mobj.group(1)
  349. # Look more for non-standard embedded Vimeo player
  350. mobj = re.search(
  351. r'<video[^>]+src=(?P<q1>[\'"])(?P<url>(?:https?:)?//(?:www\.)?vimeo\.com/[0-9]+)(?P=q1)', webpage)
  352. if mobj:
  353. return mobj.group('url')
  354. def _verify_player_video_password(self, url, video_id):
  355. password = self._downloader.params.get('videopassword')
  356. if password is None:
  357. raise ExtractorError('This video is protected by a password, use the --video-password option')
  358. data = urlencode_postdata({'password': password})
  359. pass_url = url + '/check-password'
  360. password_request = sanitized_Request(pass_url, data)
  361. password_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  362. password_request.add_header('Referer', url)
  363. return self._download_json(
  364. password_request, video_id,
  365. 'Verifying the password', 'Wrong password')
  366. def _real_initialize(self):
  367. self._login()
  368. def _real_extract(self, url):
  369. url, data = unsmuggle_url(url, {})
  370. headers = std_headers.copy()
  371. if 'http_headers' in data:
  372. headers.update(data['http_headers'])
  373. if 'Referer' not in headers:
  374. headers['Referer'] = url
  375. # Extract ID from URL
  376. mobj = re.match(self._VALID_URL, url)
  377. video_id = mobj.group('id')
  378. orig_url = url
  379. if mobj.group('pro') or mobj.group('player'):
  380. url = 'https://player.vimeo.com/video/' + video_id
  381. elif any(p in url for p in ('play_redirect_hls', 'moogaloop.swf')):
  382. url = 'https://vimeo.com/' + video_id
  383. # Retrieve video webpage to extract further information
  384. request = sanitized_Request(url, headers=headers)
  385. try:
  386. webpage = self._download_webpage(request, video_id)
  387. except ExtractorError as ee:
  388. if isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 403:
  389. errmsg = ee.cause.read()
  390. if b'Because of its privacy settings, this video cannot be played here' in errmsg:
  391. raise ExtractorError(
  392. 'Cannot download embed-only video without embedding '
  393. 'URL. Please call youtube-dl with the URL of the page '
  394. 'that embeds this video.',
  395. expected=True)
  396. raise
  397. # Now we begin extracting as much information as we can from what we
  398. # retrieved. First we extract the information common to all extractors,
  399. # and latter we extract those that are Vimeo specific.
  400. self.report_extraction(video_id)
  401. vimeo_config = self._search_regex(
  402. r'vimeo\.config\s*=\s*(?:({.+?})|_extend\([^,]+,\s+({.+?})\));', webpage,
  403. 'vimeo config', default=None)
  404. if vimeo_config:
  405. seed_status = self._parse_json(vimeo_config, video_id).get('seed_status', {})
  406. if seed_status.get('state') == 'failed':
  407. raise ExtractorError(
  408. '%s said: %s' % (self.IE_NAME, seed_status['title']),
  409. expected=True)
  410. # Extract the config JSON
  411. try:
  412. try:
  413. config_url = self._html_search_regex(
  414. r' data-config-url="(.+?)"', webpage,
  415. 'config URL', default=None)
  416. if not config_url:
  417. # Sometimes new react-based page is served instead of old one that require
  418. # different config URL extraction approach (see
  419. # https://github.com/rg3/youtube-dl/pull/7209)
  420. vimeo_clip_page_config = self._search_regex(
  421. r'vimeo\.clip_page_config\s*=\s*({.+?});', webpage,
  422. 'vimeo clip page config')
  423. config_url = self._parse_json(
  424. vimeo_clip_page_config, video_id)['player']['config_url']
  425. config_json = self._download_webpage(config_url, video_id)
  426. config = json.loads(config_json)
  427. except RegexNotFoundError:
  428. # For pro videos or player.vimeo.com urls
  429. # We try to find out to which variable is assigned the config dic
  430. m_variable_name = re.search('(\w)\.video\.id', webpage)
  431. if m_variable_name is not None:
  432. config_re = r'%s=({[^}].+?});' % re.escape(m_variable_name.group(1))
  433. else:
  434. config_re = [r' = {config:({.+?}),assets:', r'(?:[abc])=({.+?});']
  435. config = self._search_regex(config_re, webpage, 'info section',
  436. flags=re.DOTALL)
  437. config = json.loads(config)
  438. except Exception as e:
  439. if re.search('The creator of this video has not given you permission to embed it on this domain.', webpage):
  440. raise ExtractorError('The author has restricted the access to this video, try with the "--referer" option')
  441. if re.search(r'<form[^>]+?id="pw_form"', webpage) is not None:
  442. if '_video_password_verified' in data:
  443. raise ExtractorError('video password verification failed!')
  444. self._verify_video_password(url, video_id, webpage)
  445. return self._real_extract(
  446. smuggle_url(url, {'_video_password_verified': 'verified'}))
  447. else:
  448. raise ExtractorError('Unable to extract info section',
  449. cause=e)
  450. else:
  451. if config.get('view') == 4:
  452. config = self._verify_player_video_password(url, video_id)
  453. def is_rented():
  454. if '>You rented this title.<' in webpage:
  455. return True
  456. if config.get('user', {}).get('purchased'):
  457. return True
  458. label = try_get(
  459. config, lambda x: x['video']['vod']['purchase_options'][0]['label_string'], compat_str)
  460. if label and label.startswith('You rented this'):
  461. return True
  462. return False
  463. if is_rented():
  464. feature_id = config.get('video', {}).get('vod', {}).get('feature_id')
  465. if feature_id and not data.get('force_feature_id', False):
  466. return self.url_result(smuggle_url(
  467. 'https://player.vimeo.com/player/%s' % feature_id,
  468. {'force_feature_id': True}), 'Vimeo')
  469. # Extract video description
  470. video_description = self._html_search_regex(
  471. r'(?s)<div\s+class="[^"]*description[^"]*"[^>]*>(.*?)</div>',
  472. webpage, 'description', default=None)
  473. if not video_description:
  474. video_description = self._html_search_meta(
  475. 'description', webpage, default=None)
  476. if not video_description and mobj.group('pro'):
  477. orig_webpage = self._download_webpage(
  478. orig_url, video_id,
  479. note='Downloading webpage for description',
  480. fatal=False)
  481. if orig_webpage:
  482. video_description = self._html_search_meta(
  483. 'description', orig_webpage, default=None)
  484. if not video_description and not mobj.group('player'):
  485. self._downloader.report_warning('Cannot find video description')
  486. # Extract upload date
  487. video_upload_date = None
  488. mobj = re.search(r'<time[^>]+datetime="([^"]+)"', webpage)
  489. if mobj is not None:
  490. video_upload_date = unified_strdate(mobj.group(1))
  491. try:
  492. view_count = int(self._search_regex(r'UserPlays:(\d+)', webpage, 'view count'))
  493. like_count = int(self._search_regex(r'UserLikes:(\d+)', webpage, 'like count'))
  494. comment_count = int(self._search_regex(r'UserComments:(\d+)', webpage, 'comment count'))
  495. except RegexNotFoundError:
  496. # This info is only available in vimeo.com/{id} urls
  497. view_count = None
  498. like_count = None
  499. comment_count = None
  500. formats = []
  501. download_request = sanitized_Request('https://vimeo.com/%s?action=load_download_config' % video_id, headers={
  502. 'X-Requested-With': 'XMLHttpRequest'})
  503. download_data = self._download_json(download_request, video_id, fatal=False)
  504. if download_data:
  505. source_file = download_data.get('source_file')
  506. if isinstance(source_file, dict):
  507. download_url = source_file.get('download_url')
  508. if download_url and not source_file.get('is_cold') and not source_file.get('is_defrosting'):
  509. source_name = source_file.get('public_name', 'Original')
  510. if self._is_valid_url(download_url, video_id, '%s video' % source_name):
  511. ext = source_file.get('extension', determine_ext(download_url)).lower()
  512. formats.append({
  513. 'url': download_url,
  514. 'ext': ext,
  515. 'width': int_or_none(source_file.get('width')),
  516. 'height': int_or_none(source_file.get('height')),
  517. 'filesize': parse_filesize(source_file.get('size')),
  518. 'format_id': source_name,
  519. 'preference': 1,
  520. })
  521. info_dict = self._parse_config(config, video_id)
  522. formats.extend(info_dict['formats'])
  523. self._vimeo_sort_formats(formats)
  524. info_dict.update({
  525. 'id': video_id,
  526. 'formats': formats,
  527. 'upload_date': video_upload_date,
  528. 'description': video_description,
  529. 'webpage_url': url,
  530. 'view_count': view_count,
  531. 'like_count': like_count,
  532. 'comment_count': comment_count,
  533. })
  534. return info_dict
  535. class VimeoOndemandIE(VimeoBaseInfoExtractor):
  536. IE_NAME = 'vimeo:ondemand'
  537. _VALID_URL = r'https?://(?:www\.)?vimeo\.com/ondemand/(?P<id>[^/?#&]+)'
  538. _TESTS = [{
  539. # ondemand video not available via https://vimeo.com/id
  540. 'url': 'https://vimeo.com/ondemand/20704',
  541. 'md5': 'c424deda8c7f73c1dfb3edd7630e2f35',
  542. 'info_dict': {
  543. 'id': '105442900',
  544. 'ext': 'mp4',
  545. 'title': 'המעבדה - במאי יותם פלדמן',
  546. 'uploader': 'גם סרטים',
  547. 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/gumfilms',
  548. 'uploader_id': 'gumfilms',
  549. },
  550. }, {
  551. # requires Referer to be passed along with og:video:url
  552. 'url': 'https://vimeo.com/ondemand/36938/126682985',
  553. 'info_dict': {
  554. 'id': '126682985',
  555. 'ext': 'mp4',
  556. 'title': 'Rävlock, rätt läte på rätt plats',
  557. 'uploader': 'Lindroth & Norin',
  558. 'uploader_url': 're:https?://(?:www\.)?vimeo\.com/user14430847',
  559. 'uploader_id': 'user14430847',
  560. },
  561. 'params': {
  562. 'skip_download': True,
  563. },
  564. }, {
  565. 'url': 'https://vimeo.com/ondemand/nazmaalik',
  566. 'only_matching': True,
  567. }, {
  568. 'url': 'https://vimeo.com/ondemand/141692381',
  569. 'only_matching': True,
  570. }, {
  571. 'url': 'https://vimeo.com/ondemand/thelastcolony/150274832',
  572. 'only_matching': True,
  573. }]
  574. def _real_extract(self, url):
  575. video_id = self._match_id(url)
  576. webpage = self._download_webpage(url, video_id)
  577. return self.url_result(
  578. # Some videos require Referer to be passed along with og:video:url
  579. # similarly to generic vimeo embeds (e.g.
  580. # https://vimeo.com/ondemand/36938/126682985).
  581. VimeoIE._smuggle_referrer(self._og_search_video_url(webpage), url),
  582. VimeoIE.ie_key())
  583. class VimeoChannelIE(VimeoBaseInfoExtractor):
  584. IE_NAME = 'vimeo:channel'
  585. _VALID_URL = r'https://vimeo\.com/channels/(?P<id>[^/?#]+)/?(?:$|[?#])'
  586. _MORE_PAGES_INDICATOR = r'<a.+?rel="next"'
  587. _TITLE = None
  588. _TITLE_RE = r'<link rel="alternate"[^>]+?title="(.*?)"'
  589. _TESTS = [{
  590. 'url': 'https://vimeo.com/channels/tributes',
  591. 'info_dict': {
  592. 'id': 'tributes',
  593. 'title': 'Vimeo Tributes',
  594. },
  595. 'playlist_mincount': 25,
  596. }]
  597. def _page_url(self, base_url, pagenum):
  598. return '%s/videos/page:%d/' % (base_url, pagenum)
  599. def _extract_list_title(self, webpage):
  600. return self._TITLE or self._html_search_regex(self._TITLE_RE, webpage, 'list title')
  601. def _login_list_password(self, page_url, list_id, webpage):
  602. login_form = self._search_regex(
  603. r'(?s)<form[^>]+?id="pw_form"(.*?)</form>',
  604. webpage, 'login form', default=None)
  605. if not login_form:
  606. return webpage
  607. password = self._downloader.params.get('videopassword')
  608. if password is None:
  609. raise ExtractorError('This album is protected by a password, use the --video-password option', expected=True)
  610. fields = self._hidden_inputs(login_form)
  611. token, vuid = self._extract_xsrft_and_vuid(webpage)
  612. fields['token'] = token
  613. fields['password'] = password
  614. post = urlencode_postdata(fields)
  615. password_path = self._search_regex(
  616. r'action="([^"]+)"', login_form, 'password URL')
  617. password_url = compat_urlparse.urljoin(page_url, password_path)
  618. password_request = sanitized_Request(password_url, post)
  619. password_request.add_header('Content-type', 'application/x-www-form-urlencoded')
  620. self._set_vimeo_cookie('vuid', vuid)
  621. self._set_vimeo_cookie('xsrft', token)
  622. return self._download_webpage(
  623. password_request, list_id,
  624. 'Verifying the password', 'Wrong password')
  625. def _title_and_entries(self, list_id, base_url):
  626. for pagenum in itertools.count(1):
  627. page_url = self._page_url(base_url, pagenum)
  628. webpage = self._download_webpage(
  629. page_url, list_id,
  630. 'Downloading page %s' % pagenum)
  631. if pagenum == 1:
  632. webpage = self._login_list_password(page_url, list_id, webpage)
  633. yield self._extract_list_title(webpage)
  634. # Try extracting href first since not all videos are available via
  635. # short https://vimeo.com/id URL (e.g. https://vimeo.com/channels/tributes/6213729)
  636. clips = re.findall(
  637. r'id="clip_(\d+)"[^>]*>\s*<a[^>]+href="(/(?:[^/]+/)*\1)', webpage)
  638. if clips:
  639. for video_id, video_url in clips:
  640. yield self.url_result(
  641. compat_urlparse.urljoin(base_url, video_url),
  642. VimeoIE.ie_key(), video_id=video_id)
  643. # More relaxed fallback
  644. else:
  645. for video_id in re.findall(r'id=["\']clip_(\d+)', webpage):
  646. yield self.url_result(
  647. 'https://vimeo.com/%s' % video_id,
  648. VimeoIE.ie_key(), video_id=video_id)
  649. if re.search(self._MORE_PAGES_INDICATOR, webpage, re.DOTALL) is None:
  650. break
  651. def _extract_videos(self, list_id, base_url):
  652. title_and_entries = self._title_and_entries(list_id, base_url)
  653. list_title = next(title_and_entries)
  654. return self.playlist_result(title_and_entries, list_id, list_title)
  655. def _real_extract(self, url):
  656. mobj = re.match(self._VALID_URL, url)
  657. channel_id = mobj.group('id')
  658. return self._extract_videos(channel_id, 'https://vimeo.com/channels/%s' % channel_id)
  659. class VimeoUserIE(VimeoChannelIE):
  660. IE_NAME = 'vimeo:user'
  661. _VALID_URL = r'https://vimeo\.com/(?!(?:[0-9]+|watchlater)(?:$|[?#/]))(?P<name>[^/]+)(?:/videos|[#?]|$)'
  662. _TITLE_RE = r'<a[^>]+?class="user">([^<>]+?)</a>'
  663. _TESTS = [{
  664. 'url': 'https://vimeo.com/nkistudio/videos',
  665. 'info_dict': {
  666. 'title': 'Nki',
  667. 'id': 'nkistudio',
  668. },
  669. 'playlist_mincount': 66,
  670. }]
  671. def _real_extract(self, url):
  672. mobj = re.match(self._VALID_URL, url)
  673. name = mobj.group('name')
  674. return self._extract_videos(name, 'https://vimeo.com/%s' % name)
  675. class VimeoAlbumIE(VimeoChannelIE):
  676. IE_NAME = 'vimeo:album'
  677. _VALID_URL = r'https://vimeo\.com/album/(?P<id>\d+)(?:$|[?#]|/(?!video))'
  678. _TITLE_RE = r'<header id="page_header">\n\s*<h1>(.*?)</h1>'
  679. _TESTS = [{
  680. 'url': 'https://vimeo.com/album/2632481',
  681. 'info_dict': {
  682. 'id': '2632481',
  683. 'title': 'Staff Favorites: November 2013',
  684. },
  685. 'playlist_mincount': 13,
  686. }, {
  687. 'note': 'Password-protected album',
  688. 'url': 'https://vimeo.com/album/3253534',
  689. 'info_dict': {
  690. 'title': 'test',
  691. 'id': '3253534',
  692. },
  693. 'playlist_count': 1,
  694. 'params': {
  695. 'videopassword': 'youtube-dl',
  696. }
  697. }, {
  698. 'url': 'https://vimeo.com/album/2632481/sort:plays/format:thumbnail',
  699. 'only_matching': True,
  700. }, {
  701. # TODO: respect page number
  702. 'url': 'https://vimeo.com/album/2632481/page:2/sort:plays/format:thumbnail',
  703. 'only_matching': True,
  704. }]
  705. def _page_url(self, base_url, pagenum):
  706. return '%s/page:%d/' % (base_url, pagenum)
  707. def _real_extract(self, url):
  708. album_id = self._match_id(url)
  709. return self._extract_videos(album_id, 'https://vimeo.com/album/%s' % album_id)
  710. class VimeoGroupsIE(VimeoAlbumIE):
  711. IE_NAME = 'vimeo:group'
  712. _VALID_URL = r'https://vimeo\.com/groups/(?P<name>[^/]+)(?:/(?!videos?/\d+)|$)'
  713. _TESTS = [{
  714. 'url': 'https://vimeo.com/groups/rolexawards',
  715. 'info_dict': {
  716. 'id': 'rolexawards',
  717. 'title': 'Rolex Awards for Enterprise',
  718. },
  719. 'playlist_mincount': 73,
  720. }]
  721. def _extract_list_title(self, webpage):
  722. return self._og_search_title(webpage)
  723. def _real_extract(self, url):
  724. mobj = re.match(self._VALID_URL, url)
  725. name = mobj.group('name')
  726. return self._extract_videos(name, 'https://vimeo.com/groups/%s' % name)
  727. class VimeoReviewIE(VimeoBaseInfoExtractor):
  728. IE_NAME = 'vimeo:review'
  729. IE_DESC = 'Review pages on vimeo'
  730. _VALID_URL = r'https://vimeo\.com/[^/]+/review/(?P<id>[^/]+)'
  731. _TESTS = [{
  732. 'url': 'https://vimeo.com/user21297594/review/75524534/3c257a1b5d',
  733. 'md5': 'c507a72f780cacc12b2248bb4006d253',
  734. 'info_dict': {
  735. 'id': '75524534',
  736. 'ext': 'mp4',
  737. 'title': "DICK HARDWICK 'Comedian'",
  738. 'uploader': 'Richard Hardwick',
  739. 'uploader_id': 'user21297594',
  740. }
  741. }, {
  742. 'note': 'video player needs Referer',
  743. 'url': 'https://vimeo.com/user22258446/review/91613211/13f927e053',
  744. 'md5': '6295fdab8f4bf6a002d058b2c6dce276',
  745. 'info_dict': {
  746. 'id': '91613211',
  747. 'ext': 'mp4',
  748. 'title': 're:(?i)^Death by dogma versus assembling agile . Sander Hoogendoorn',
  749. 'uploader': 'DevWeek Events',
  750. 'duration': 2773,
  751. 'thumbnail': 're:^https?://.*\.jpg$',
  752. 'uploader_id': 'user22258446',
  753. }
  754. }, {
  755. 'note': 'Password protected',
  756. 'url': 'https://vimeo.com/user37284429/review/138823582/c4d865efde',
  757. 'info_dict': {
  758. 'id': '138823582',
  759. 'ext': 'mp4',
  760. 'title': 'EFFICIENT PICKUP MASTERCLASS MODULE 1',
  761. 'uploader': 'TMB',
  762. 'uploader_id': 'user37284429',
  763. },
  764. 'params': {
  765. 'videopassword': 'holygrail',
  766. },
  767. }]
  768. def _real_initialize(self):
  769. self._login()
  770. def _get_config_url(self, webpage_url, video_id, video_password_verified=False):
  771. webpage = self._download_webpage(webpage_url, video_id)
  772. config_url = self._html_search_regex(
  773. r'data-config-url="([^"]+)"', webpage, 'config URL',
  774. default=NO_DEFAULT if video_password_verified else None)
  775. if config_url is None:
  776. self._verify_video_password(webpage_url, video_id, webpage)
  777. config_url = self._get_config_url(
  778. webpage_url, video_id, video_password_verified=True)
  779. return config_url
  780. def _real_extract(self, url):
  781. video_id = self._match_id(url)
  782. config_url = self._get_config_url(url, video_id)
  783. config = self._download_json(config_url, video_id)
  784. info_dict = self._parse_config(config, video_id)
  785. self._vimeo_sort_formats(info_dict['formats'])
  786. info_dict['id'] = video_id
  787. return info_dict
  788. class VimeoWatchLaterIE(VimeoChannelIE):
  789. IE_NAME = 'vimeo:watchlater'
  790. IE_DESC = 'Vimeo watch later list, "vimeowatchlater" keyword (requires authentication)'
  791. _VALID_URL = r'https://vimeo\.com/(?:home/)?watchlater|:vimeowatchlater'
  792. _TITLE = 'Watch Later'
  793. _LOGIN_REQUIRED = True
  794. _TESTS = [{
  795. 'url': 'https://vimeo.com/watchlater',
  796. 'only_matching': True,
  797. }]
  798. def _real_initialize(self):
  799. self._login()
  800. def _page_url(self, base_url, pagenum):
  801. url = '%s/page:%d/' % (base_url, pagenum)
  802. request = sanitized_Request(url)
  803. # Set the header to get a partial html page with the ids,
  804. # the normal page doesn't contain them.
  805. request.add_header('X-Requested-With', 'XMLHttpRequest')
  806. return request
  807. def _real_extract(self, url):
  808. return self._extract_videos('watchlater', 'https://vimeo.com/watchlater')
  809. class VimeoLikesIE(InfoExtractor):
  810. _VALID_URL = r'https://(?:www\.)?vimeo\.com/user(?P<id>[0-9]+)/likes/?(?:$|[?#]|sort:)'
  811. IE_NAME = 'vimeo:likes'
  812. IE_DESC = 'Vimeo user likes'
  813. _TEST = {
  814. 'url': 'https://vimeo.com/user755559/likes/',
  815. 'playlist_mincount': 293,
  816. 'info_dict': {
  817. 'id': 'user755559_likes',
  818. 'description': 'See all the videos urza likes',
  819. 'title': 'Videos urza likes',
  820. },
  821. }
  822. def _real_extract(self, url):
  823. user_id = self._match_id(url)
  824. webpage = self._download_webpage(url, user_id)
  825. page_count = self._int(
  826. self._search_regex(
  827. r'''(?x)<li><a\s+href="[^"]+"\s+data-page="([0-9]+)">
  828. .*?</a></li>\s*<li\s+class="pagination_next">
  829. ''', webpage, 'page count'),
  830. 'page count', fatal=True)
  831. PAGE_SIZE = 12
  832. title = self._html_search_regex(
  833. r'(?s)<h1>(.+?)</h1>', webpage, 'title', fatal=False)
  834. description = self._html_search_meta('description', webpage)
  835. def _get_page(idx):
  836. page_url = 'https://vimeo.com/user%s/likes/page:%d/sort:date' % (
  837. user_id, idx + 1)
  838. webpage = self._download_webpage(
  839. page_url, user_id,
  840. note='Downloading page %d/%d' % (idx + 1, page_count))
  841. video_list = self._search_regex(
  842. r'(?s)<ol class="js-browse_list[^"]+"[^>]*>(.*?)</ol>',
  843. webpage, 'video content')
  844. paths = re.findall(
  845. r'<li[^>]*>\s*<a\s+href="([^"]+)"', video_list)
  846. for path in paths:
  847. yield {
  848. '_type': 'url',
  849. 'url': compat_urlparse.urljoin(page_url, path),
  850. }
  851. pl = InAdvancePagedList(_get_page, page_count, PAGE_SIZE)
  852. return {
  853. '_type': 'playlist',
  854. 'id': 'user%s_likes' % user_id,
  855. 'title': title,
  856. 'description': description,
  857. 'entries': pl,
  858. }