modularize src

+ merge main.py and manage.py
+ move start logic to swingmusic/__main__.py
+ add a run.py on the project root
This commit is contained in:
cwilvx
2025-05-25 20:35:54 +03:00
parent 76fc97e088
commit 86fabcd5e3
171 changed files with 658 additions and 627 deletions
+49
View File
@@ -0,0 +1,49 @@
from dataclasses import asdict
from swingmusic.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)
album_dict["type"] = "album"
return album_dict
def serialize_for_card(album: Album):
props_to_remove = {
"duration",
"count",
"artisthashes",
"albumartists_hashes",
"created_date",
"og_title",
"base_title",
"genres",
"playcount",
"trackcount",
"type",
"playduration",
"genrehashes",
"fav_userids",
"extra",
"id",
"lastplayed",
"weakhash",
}
return album_serializer(album, props_to_remove)
def serialize_for_card_many(albums: list[Album]):
return [serialize_for_card(a) for a in albums]