Skip to content

Commit

Permalink
Enforce album cover image on tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Aug 5, 2023
1 parent 35ff39f commit a49621e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions music_assistant/server/controllers/media/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,4 +717,9 @@ def _parse_db_row(db_row: Mapping) -> dict[str, Any]:
"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
8 changes: 5 additions & 3 deletions music_assistant/server/controllers/media/tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,11 @@ async def add_item_to_library(self, item: Track, metadata_lookup: bool = True) -
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:
Expand Down
7 changes: 7 additions & 0 deletions music_assistant/server/providers/tidal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,13 @@ async def _parse_track(
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(
Expand Down

0 comments on commit a49621e

Please sign in to comment.