2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..compat import compat_str
18 def _extract_episode(data, episode_id=None):
20 download_url = data['download_url']
22 series = try_get(data, lambda x: x['show']['title'], compat_str)
23 uploader = try_get(data, lambda x: x['author']['fullname'], compat_str)
26 for image in ('image_original', 'image_medium', 'image'):
27 image_url = url_or_none(data.get('%s_url' % image))
29 thumbnails.append({'url': image_url})
32 return int_or_none(try_get(
34 (lambda x: x['%ss_count' % key],
35 lambda x: x['stats']['%ss' % key])))
38 return float_or_none(data.get(key), scale=1000)
41 'id': compat_str(episode_id or data['episode_id']),
43 'display_id': data.get('permalink'),
45 'description': data.get('description'),
46 'timestamp': unified_timestamp(data.get('published_at')),
48 'uploader_id': str_or_none(data.get('author_id')),
50 'duration': duration('duration') or duration('length'),
51 'view_count': stats('play'),
52 'like_count': stats('like'),
53 'comment_count': stats('message'),
54 'format': 'MPEG Layer 3',
58 'thumbnails': thumbnails,
60 'extractor_key': SpreakerIE.ie_key(),
64 class SpreakerIE(InfoExtractor):
69 (?:download/)?episode|
75 'url': 'https://api.spreaker.com/episode/12534508',
78 'display_id': 'swm-ep15-how-to-market-your-music-part-2',
80 'title': 'EP:15 | Music Marketing (Likes) - Part 2',
81 'description': 'md5:0588c43e27be46423e183076fa071177',
82 'timestamp': 1502250336,
83 'upload_date': '20170809',
85 'uploader_id': '9780658',
90 'series': 'Success With Music (SWM)',
93 'url': 'https://api.spreaker.com/download/episode/12534508/swm_ep15_how_to_market_your_music_part_2.mp3',
94 'only_matching': True,
96 'url': 'https://api.spreaker.com/v2/episodes/12534508?export=episode_segments',
97 'only_matching': True,
100 def _real_extract(self, url):
101 episode_id = self._match_id(url)
102 data = self._download_json(
103 'https://api.spreaker.com/v2/episodes/%s' % episode_id,
104 episode_id)['response']['episode']
105 return _extract_episode(data, episode_id)
108 class SpreakerPageIE(InfoExtractor):
109 _VALID_URL = r'https?://(?:www\.)?spreaker\.com/user/[^/]+/(?P<id>[^/?#&]+)'
111 'url': 'https://www.spreaker.com/user/9780658/swm-ep15-how-to-market-your-music-part-2',
112 'only_matching': True,
115 def _real_extract(self, url):
116 display_id = self._match_id(url)
117 webpage = self._download_webpage(url, display_id)
118 episode_id = self._search_regex(
119 (r'data-episode_id=["\'](?P<id>\d+)',
120 r'episode_id\s*:\s*(?P<id>\d+)'), webpage, 'episode id')
121 return self.url_result(
122 'https://api.spreaker.com/episode/%s' % episode_id,
123 ie=SpreakerIE.ie_key(), video_id=episode_id)
126 class SpreakerShowIE(InfoExtractor):
127 _VALID_URL = r'https?://api\.spreaker\.com/show/(?P<id>\d+)'
129 'url': 'https://api.spreaker.com/show/4652058',
133 'playlist_mincount': 118,
136 def _entries(self, show_id):
137 for page_num in itertools.count(1):
138 episodes = self._download_json(
139 'https://api.spreaker.com/show/%s/episodes' % show_id,
140 show_id, note='Downloading JSON page %d' % page_num, query={
144 pager = try_get(episodes, lambda x: x['response']['pager'], dict)
147 results = pager.get('results')
148 if not results or not isinstance(results, list):
150 for result in results:
151 if not isinstance(result, dict):
153 yield _extract_episode(result)
154 if page_num == pager.get('last_page'):
157 def _real_extract(self, url):
158 show_id = self._match_id(url)
159 return self.playlist_result(self._entries(show_id), playlist_id=show_id)
162 class SpreakerShowPageIE(InfoExtractor):
163 _VALID_URL = r'https?://(?:www\.)?spreaker\.com/show/(?P<id>[^/?#&]+)'
165 'url': 'https://www.spreaker.com/show/success-with-music',
166 'only_matching': True,
169 def _real_extract(self, url):
170 display_id = self._match_id(url)
171 webpage = self._download_webpage(url, display_id)
172 show_id = self._search_regex(
173 r'show_id\s*:\s*(?P<id>\d+)', webpage, 'show id')
174 return self.url_result(
175 'https://api.spreaker.com/show/%s' % show_id,
176 ie=SpreakerShowIE.ie_key(), video_id=show_id)