]>
Commit | Line | Data |
---|---|---|
1 | import json | |
2 | ||
3 | from .common import InfoExtractor | |
4 | from ..compat import ( | |
5 | compat_urlparse, | |
6 | ) | |
7 | from ..utils import ( | |
8 | ExtractorError, | |
9 | get_element_by_id, | |
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 = self._match_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'\$\.extend\(.*?slideshare_object,\s*(\{.*?\})\);', | |
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 = get_element_by_id('slideshow-description-paragraph', webpage) or self._html_search_regex( | |
42 | r'(?s)<p[^>]+itemprop="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.strip() if description else None, | |
53 | } |