Enforce album cover image on tracks
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Sat, 5 Aug 2023 01:49:28 +0000 (03:49 +0200)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Sat, 5 Aug 2023 01:49:28 +0000 (03:49 +0200)
music_assistant/server/controllers/media/base.py
music_assistant/server/controllers/media/tracks.py
music_assistant/server/providers/tidal/__init__.py

index 32e82d13ba59cf990803120f2978d1f255b69bbe..a30106ffa0529c1446c9c112e22badada4cfdafe 100644 (file)
@@ -717,4 +717,9 @@ class MediaControllerBase(Generic[ItemCls], metaclass=ABCMeta):
                 "version": db_row_dict["album_version"],
             }
             db_row_dict["album"] = ItemMapping.from_dict(db_row_dict["album"])
+            if db_row_dict["album_metadata"]:
+                # copy album image
+                album_metadata = json_loads(db_row_dict["album_metadata"])
+                if album_metadata and album_metadata["images"]:
+                    db_row_dict["metadata"]["images"] = album_metadata["images"]
         return db_row_dict
index fe4e864203e6afdf53c0975007b92cbd690b611c..7892117dae9e5e6fe673a2dfe9a367c4fc17f2c4 100644 (file)
@@ -137,9 +137,11 @@ class TracksController(MediaControllerBase[Track]):
             and item.album.image
             and item.album.album_type == AlbumType.SINGLE
         ):
-            if not item.metadata.images:
-                item.metadata.images = []
-            item.metadata.images.append(item.album.image)
+            item.metadata.images = item.album.metadata.images
+        elif item.image and isinstance(item.album, Album) and item.image == item.album.image:
+            item.metadata.images = []
+        if item.image and isinstance(item.album, Album) and not item.album.image:
+            item.album.metadata.images = item.metadata.images
         # actually add (or update) the item in the library db
         # use the lock to prevent a race condition of the same item being added twice
         async with self._db_add_lock:
index 9e020e2225c1788fb92edec5d8a086ef6212593d..f6a471558efecae719ada6f8341b75edca3e7ef5 100644 (file)
@@ -616,6 +616,13 @@ class TidalProvider(MusicProvider):
                     track.metadata.lyrics = lyrics_obj.text
             except Exception:
                 self.logger.info(f"Track {track_obj.id} has no available lyrics")
+        if not track.image and track_obj.album and (image_url := track_obj.album.image(640, None)):
+            track.metadata.images = [
+                MediaItemImage(
+                    type=ImageType.THUMB,
+                    path=image_url,
+                )
+            ]
         return track
 
     async def _parse_playlist(