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.

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