]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/slideshare.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / slideshare.py
CommitLineData
07463ea1
JMF
1import json
2
3from .common import InfoExtractor
1cc79574 4from ..compat import (
07463ea1 5 compat_urlparse,
1cc79574
PH
6)
7from ..utils import (
07463ea1 8 ExtractorError,
77082c7b 9 get_element_by_id,
07463ea1
JMF
10)
11
12
13class SlideshareIE(InfoExtractor):
92519402 14 _VALID_URL = r'https?://(?:www\.)?slideshare\.net/[^/]+?/(?P<title>.+?)($|\?)'
07463ea1
JMF
15
16 _TEST = {
1afe7534
JMF
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.',
07463ea1
JMF
23 },
24 }
25
26 def _real_extract(self, url):
5ad28e7f 27 mobj = self._match_valid_url(url)
07463ea1
JMF
28 page_title = mobj.group('title')
29 webpage = self._download_webpage(url, page_title)
30 slideshare_obj = self._search_regex(
00dbdfc1 31 r'\$\.extend\(.*?slideshare_object,\s*(\{.*?\})\);',
1afe7534 32 webpage, 'slideshare object')
07463ea1 33 info = json.loads(slideshare_obj)
1afe7534
JMF
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)
07463ea1
JMF
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)
77082c7b 41 description = get_element_by_id('slideshow-description-paragraph', webpage) or self._html_search_regex(
b7a7319c 42 r'(?s)<p[^>]+itemprop="description"[^>]*>(.+?)</p>', webpage,
c82b1fda 43 'description', fatal=False)
07463ea1
JMF
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'],
77082c7b 52 'description': description.strip() if description else None,
07463ea1 53 }