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