mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-06-11 05:27:21 +00:00

+ fix help text + run populate once when -nps flag is used + update app version + sort tracks by track and disc no. when saving to playlist + serialize search results + update tags.artist -> tags.artists + update tags.albumartist -> tags.albumartists + remove artist images from serialized albums + add function to serialize artists for cards + misc
34 lines
784 B
Python
34 lines
784 B
Python
from dataclasses import asdict
|
|
from app.models import Album
|
|
|
|
|
|
def album_serializer(album: Album, to_remove: set[str]) -> dict:
|
|
album_dict = asdict(album)
|
|
|
|
to_remove.update(key for key in album_dict.keys() if key.startswith("is_"))
|
|
for key in to_remove:
|
|
album_dict.pop(key, None)
|
|
|
|
# remove artist images
|
|
for artist in album_dict["albumartists"]:
|
|
artist.pop("image", None)
|
|
|
|
return album_dict
|
|
|
|
|
|
def serialize_for_card(album: Album):
|
|
props_to_remove = {
|
|
"duration",
|
|
"count",
|
|
"albumartists_hashes",
|
|
"og_title",
|
|
"base_title",
|
|
"genres",
|
|
}
|
|
|
|
return album_serializer(album, props_to_remove)
|
|
|
|
|
|
def serialize_for_card_many(albums: list[Album]):
|
|
return [serialize_for_card(a) for a in albums]
|