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