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.

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