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.

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