[ie/twitter:spaces] Support video spaces (#10789)
[yt-dlp3.git] / yt_dlp / extractor / slideshare.py
blob302b6e15cdc973bc82d62bf4ec597b4ec5b448f3
1 import json
2 import urllib.parse
4 from .common import InfoExtractor
5 from ..utils import (
6 ExtractorError,
7 get_element_by_id,
11 class SlideshareIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?slideshare\.net/[^/]+?/(?P<title>.+?)($|\?)'
14 _TEST = {
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.',
24 def _real_extract(self, url):
25 mobj = self._match_valid_url(url)
26 page_title = mobj.group('title')
27 webpage = self._download_webpage(url, page_title)
28 slideshare_obj = self._search_regex(
29 r'\$\.extend\(.*?slideshare_object,\s*(\{.*?\})\);',
30 webpage, 'slideshare object')
31 info = json.loads(slideshare_obj)
32 if info['slideshow']['type'] != 'video':
33 raise ExtractorError('Webpage type is "{}": only video extraction is supported for Slideshare'.format(info['slideshow']['type']), expected=True)
35 doc = info['doc']
36 bucket = info['jsplayer']['video_bucket']
37 ext = info['jsplayer']['video_extension']
38 video_url = urllib.parse.urljoin(bucket, doc + '-SD.' + ext)
39 description = get_element_by_id('slideshow-description-paragraph', webpage) or self._html_search_regex(
40 r'(?s)<p[^>]+itemprop="description"[^>]*>(.+?)</p>', webpage,
41 'description', fatal=False)
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'],
50 'description': description.strip() if description else None,