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.

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