Verified Commit 70c5319a authored by David Sn's avatar David Sn
Browse files

Add support for cover art

Signed-off-by: David Sn's avatarDavid Sn <>
parent 189bf9a9
......@@ -255,6 +255,34 @@ class FunkwhaleLibraryProvider(backend.LibraryProvider):
return libraries, True
def get_images(self, uris):
logger.debug("Handling get images: %s", uris)
result = {}
# TODO Add cache
for uri in uris:
track_id = uri.split(":")[-1]
payload = self.backend.client.get_track(track_id)
if not payload["album"]["cover"]:
result[uri] = []
for type, cover_url in payload["album"]["cover"]["urls"].items():
if not cover_url:
if type == "large_square_crop":
image = models.Image(uri=cover_url, width=600, height=600)
elif type == "medium_square_crop":
image = models.Image(uri=cover_url, width=200, height=200)
image = models.Image(uri=cover_url)
return result
def search(self, query=None, uris=None, exact=False):
# TODO Support exact search
......@@ -333,8 +361,6 @@ def convert_to_artist(payload, uri_prefix="funkwhale:artists"):
def convert_to_album(payload, uri_prefix="funkwhale:albums"):
artist = convert_to_artist(payload["artist"])
image = payload["cover"]["urls"]["original"] if payload["cover"] else None
return models.Album(
uri=uri_prefix + ":%s" % payload["id"],
......@@ -349,6 +375,7 @@ def convert_to_album(payload, uri_prefix="funkwhale:albums"):
def convert_to_track(payload, uri_prefix="funkwhale:tracks"):
artist = convert_to_artist(payload["artist"])
album = convert_to_album(payload["album"])
upload = payload["uploads"][0]
except (KeyError, IndexError):
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment