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.

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