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