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.

47 lines
1.8 KiB

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