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.

673 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[\s=:"\']+([^"\']+)', 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. else:
  214. url = 'https://vimeo.com/' + video_id
  215. # Retrieve video webpage to extract further information
  216. request = compat_urllib_request.Request(url, None, headers)
  217. try:
  218. webpage = self._download_webpage(request, video_id)
  219. except ExtractorError as ee:
  220. if isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 403:
  221. errmsg = ee.cause.read()
  222. if b'Because of its privacy settings, this video cannot be played here' in errmsg:
  223. raise ExtractorError(
  224. 'Cannot download embed-only video without embedding '
  225. 'URL. Please call youtube-dl with the URL of the page '
  226. 'that embeds this video.',
  227. expected=True)
  228. raise
  229. # Now we begin extracting as much information as we can from what we
  230. # retrieved. First we extract the information common to all extractors,
  231. # and latter we extract those that are Vimeo specific.
  232. self.report_extraction(video_id)
  233. vimeo_config = self._search_regex(
  234. r'vimeo\.config\s*=\s*({.+?});', webpage,
  235. 'vimeo config', default=None)
  236. if vimeo_config:
  237. seed_status = self._parse_json(vimeo_config, video_id).get('seed_status', {})
  238. if seed_status.get('state') == 'failed':
  239. raise ExtractorError(
  240. '%s returned error: %s' % (self.IE_NAME, seed_status['title']),
  241. expected=True)
  242. # Extract the config JSON
  243. try:
  244. try:
  245. config_url = self._html_search_regex(
  246. r' data-config-url="(.+?)"', webpage, 'config URL')
  247. config_json = self._download_webpage(config_url, video_id)
  248. config = json.loads(config_json)
  249. except RegexNotFoundError:
  250. # For pro videos or player.vimeo.com urls
  251. # We try to find out to which variable is assigned the config dic
  252. m_variable_name = re.search('(\w)\.video\.id', webpage)
  253. if m_variable_name is not None:
  254. config_re = r'%s=({[^}].+?});' % re.escape(m_variable_name.group(1))
  255. else:
  256. config_re = [r' = {config:({.+?}),assets:', r'(?:[abc])=({.+?});']
  257. config = self._search_regex(config_re, webpage, 'info section',
  258. flags=re.DOTALL)
  259. config = json.loads(config)
  260. except Exception as e:
  261. if re.search('The creator of this video has not given you permission to embed it on this domain.', webpage):
  262. raise ExtractorError('The author has restricted the access to this video, try with the "--referer" option')
  263. if re.search(r'<form[^>]+?id="pw_form"', webpage) is not None:
  264. if data and '_video_password_verified' in data:
  265. raise ExtractorError('video password verification failed!')
  266. self._verify_video_password(url, video_id, webpage)
  267. return self._real_extract(
  268. smuggle_url(url, {'_video_password_verified': 'verified'}))
  269. else:
  270. raise ExtractorError('Unable to extract info section',
  271. cause=e)
  272. else:
  273. if config.get('view') == 4:
  274. config = self._verify_player_video_password(url, video_id)
  275. # Extract title
  276. video_title = config["video"]["title"]
  277. # Extract uploader and uploader_id
  278. video_uploader = config["video"]["owner"]["name"]
  279. video_uploader_id = config["video"]["owner"]["url"].split('/')[-1] if config["video"]["owner"]["url"] else None
  280. # Extract video thumbnail
  281. video_thumbnail = config["video"].get("thumbnail")
  282. if video_thumbnail is None:
  283. video_thumbs = config["video"].get("thumbs")
  284. if video_thumbs and isinstance(video_thumbs, dict):
  285. _, video_thumbnail = sorted((int(width if width.isdigit() else 0), t_url) for (width, t_url) in video_thumbs.items())[-1]
  286. # Extract video description
  287. video_description = self._html_search_regex(
  288. r'(?s)<div\s+class="[^"]*description[^"]*"[^>]*>(.*?)</div>',
  289. webpage, 'description', default=None)
  290. if not video_description:
  291. video_description = self._html_search_meta(
  292. 'description', webpage, default=None)
  293. if not video_description and mobj.group('pro'):
  294. orig_webpage = self._download_webpage(
  295. orig_url, video_id,
  296. note='Downloading webpage for description',
  297. fatal=False)
  298. if orig_webpage:
  299. video_description = self._html_search_meta(
  300. 'description', orig_webpage, default=None)
  301. if not video_description and not mobj.group('player'):
  302. self._downloader.report_warning('Cannot find video description')
  303. # Extract video duration
  304. video_duration = int_or_none(config["video"].get("duration"))
  305. # Extract upload date
  306. video_upload_date = None
  307. mobj = re.search(r'<time[^>]+datetime="([^"]+)"', webpage)
  308. if mobj is not None:
  309. video_upload_date = unified_strdate(mobj.group(1))
  310. try:
  311. view_count = int(self._search_regex(r'UserPlays:(\d+)', webpage, 'view count'))
  312. like_count = int(self._search_regex(r'UserLikes:(\d+)', webpage, 'like count'))
  313. comment_count = int(self._search_regex(r'UserComments:(\d+)', webpage, 'comment count'))
  314. except RegexNotFoundError:
  315. # This info is only available in vimeo.com/{id} urls
  316. view_count = None
  317. like_count = None
  318. comment_count = None
  319. # Vimeo specific: extract request signature and timestamp
  320. sig = config['request']['signature']
  321. timestamp = config['request']['timestamp']
  322. # Vimeo specific: extract video codec and quality information
  323. # First consider quality, then codecs, then take everything
  324. codecs = [('vp6', 'flv'), ('vp8', 'flv'), ('h264', 'mp4')]
  325. files = {'hd': [], 'sd': [], 'other': []}
  326. config_files = config["video"].get("files") or config["request"].get("files")
  327. for codec_name, codec_extension in codecs:
  328. for quality in config_files.get(codec_name, []):
  329. format_id = '-'.join((codec_name, quality)).lower()
  330. key = quality if quality in files else 'other'
  331. video_url = None
  332. if isinstance(config_files[codec_name], dict):
  333. file_info = config_files[codec_name][quality]
  334. video_url = file_info.get('url')
  335. else:
  336. file_info = {}
  337. if video_url is None:
  338. video_url = "http://player.vimeo.com/play_redirect?clip_id=%s&sig=%s&time=%s&quality=%s&codecs=%s&type=moogaloop_local&embed_location=" \
  339. % (video_id, sig, timestamp, quality, codec_name.upper())
  340. files[key].append({
  341. 'ext': codec_extension,
  342. 'url': video_url,
  343. 'format_id': format_id,
  344. 'width': file_info.get('width'),
  345. 'height': file_info.get('height'),
  346. })
  347. formats = []
  348. for key in ('other', 'sd', 'hd'):
  349. formats += files[key]
  350. if len(formats) == 0:
  351. raise ExtractorError('No known codec found')
  352. subtitles = {}
  353. text_tracks = config['request'].get('text_tracks')
  354. if text_tracks:
  355. for tt in text_tracks:
  356. subtitles[tt['lang']] = [{
  357. 'ext': 'vtt',
  358. 'url': 'https://vimeo.com' + tt['url'],
  359. }]
  360. return {
  361. 'id': video_id,
  362. 'uploader': video_uploader,
  363. 'uploader_id': video_uploader_id,
  364. 'upload_date': video_upload_date,
  365. 'title': video_title,
  366. 'thumbnail': video_thumbnail,
  367. 'description': video_description,
  368. 'duration': video_duration,
  369. 'formats': formats,
  370. 'webpage_url': url,
  371. 'view_count': view_count,
  372. 'like_count': like_count,
  373. 'comment_count': comment_count,
  374. 'subtitles': subtitles,
  375. }
  376. class VimeoChannelIE(InfoExtractor):
  377. IE_NAME = 'vimeo:channel'
  378. _VALID_URL = r'https://vimeo\.com/channels/(?P<id>[^/?#]+)/?(?:$|[?#])'
  379. _MORE_PAGES_INDICATOR = r'<a.+?rel="next"'
  380. _TITLE_RE = r'<link rel="alternate"[^>]+?title="(.*?)"'
  381. _TESTS = [{
  382. 'url': 'https://vimeo.com/channels/tributes',
  383. 'info_dict': {
  384. 'id': 'tributes',
  385. 'title': 'Vimeo Tributes',
  386. },
  387. 'playlist_mincount': 25,
  388. }]
  389. def _page_url(self, base_url, pagenum):
  390. return '%s/videos/page:%d/' % (base_url, pagenum)
  391. def _extract_list_title(self, webpage):
  392. return self._html_search_regex(self._TITLE_RE, webpage, 'list title')
  393. def _login_list_password(self, page_url, list_id, webpage):
  394. login_form = self._search_regex(
  395. r'(?s)<form[^>]+?id="pw_form"(.*?)</form>',
  396. webpage, 'login form', default=None)
  397. if not login_form:
  398. return webpage
  399. password = self._downloader.params.get('videopassword', None)
  400. if password is None:
  401. raise ExtractorError('This album is protected by a password, use the --video-password option', expected=True)
  402. fields = dict(re.findall(r'''(?x)<input\s+
  403. type="hidden"\s+
  404. name="([^"]+)"\s+
  405. value="([^"]*)"
  406. ''', login_form))
  407. token = self._search_regex(r'xsrft[\s=:"\']+([^"\']+)', webpage, 'login token')
  408. fields['token'] = token
  409. fields['password'] = password
  410. post = urlencode_postdata(fields)
  411. password_path = self._search_regex(
  412. r'action="([^"]+)"', login_form, 'password URL')
  413. password_url = compat_urlparse.urljoin(page_url, password_path)
  414. password_request = compat_urllib_request.Request(password_url, post)
  415. password_request.add_header('Content-type', 'application/x-www-form-urlencoded')
  416. self._set_cookie('vimeo.com', 'xsrft', token)
  417. return self._download_webpage(
  418. password_request, list_id,
  419. 'Verifying the password', 'Wrong password')
  420. def _extract_videos(self, list_id, base_url):
  421. video_ids = []
  422. for pagenum in itertools.count(1):
  423. page_url = self._page_url(base_url, pagenum)
  424. webpage = self._download_webpage(
  425. page_url, list_id,
  426. 'Downloading page %s' % pagenum)
  427. if pagenum == 1:
  428. webpage = self._login_list_password(page_url, list_id, webpage)
  429. video_ids.extend(re.findall(r'id="clip_(\d+?)"', webpage))
  430. if re.search(self._MORE_PAGES_INDICATOR, webpage, re.DOTALL) is None:
  431. break
  432. entries = [self.url_result('https://vimeo.com/%s' % video_id, 'Vimeo')
  433. for video_id in video_ids]
  434. return {'_type': 'playlist',
  435. 'id': list_id,
  436. 'title': self._extract_list_title(webpage),
  437. 'entries': entries,
  438. }
  439. def _real_extract(self, url):
  440. mobj = re.match(self._VALID_URL, url)
  441. channel_id = mobj.group('id')
  442. return self._extract_videos(channel_id, 'https://vimeo.com/channels/%s' % channel_id)
  443. class VimeoUserIE(VimeoChannelIE):
  444. IE_NAME = 'vimeo:user'
  445. _VALID_URL = r'https://vimeo\.com/(?![0-9]+(?:$|[?#/]))(?P<name>[^/]+)(?:/videos|[#?]|$)'
  446. _TITLE_RE = r'<a[^>]+?class="user">([^<>]+?)</a>'
  447. _TESTS = [{
  448. 'url': 'https://vimeo.com/nkistudio/videos',
  449. 'info_dict': {
  450. 'title': 'Nki',
  451. 'id': 'nkistudio',
  452. },
  453. 'playlist_mincount': 66,
  454. }]
  455. def _real_extract(self, url):
  456. mobj = re.match(self._VALID_URL, url)
  457. name = mobj.group('name')
  458. return self._extract_videos(name, 'https://vimeo.com/%s' % name)
  459. class VimeoAlbumIE(VimeoChannelIE):
  460. IE_NAME = 'vimeo:album'
  461. _VALID_URL = r'https://vimeo\.com/album/(?P<id>\d+)'
  462. _TITLE_RE = r'<header id="page_header">\n\s*<h1>(.*?)</h1>'
  463. _TESTS = [{
  464. 'url': 'https://vimeo.com/album/2632481',
  465. 'info_dict': {
  466. 'id': '2632481',
  467. 'title': 'Staff Favorites: November 2013',
  468. },
  469. 'playlist_mincount': 13,
  470. }, {
  471. 'note': 'Password-protected album',
  472. 'url': 'https://vimeo.com/album/3253534',
  473. 'info_dict': {
  474. 'title': 'test',
  475. 'id': '3253534',
  476. },
  477. 'playlist_count': 1,
  478. 'params': {
  479. 'videopassword': 'youtube-dl',
  480. }
  481. }]
  482. def _page_url(self, base_url, pagenum):
  483. return '%s/page:%d/' % (base_url, pagenum)
  484. def _real_extract(self, url):
  485. album_id = self._match_id(url)
  486. return self._extract_videos(album_id, 'https://vimeo.com/album/%s' % album_id)
  487. class VimeoGroupsIE(VimeoAlbumIE):
  488. IE_NAME = 'vimeo:group'
  489. _VALID_URL = r'https://vimeo\.com/groups/(?P<name>[^/]+)'
  490. _TESTS = [{
  491. 'url': 'https://vimeo.com/groups/rolexawards',
  492. 'info_dict': {
  493. 'id': 'rolexawards',
  494. 'title': 'Rolex Awards for Enterprise',
  495. },
  496. 'playlist_mincount': 73,
  497. }]
  498. def _extract_list_title(self, webpage):
  499. return self._og_search_title(webpage)
  500. def _real_extract(self, url):
  501. mobj = re.match(self._VALID_URL, url)
  502. name = mobj.group('name')
  503. return self._extract_videos(name, 'https://vimeo.com/groups/%s' % name)
  504. class VimeoReviewIE(InfoExtractor):
  505. IE_NAME = 'vimeo:review'
  506. IE_DESC = 'Review pages on vimeo'
  507. _VALID_URL = r'https://vimeo\.com/[^/]+/review/(?P<id>[^/]+)'
  508. _TESTS = [{
  509. 'url': 'https://vimeo.com/user21297594/review/75524534/3c257a1b5d',
  510. 'md5': 'c507a72f780cacc12b2248bb4006d253',
  511. 'info_dict': {
  512. 'id': '75524534',
  513. 'ext': 'mp4',
  514. 'title': "DICK HARDWICK 'Comedian'",
  515. 'uploader': 'Richard Hardwick',
  516. }
  517. }, {
  518. 'note': 'video player needs Referer',
  519. 'url': 'https://vimeo.com/user22258446/review/91613211/13f927e053',
  520. 'md5': '6295fdab8f4bf6a002d058b2c6dce276',
  521. 'info_dict': {
  522. 'id': '91613211',
  523. 'ext': 'mp4',
  524. 'title': 're:(?i)^Death by dogma versus assembling agile . Sander Hoogendoorn',
  525. 'uploader': 'DevWeek Events',
  526. 'duration': 2773,
  527. 'thumbnail': 're:^https?://.*\.jpg$',
  528. }
  529. }]
  530. def _real_extract(self, url):
  531. mobj = re.match(self._VALID_URL, url)
  532. video_id = mobj.group('id')
  533. player_url = 'https://player.vimeo.com/player/' + video_id
  534. return self.url_result(player_url, 'Vimeo', video_id)
  535. class VimeoWatchLaterIE(VimeoBaseInfoExtractor, VimeoChannelIE):
  536. IE_NAME = 'vimeo:watchlater'
  537. IE_DESC = 'Vimeo watch later list, "vimeowatchlater" keyword (requires authentication)'
  538. _VALID_URL = r'https://vimeo\.com/home/watchlater|:vimeowatchlater'
  539. _LOGIN_REQUIRED = True
  540. _TITLE_RE = r'href="/home/watchlater".*?>(.*?)<'
  541. _TESTS = [{
  542. 'url': 'https://vimeo.com/home/watchlater',
  543. 'only_matching': True,
  544. }]
  545. def _real_initialize(self):
  546. self._login()
  547. def _page_url(self, base_url, pagenum):
  548. url = '%s/page:%d/' % (base_url, pagenum)
  549. request = compat_urllib_request.Request(url)
  550. # Set the header to get a partial html page with the ids,
  551. # the normal page doesn't contain them.
  552. request.add_header('X-Requested-With', 'XMLHttpRequest')
  553. return request
  554. def _real_extract(self, url):
  555. return self._extract_videos('watchlater', 'https://vimeo.com/home/watchlater')
  556. class VimeoLikesIE(InfoExtractor):
  557. _VALID_URL = r'https://(?:www\.)?vimeo\.com/user(?P<id>[0-9]+)/likes/?(?:$|[?#]|sort:)'
  558. IE_NAME = 'vimeo:likes'
  559. IE_DESC = 'Vimeo user likes'
  560. _TEST = {
  561. 'url': 'https://vimeo.com/user755559/likes/',
  562. 'playlist_mincount': 293,
  563. "info_dict": {
  564. 'id': 'user755559_likes',
  565. "description": "See all the videos urza likes",
  566. "title": 'Videos urza likes',
  567. },
  568. }
  569. def _real_extract(self, url):
  570. user_id = self._match_id(url)
  571. webpage = self._download_webpage(url, user_id)
  572. page_count = self._int(
  573. self._search_regex(
  574. r'''(?x)<li><a\s+href="[^"]+"\s+data-page="([0-9]+)">
  575. .*?</a></li>\s*<li\s+class="pagination_next">
  576. ''', webpage, 'page count'),
  577. 'page count', fatal=True)
  578. PAGE_SIZE = 12
  579. title = self._html_search_regex(
  580. r'(?s)<h1>(.+?)</h1>', webpage, 'title', fatal=False)
  581. description = self._html_search_meta('description', webpage)
  582. def _get_page(idx):
  583. page_url = 'https://vimeo.com/user%s/likes/page:%d/sort:date' % (
  584. user_id, idx + 1)
  585. webpage = self._download_webpage(
  586. page_url, user_id,
  587. note='Downloading page %d/%d' % (idx + 1, page_count))
  588. video_list = self._search_regex(
  589. r'(?s)<ol class="js-browse_list[^"]+"[^>]*>(.*?)</ol>',
  590. webpage, 'video content')
  591. paths = re.findall(
  592. r'<li[^>]*>\s*<a\s+href="([^"]+)"', video_list)
  593. for path in paths:
  594. yield {
  595. '_type': 'url',
  596. 'url': compat_urlparse.urljoin(page_url, path),
  597. }
  598. pl = InAdvancePagedList(_get_page, page_count, PAGE_SIZE)
  599. return {
  600. '_type': 'playlist',
  601. 'id': 'user%s_likes' % user_id,
  602. 'title': title,
  603. 'description': description,
  604. 'entries': pl,
  605. }