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.

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