Fix ambedded image preferred over album image
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Sat, 25 Mar 2023 19:51:02 +0000 (20:51 +0100)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Sat, 25 Mar 2023 19:51:02 +0000 (20:51 +0100)
music_assistant/server/controllers/media/albums.py
music_assistant/server/providers/filesystem_local/base.py

index dd2cdc2685a82ff0e078ef9c159069698ec4ec12..b1c335f237cd11175786ce44831492bf9e76fcb1 100644 (file)
@@ -349,7 +349,7 @@ class AlbumsController(MediaControllerBase[Album]):
         db_album = await self.get_db_item(item_id)
         # simply grab all tracks in the db that are linked to this album
         # TODO: adjust to json query instead of text search?
-        query = f"SELECT * FROM tracks WHERE albums LIKE '%\"{item_id}\"%'"
+        query = 'SELECT * FROM tracks WHERE albums LIKE "item_id":"{item_id}","provider":"database"'
         result = []
         for track in await self.mass.music.tracks.get_db_items_by_query(query):
             if album_mapping := next(
index 4a07009ac820fd32172bc1c4dafd1a7a9c4dcf1f..2949b1a4c68f277955f44f6865f4a31cf098ce0b 100644 (file)
@@ -658,19 +658,20 @@ class FileSystemProviderBase(MusicProvider):
                     artist.musicbrainz_id = tags.musicbrainz_artistids[index]
             track.artists.append(artist)
 
-        # cover image - prefer album image, fallback to embedded
-        if track.album and track.album.image:
-            track.metadata.images = [track.album.image]
-        elif tags.has_cover_image:
+        # cover image - prefer embedded image, fallback to album cover
+        if tags.has_cover_image:
             # we do not actually embed the image in the metadata because that would consume too
             # much space and bandwidth. Instead we set the filename as value so the image can
             # be retrieved later in realtime.
             track.metadata.images = [
                 MediaItemImage(ImageType.THUMB, file_item.path, self.instance_id)
             ]
-            if track.album:
-                # set embedded cover on album
-                track.album.metadata.images = track.metadata.images
+        elif track.album.image:
+            track.metadata.images = [track.album.image]
+
+        if track.album and not track.album.metadata.images:
+            # set embedded cover on album if it does not have one yet
+            track.album.metadata.images = track.metadata.images
 
         # parse other info
         track.duration = tags.duration or 0