Skip to content

Commit

Permalink
Fix (album) images for track listings (#1586)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt authored Aug 21, 2024
1 parent ce72dbe commit 4643e88
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
21 changes: 11 additions & 10 deletions music_assistant/server/controllers/media/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

ItemCls = TypeVar("ItemCls", bound="MediaItemType")

JSON_KEYS = ("artists", "album", "metadata", "provider_mappings", "external_ids", "albums")
JSON_KEYS = ("artists", "track_album", "metadata", "provider_mappings", "external_ids")

SORT_KEYS = {
"name": "name COLLATE NOCASE ASC",
Expand Down Expand Up @@ -815,13 +815,14 @@ def _parse_db_row(db_row: Mapping) -> dict[str, Any]:
continue
db_row_dict[key] = json_loads(raw_value)

# copy albums --> album
if albums := db_row_dict.get("albums"):
db_row_dict["album"] = albums[0]
db_row_dict["disc_number"] = albums[0]["disc_number"]
db_row_dict["track_number"] = albums[0]["disc_number"]

# copy album image to itemmapping single image
if (album := db_row_dict.get("album")) and (images := album.get("images")):
db_row_dict["album"]["image"] = next((x for x in images if x["type"] == "thumb"), None)
# copy track_album --> album
if track_album := db_row_dict.get("track_album"):
db_row_dict["album"] = track_album
db_row_dict["disc_number"] = track_album["disc_number"]
db_row_dict["track_number"] = track_album["disc_number"]
# copy album image to itemmapping single image
if images := track_album.get("images"):
db_row_dict["album"]["image"] = next(
(x for x in images if x["type"] == "thumb"), None
)
return db_row_dict
7 changes: 4 additions & 3 deletions music_assistant/server/controllers/media/tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,17 @@ def __init__(self, *args, **kwargs) -> None:
'sort_name', artists.sort_name,
'media_type', 'artist'
)) FROM artists JOIN track_artists on track_artists.track_id = tracks.item_id WHERE artists.item_id = track_artists.artist_id) AS artists,
(SELECT JSON_GROUP_ARRAY(
(SELECT
json_object(
'item_id', albums.item_id,
'provider', 'library',
'name', albums.name,
'sort_name', albums.sort_name,
'media_type', 'album',
'disc_number', album_tracks.disc_number,
'track_number', album_tracks.track_number
)) FROM albums JOIN album_tracks on album_tracks.track_id = tracks.item_id WHERE albums.item_id = album_tracks.album_id) AS albums
'track_number', album_tracks.track_number,
'images', json_extract(albums.metadata, '$.images')
) FROM albums JOIN album_tracks on album_tracks.track_id = tracks.item_id WHERE albums.item_id = album_tracks.album_id) AS track_album
FROM tracks""" # noqa: E501
# register (extra) api handlers
api_base = self.api_base
Expand Down

0 comments on commit 4643e88

Please sign in to comment.