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.

736 lines
29 KiB

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