mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-06-06 19:25:34 +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
42 lines
998 B
Python
42 lines
998 B
Python
from dataclasses import asdict
|
|
|
|
from app.models.track import Track
|
|
|
|
|
|
def serialize_track(track: Track, to_remove: set = {}, remove_disc=True) -> dict:
|
|
album_dict = asdict(track)
|
|
props = {
|
|
"date",
|
|
"genre",
|
|
"last_mod",
|
|
"og_title",
|
|
"og_album",
|
|
"copyright",
|
|
"disc",
|
|
"track",
|
|
"artist_hashes",
|
|
}.union(to_remove)
|
|
|
|
if not remove_disc:
|
|
props.remove("disc")
|
|
props.remove("track")
|
|
|
|
props.update(key for key in album_dict.keys() if key.startswith("is_"))
|
|
props.remove("is_favorite")
|
|
|
|
for key in props:
|
|
album_dict.pop(key, None)
|
|
|
|
to_remove_images = ["artists", "albumartists"]
|
|
for key in to_remove_images:
|
|
for artist in album_dict[key]:
|
|
artist.pop("image", None)
|
|
|
|
return album_dict
|
|
|
|
|
|
def serialize_tracks(
|
|
tracks: list[Track], _remove: set = {}, remove_disc=True
|
|
) -> list[dict]:
|
|
return [serialize_track(t, _remove, remove_disc) for t in tracks]
|