mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-06-07 03:35:35 +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
44 lines
1.0 KiB
Python
44 lines
1.0 KiB
Python
"""
|
|
Contains methods relating to albums.
|
|
"""
|
|
|
|
from dataclasses import asdict
|
|
from typing import Any
|
|
|
|
from alive_progress import alive_bar
|
|
|
|
from app.logger import log
|
|
from app.models.track import Track
|
|
from app.store.albums import AlbumStore
|
|
from app.store.tracks import TrackStore
|
|
|
|
|
|
def validate_albums():
|
|
"""
|
|
Removes albums that have no tracks.
|
|
|
|
Probably albums that were added from incompletely written files.
|
|
"""
|
|
|
|
album_hashes = {t.albumhash for t in TrackStore.tracks}
|
|
albums = AlbumStore.albums
|
|
|
|
with alive_bar(len(albums)) as bar:
|
|
log.info("Validating albums")
|
|
for album in albums:
|
|
if album.albumhash not in album_hashes:
|
|
AlbumStore.remove_album(album)
|
|
bar()
|
|
|
|
|
|
def sort_by_track_no(tracks: list[Track]) -> list[dict[str, Any]]:
|
|
tracks = [asdict(t) for t in tracks]
|
|
|
|
for t in tracks:
|
|
track = str(t["track"]).zfill(3)
|
|
t["_pos"] = int(f"{t['disc']}{track}")
|
|
|
|
tracks = sorted(tracks, key=lambda t: t["_pos"])
|
|
|
|
return tracks
|