mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-07-29 15:13:46 +00:00
Reorganize repository structure for better organization
- Move backend code to swingmusic/ folder - Move client applications to root level (swingmusic-android, swingmusic-desktop, swingmusic-webclient) - Remove intermediate backend/ and clients/ folders - Update README with new folder structure and setup instructions - Clean and organized repository layout
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
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]
|
||||
@@ -1,42 +0,0 @@
|
||||
from dataclasses import asdict
|
||||
|
||||
from swingmusic.models.artist import Artist
|
||||
|
||||
|
||||
def serialize_for_card(artist: Artist, include: set[str] = set()):
|
||||
try:
|
||||
artist_dict = asdict(artist)
|
||||
except TypeError:
|
||||
return {}
|
||||
|
||||
props_to_remove = {
|
||||
"is_favorite",
|
||||
"trackcount",
|
||||
"duration",
|
||||
"albumcount",
|
||||
"playcount",
|
||||
"playduration",
|
||||
"playcount",
|
||||
"lastplayed",
|
||||
"id",
|
||||
"genres",
|
||||
"genrehashes",
|
||||
"extra",
|
||||
"created_date",
|
||||
"date",
|
||||
"fav_userids",
|
||||
"_score",
|
||||
}
|
||||
|
||||
if include:
|
||||
props_to_remove = props_to_remove - include
|
||||
|
||||
for key in props_to_remove:
|
||||
artist_dict.pop(key, None)
|
||||
|
||||
artist_dict["type"] = "artist"
|
||||
return artist_dict
|
||||
|
||||
|
||||
def serialize_for_cards(artists: list[Artist]):
|
||||
return [serialize_for_card(a) for a in artists]
|
||||
@@ -1,13 +0,0 @@
|
||||
from dataclasses import asdict
|
||||
from swingmusic.models.playlist import Playlist
|
||||
|
||||
|
||||
def serialize_for_card(playlist: Playlist, to_remove=set()):
|
||||
p_dict = asdict(playlist)
|
||||
|
||||
props = {"trackhashes"}.union(to_remove)
|
||||
|
||||
for key in props:
|
||||
p_dict.pop(key, None)
|
||||
|
||||
return p_dict
|
||||
@@ -1,64 +0,0 @@
|
||||
from dataclasses import asdict
|
||||
|
||||
from swingmusic.models.track import Track
|
||||
|
||||
|
||||
def serialize_track(track: Track, to_remove:set=set(), remove_disc:bool=True) -> dict:
|
||||
"""
|
||||
Convert `Track` to dict
|
||||
|
||||
:params track: Track to convert
|
||||
:params to_remove: custom tags which should also be removed from Track.
|
||||
:params remove_disc:
|
||||
"""
|
||||
album_dict = asdict(track)
|
||||
album_keys = ( key for key in album_dict.keys() if key.startswith(("is_", "_")) )
|
||||
# add all keys from album_dict starting with "is_" or "_"
|
||||
|
||||
props = {
|
||||
"date",
|
||||
"genre",
|
||||
"last_mod",
|
||||
"og_title",
|
||||
"og_album",
|
||||
"copyright",
|
||||
"config",
|
||||
"artist_hashes",
|
||||
"created_date",
|
||||
"fav_userids",
|
||||
"playcount",
|
||||
"genrehashes",
|
||||
"id",
|
||||
"lastplayed",
|
||||
"playduration",
|
||||
"genres",
|
||||
*to_remove,
|
||||
*album_keys,
|
||||
}
|
||||
|
||||
if remove_disc:
|
||||
props.add("disc")
|
||||
props.add("track")
|
||||
|
||||
|
||||
for key in props:
|
||||
album_dict.pop(key, None)
|
||||
|
||||
# remove images
|
||||
for key in ["artists", "albumartists"]:
|
||||
for artist in album_dict[key]:
|
||||
artist.pop("image", None)
|
||||
|
||||
# is_favorite @property is not included in `asdict`
|
||||
album_dict["is_favorite"] = track.is_favorite
|
||||
|
||||
return album_dict
|
||||
|
||||
|
||||
def serialize_tracks(tracks: list[Track], _remove: set = set(), remove_disc=True) -> list[dict]:
|
||||
"""
|
||||
wrapper for iterable type with Tracks.
|
||||
convert Tracks to dict and return as list[dict]
|
||||
"""
|
||||
|
||||
return [serialize_track(t, _remove, remove_disc) for t in tracks]
|
||||
Reference in New Issue
Block a user