mirror of
https://github.com/nathom/streamrip.git
synced 2025-05-13 06:34:45 -04:00
Move soundcloud album parsing to Playlist
This commit is contained in:
parent
c480462edf
commit
74aca34e6a
2 changed files with 9 additions and 25 deletions
|
@ -660,14 +660,12 @@ class SoundCloudClient(ClientInterface):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def get(self, id=None, url=None, media_type="track"):
|
def get(self, id=None, url=None, media_type="track"):
|
||||||
assert media_type in ("track", "playlist", "album"), f"{media_type} not supported"
|
assert media_type in ("track", "playlist"), f"{media_type} not supported"
|
||||||
if media_type == 'album':
|
|
||||||
media_type = 'playlist'
|
|
||||||
|
|
||||||
if url is not None:
|
if url is not None:
|
||||||
resp, status = self._get(f"resolve?url={url}")
|
resp, status = self._get(f"resolve?url={url}")
|
||||||
elif id is not None:
|
elif id is not None:
|
||||||
resp, _ = self._get(f"tracks/{id}")
|
resp, _ = self._get(f"{media_type}s/{id}")
|
||||||
else:
|
else:
|
||||||
raise Exception("Must provide id or url")
|
raise Exception("Must provide id or url")
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
|
from pprint import pprint
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
@ -752,25 +753,6 @@ class Album(Tracklist):
|
||||||
"sampling_rate": 44100,
|
"sampling_rate": 44100,
|
||||||
"tracktotal": resp.get("track_total") or resp.get("nb_tracks"),
|
"tracktotal": resp.get("track_total") or resp.get("nb_tracks"),
|
||||||
}
|
}
|
||||||
elif client.source == 'soundcloud':
|
|
||||||
print(resp.keys())
|
|
||||||
return {
|
|
||||||
"id": resp['id'],
|
|
||||||
"title": resp['title'],
|
|
||||||
"_artist": resp['user']['username'],
|
|
||||||
"albumartist": resp['user']['username'],
|
|
||||||
"year": resp['created_at'][:4],
|
|
||||||
"cover_urls": {
|
|
||||||
"small": resp['artwork_url'],
|
|
||||||
"large": resp['artwork_url'].replace('large', 't500x500') if resp['artwork_url'] is not None else None
|
|
||||||
},
|
|
||||||
"url": resp['uri'],
|
|
||||||
"streamable": True, # assume to be true for convenience
|
|
||||||
"quality": 0, # always 128 kbps mp3
|
|
||||||
# no bit depth
|
|
||||||
# no sampling rate
|
|
||||||
"tracktotal": resp['track_count'],
|
|
||||||
}
|
|
||||||
|
|
||||||
raise InvalidSourceError(client.source)
|
raise InvalidSourceError(client.source)
|
||||||
|
|
||||||
|
@ -950,7 +932,7 @@ class Playlist(Tracklist):
|
||||||
"""Represents a downloadable playlist.
|
"""Represents a downloadable playlist.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
>>> resp = client.get('hip hop', 'playlist')
|
>>> resp = client.search('hip hop', 'playlist')
|
||||||
>>> pl = Playlist.from_api(resp['items'][0], client)
|
>>> pl = Playlist.from_api(resp['items'][0], client)
|
||||||
>>> pl.load_meta()
|
>>> pl.load_meta()
|
||||||
>>> pl.download()
|
>>> pl.download()
|
||||||
|
@ -993,7 +975,7 @@ class Playlist(Tracklist):
|
||||||
:type new_tracknumbers: bool
|
:type new_tracknumbers: bool
|
||||||
:param kwargs:
|
:param kwargs:
|
||||||
"""
|
"""
|
||||||
self.meta = self.client.get(self.id, "playlist")
|
self.meta = self.client.get(id=self.id, media_type="playlist")
|
||||||
self._load_tracks(**kwargs)
|
self._load_tracks(**kwargs)
|
||||||
|
|
||||||
def _load_tracks(self, new_tracknumbers: bool = True):
|
def _load_tracks(self, new_tracknumbers: bool = True):
|
||||||
|
@ -1036,6 +1018,10 @@ class Playlist(Tracklist):
|
||||||
def meta_args(track):
|
def meta_args(track):
|
||||||
return {"track": track, "source": self.client.source}
|
return {"track": track, "source": self.client.source}
|
||||||
|
|
||||||
|
elif self.client.source == 'soundcloud':
|
||||||
|
self.name = self.meta['title']
|
||||||
|
tracklist = self.meta['tracks']
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue