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.

670 lines
26 KiB

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