1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-11-23 00:54:31 +01:00

[spreaker] Fixes requested

This commit is contained in:
Andrew Udvare 2018-07-01 17:25:38 -04:00
parent b3f68149b6
commit 5ec9047d2c
2 changed files with 112 additions and 114 deletions

View File

@ -1022,10 +1022,8 @@ from .stitcher import StitcherIE
from .sport5 import Sport5IE from .sport5 import Sport5IE
from .sportbox import SportBoxEmbedIE from .sportbox import SportBoxEmbedIE
from .sportdeutschland import SportDeutschlandIE from .sportdeutschland import SportDeutschlandIE
from .sportschau import SportschauIE
from .spreaker import ( from .spreaker import (
SpreakerIE, SpreakerIE,
SpreakerAPIEpisodeIE,
SpreakerPlaylistIE SpreakerPlaylistIE
) )
from .springboardplatform import SpringboardPlatformIE from .springboardplatform import SpringboardPlatformIE

View File

@ -8,120 +8,6 @@ from ..compat import compat_str
from ..utils import int_or_none, ExtractorError from ..utils import int_or_none, ExtractorError
class SpreakerPlaylistIE(InfoExtractor):
IE_NAME = 'spreaker:playlist'
_VALID_URL = r'^https?://(?:www\.)?spreaker\.com/show/[a-z0-9_-]+'
_TEST = {
'url': 'https://www.spreaker.com/show/success-with-music',
'info_dict': {
'title': 'Success With Music',
'id': 2317431,
},
'playlist_mincount': 14,
}
def _real_extract(self, url):
html = self._download_webpage(url, None)
playlist_url = self._html_search_regex(
r'data-playlist_url="(?P<url>https\://[^"]+")', html, 'url')
items = self._download_json(playlist_url,
None,
'Downloading playlist JSON')
playlist = items['response']['playlist']
next_url = playlist.get('next_url')
items = playlist.get('items', [])
if not items:
raise ExtractorError('Empty playlist')
page_no = 2
download_str = 'Downloading playlist JSON page #%d'
while next_url:
items_ = self._download_json(next_url,
None,
download_str % (page_no,))
playlist_ = items_['response']['playlist']
new_items = playlist_.get('items', [])
if not new_items:
break
items += new_items
next_url = playlist_.get('next_url')
page_no += 1
urls = [x['api_url'] for x in items]
ret = []
for index, url in enumerate(urls):
data = self._download_json(url, None)['response']['episode']
dict_ = SpreakerIE._spreaker_episode_data_to_info(data)
dict_.update({
'playlist_id': compat_str(data['show_id']),
'playlist_title': data['show']['title'],
'playlist_index': index,
})
ret.append(dict_)
return self.playlist_result(ret,
data['show_id'],
data['show']['title'])
class SpreakerAPIEpisodeIE(InfoExtractor):
IE_NAME = 'spreaker:api'
_VALID_URL = r'^https?://(?:api\.)?spreaker\.com/(?:download/)?episode/(?P<id>[0-9]+)(?:/[^\.]+\.mp3$)?'
_TESTS = [
{
'url': 'https://api.spreaker.com/episode/12534508',
'info_dict': {
'id': '12534508',
'ext': 'mp3',
'title': 'Marketing Your Music - Part 2',
'upload_date': '20170809',
'uploader': 'SWM',
'uploader_id': 9780658,
},
},
{
'url': 'https://api.spreaker.com/download/episode/12534508/swm_ep15_how_to_market_your_music_part_2.mp3',
'info_dict': {
'id': '12534508',
'ext': 'mp3',
'title': 'Marketing Your Music - Part 2',
'upload_date': '20170809',
'uploader': 'SWM',
'uploader_id': 9780658,
},
},
]
def _real_extract(self, url):
episode_id = self._match_id(url)
if not re.match(r'^[0-9]+$', episode_id):
raise ExtractorError('Invalid ID')
url = 'https://api.spreaker.com/episode/%s' % (episode_id,)
data = self._download_json(url, episode_id)['response']['episode']
if not data['download_enabled']:
raise ExtractorError('Not supported yet')
return SpreakerIE._spreaker_episode_data_to_info(data)
class SpreakerIE(InfoExtractor):
IE_NAME = 'spreaker'
_VALID_URL = r'^https?://(?:www\.)?spreaker\.com/user/[a-z0-9_-]+/[a-z0-9_-]'
_TEST = {
'url': 'https://www.spreaker.com/user/9780658/swm-ep15-how-to-market-your-music-part-2',
'info_dict': {
'id': '12534508',
'ext': 'mp3',
'title': 'Marketing Your Music - Part 2',
'upload_date': '20170809',
'uploader': 'SWM',
'uploader_id': 9780658,
},
}
@staticmethod
def _spreaker_episode_data_to_info(data): def _spreaker_episode_data_to_info(data):
published_at = data.get('published_at') published_at = data.get('published_at')
upload_date = None upload_date = None
@ -134,11 +20,19 @@ class SpreakerIE(InfoExtractor):
show_image = show.get('image', {}) show_image = show.get('image', {})
if stats: if stats:
view_count = (stats.get('plays', 0) + plays = stats.get('plays')
stats.get('plays_streaming', 0) + plays_streaming = stats.get('plays_streaming')
stats.get('plays_download', 0)) plays_download = stats.get('plays_download')
like_count = stats.get('likes', 0) view_count = None
comment_count = stats.get('messages', 0) for x in [plays, plays_streaming, plays_download]:
if x is None:
continue
if view_count is None:
view_count = x
else:
view_count += x
like_count = stats.get('likes')
comment_count = stats.get('messages')
return { return {
'id': compat_str(data['episode_id']), 'id': compat_str(data['episode_id']),
@ -181,12 +75,118 @@ class SpreakerIE(InfoExtractor):
'extractor': 'spreaker', 'extractor': 'spreaker',
} }
class SpreakerPlaylistIE(InfoExtractor):
IE_NAME = 'spreaker:playlist'
_VALID_URL = r'https?://(?:www\.)?spreaker\.com/show/[a-z0-9_-]+'
_TEST = {
'url': 'https://www.spreaker.com/show/success-with-music',
'info_dict': {
'title': 'Success With Music',
'id': 2317431,
},
'playlist_mincount': 14,
}
def _real_extract(self, url): def _real_extract(self, url):
html = self._download_webpage(url, None) html = self._download_webpage(url, None)
playlist_url = self._html_search_regex(
r'data-playlist_url="(?P<url>https\://[^"]+")', html, 'url')
items = self._download_json(playlist_url,
None,
'Downloading playlist JSON')
playlist = items['response']['playlist']
next_url = playlist.get('next_url')
items = playlist.get('items', [])
if not items:
raise ExtractorError('Empty playlist')
page_no = 2
download_str = 'Downloading playlist JSON page #%d'
while next_url:
items_ = self._download_json(next_url,
None,
download_str % (page_no,))
playlist_ = items_['response']['playlist']
new_items = playlist_.get('items', [])
if not new_items:
break
items += new_items
next_url = playlist_.get('next_url')
page_no += 1
urls = [x['api_url'] for x in items]
entries = []
for index, url in enumerate(urls):
data = self._download_json(url, None)['response']['episode']
dict_ = _spreaker_episode_data_to_info(data)
entries.append(dict_)
return self.playlist_result(entries,
data['show_id'],
data['show']['title'])
class SpreakerIE(InfoExtractor):
IE_NAME = 'spreaker'
_VALID_URL = (r'https?://(?:(?:api|www)\.)?spreaker\.com/'
r'(?:(?:(?:download/)?episode/(?P<id>[0-9]+)'
r'(?:/[^\.]+\.mp3$)?)|user/[a-z0-9_-]+/[a-z0-9_-]+)')
_TESTS = [
{
'url': 'https://api.spreaker.com/episode/12534508',
'info_dict': {
'id': '12534508',
'ext': 'mp3',
'title': 'EP:15 | Music Marketing (Likes) - Part 2',
'upload_date': '20170809',
'uploader': 'SWM',
'uploader_id': 9780658,
},
},
{
'url': ('https://api.spreaker.com/download/episode/12534508/'
'swm_ep15_how_to_market_your_music_part_2.mp3'),
'info_dict': {
'id': '12534508',
'ext': 'mp3',
'title': 'EP:15 | Music Marketing (Likes) - Part 2',
'upload_date': '20170809',
'uploader': 'SWM',
'uploader_id': 9780658,
},
},
{
'url': ('https://www.spreaker.com/user/9780658/swm-ep15-how-to-'
'market-your-music-part-2'),
'info_dict': {
'id': '12534508',
'ext': 'mp3',
'title': 'EP:15 | Music Marketing (Likes) - Part 2',
'upload_date': '20170809',
'uploader': 'SWM',
'uploader_id': 9780658,
},
}
]
def _real_extract(self, url):
episode_id = self._match_id(url)
if re.match(r'^[0-9]+$', episode_id):
url = 'https://api.spreaker.com/episode/%s' % (episode_id,)
else:
html = self._download_webpage(url,
None,
note='Downloading episode page')
episode_id = self._html_search_regex( episode_id = self._html_search_regex(
r'data-episode_id="(?P<id>[0-9]+)"', html, 'id') r'data-episode_id="(?P<id>[0-9]+)"', html, 'id')
if not re.match(r'^[0-9]+$', episode_id): if not re.match(r'^[0-9]+$', episode_id):
raise ExtractorError('Could not find episode ID') raise ExtractorError('Could not find episode ID')
data_url = 'https://api.spreaker.com/episode/%s' % (episode_id) url = 'https://api.spreaker.com/episode/%s' % (episode_id)
return self.url_result(data_url) data = self._download_json(url, episode_id)['response']['episode']
if not data['download_enabled']:
raise ExtractorError('Not supported yet')
return _spreaker_episode_data_to_info(data)