]>
Commit | Line | Data |
---|---|---|
2e90dff2 | 1 | from .common import InfoExtractor |
3395958d | 2 | from ..utils import ( |
0a5baf9c RA |
3 | clean_html, |
4 | get_element_by_class, | |
3395958d | 5 | parse_duration, |
0a5baf9c | 6 | strip_or_none, |
3395958d PH |
7 | unified_strdate, |
8 | ) | |
49aeedb8 | 9 | |
2e90dff2 | 10 | |
11 | class LibsynIE(InfoExtractor): | |
3b9b32f4 | 12 | _VALID_URL = r'(?P<mainurl>https?://html5-player\.libsyn\.com/embed/episode/id/(?P<id>[0-9]+))' |
49aeedb8 | 13 | |
3b9b32f4 | 14 | _TESTS = [{ |
3395958d PH |
15 | 'url': 'http://html5-player.libsyn.com/embed/episode/id/6385796/', |
16 | 'md5': '2a55e75496c790cdeb058e7e6c087746', | |
9ef4f12b | 17 | 'info_dict': { |
3395958d | 18 | 'id': '6385796', |
49aeedb8 | 19 | 'ext': 'mp3', |
3395958d | 20 | 'title': "Champion Minded - Developing a Growth Mindset", |
0a5baf9c RA |
21 | # description fetched using another request: |
22 | # http://html5-player.libsyn.com/embed/getitemdetails?item_id=6385796 | |
23 | # 'description': 'In this episode, Allistair talks about the importance of developing a growth mindset, not only in sports, but in life too.', | |
3395958d | 24 | 'upload_date': '20180320', |
3b9b32f4 | 25 | 'thumbnail': 're:^https?://.*', |
9ef4f12b | 26 | }, |
3b9b32f4 PH |
27 | }, { |
28 | 'url': 'https://html5-player.libsyn.com/embed/episode/id/3727166/height/75/width/200/theme/standard/direction/no/autoplay/no/autonext/no/thumbnail/no/preload/no/no_addthis/no/', | |
29 | 'md5': '6c5cb21acd622d754d3b1a92b582ce42', | |
30 | 'info_dict': { | |
31 | 'id': '3727166', | |
32 | 'ext': 'mp3', | |
33 | 'title': 'Clients From Hell Podcast - How a Sex Toy Company Kickstarted my Freelance Career', | |
34 | 'upload_date': '20150818', | |
35 | 'thumbnail': 're:^https?://.*', | |
36 | } | |
37 | }] | |
2e90dff2 | 38 | |
39 | def _real_extract(self, url): | |
5ad28e7f | 40 | url, video_id = self._match_valid_url(url).groups() |
49aeedb8 S |
41 | webpage = self._download_webpage(url, video_id) |
42 | ||
0a5baf9c RA |
43 | data = self._parse_json(self._search_regex( |
44 | r'var\s+playlistItem\s*=\s*({.+?});', | |
45 | webpage, 'JSON data block'), video_id) | |
46 | ||
47 | episode_title = data.get('item_title') or get_element_by_class('episode-title', webpage) | |
48 | if not episode_title: | |
49 | self._search_regex( | |
50 | [r'data-title="([^"]+)"', r'<title>(.+?)</title>'], | |
51 | webpage, 'episode title') | |
52 | episode_title = episode_title.strip() | |
53 | ||
54 | podcast_title = strip_or_none(clean_html(self._search_regex( | |
55 | r'<h3>([^<]+)</h3>', webpage, 'podcast title', | |
56 | default=None) or get_element_by_class('podcast-title', webpage))) | |
49aeedb8 | 57 | |
336d1904 | 58 | title = '%s - %s' % (podcast_title, episode_title) if podcast_title else episode_title |
49aeedb8 | 59 | |
0a5baf9c RA |
60 | formats = [] |
61 | for k, format_id in (('media_url_libsyn', 'libsyn'), ('media_url', 'main'), ('download_link', 'download')): | |
62 | f_url = data.get(k) | |
63 | if not f_url: | |
64 | continue | |
65 | formats.append({ | |
66 | 'url': f_url, | |
67 | 'format_id': format_id, | |
68 | }) | |
69 | ||
49aeedb8 | 70 | description = self._html_search_regex( |
3395958d | 71 | r'<p\s+id="info_text_body">(.+?)</p>', webpage, |
3b9b32f4 | 72 | 'description', default=None) |
3395958d PH |
73 | if description: |
74 | # Strip non-breaking and normal spaces | |
75 | description = description.replace('\u00A0', ' ').strip() | |
49aeedb8 | 76 | release_date = unified_strdate(self._search_regex( |
0a5baf9c RA |
77 | r'<div class="release_date">Released: ([^<]+)<', |
78 | webpage, 'release date', default=None) or data.get('release_date')) | |
3395958d | 79 | |
2e90dff2 | 80 | return { |
49aeedb8 S |
81 | 'id': video_id, |
82 | 'title': title, | |
83 | 'description': description, | |
0a5baf9c | 84 | 'thumbnail': data.get('thumbnail_url'), |
49aeedb8 | 85 | 'upload_date': release_date, |
0a5baf9c | 86 | 'duration': parse_duration(data.get('duration')), |
2e90dff2 | 87 | 'formats': formats, |
88 | } |