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.

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