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