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.

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