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