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.

55 lines
2.0 KiB

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