mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
b9ad07441a
+ allow sorting all items with those two + add methods to update scrobble info
38 lines
857 B
Python
38 lines
857 B
Python
from dataclasses import asdict
|
|
from app.models import Album
|
|
|
|
|
|
def album_serializer(album: Album, to_remove: set[str]) -> dict:
|
|
try:
|
|
album_dict = asdict(album)
|
|
except TypeError:
|
|
return {}
|
|
|
|
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",
|
|
"playcount"
|
|
}
|
|
|
|
return album_serializer(album, props_to_remove)
|
|
|
|
|
|
def serialize_for_card_many(albums: list[Album]):
|
|
return [serialize_for_card(a) for a in albums]
|