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.

53 lines
2.0 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. import json
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. compat_urlparse,
  7. ExtractorError,
  8. )
  9. class SlideshareIE(InfoExtractor):
  10. _VALID_URL = r'https?://www\.slideshare\.net/[^/]+?/(?P<title>.+?)($|\?)'
  11. _TEST = {
  12. 'url': 'http://www.slideshare.net/Dataversity/keynote-presentation-managing-scale-and-complexity',
  13. 'info_dict': {
  14. 'id': '25665706',
  15. 'ext': 'mp4',
  16. 'title': 'Managing Scale and Complexity',
  17. 'description': 'This was a keynote presentation at the NoSQL Now! 2013 Conference & Expo (http://www.nosqlnow.com). This presentation was given by Adrian Cockcroft from Netflix.',
  18. },
  19. }
  20. def _real_extract(self, url):
  21. mobj = re.match(self._VALID_URL, url)
  22. page_title = mobj.group('title')
  23. webpage = self._download_webpage(url, page_title)
  24. slideshare_obj = self._search_regex(
  25. r'var slideshare_object = ({.*?}); var user_info =',
  26. webpage, 'slideshare object')
  27. info = json.loads(slideshare_obj)
  28. if info['slideshow']['type'] != 'video':
  29. raise ExtractorError('Webpage type is "%s": only video extraction is supported for Slideshare' % info['slideshow']['type'], expected=True)
  30. doc = info['doc']
  31. bucket = info['jsplayer']['video_bucket']
  32. ext = info['jsplayer']['video_extension']
  33. video_url = compat_urlparse.urljoin(bucket, doc + '-SD.' + ext)
  34. description = self._html_search_regex(
  35. r'<p\s+(?:style="[^"]*"\s+)?class="description.*?"[^>]*>(.*?)</p>', webpage,
  36. 'description', fatal=False)
  37. return {
  38. '_type': 'video',
  39. 'id': info['slideshow']['id'],
  40. 'title': info['slideshow']['title'],
  41. 'ext': ext,
  42. 'url': video_url,
  43. 'thumbnail': info['slideshow']['pin_image_url'],
  44. 'description': description,
  45. }