mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 20:43:04 +00:00
fix: album favorite state, artist and album colors
+ fix: unserialized artist result + misc
This commit is contained in:
+7
-22
@@ -4,7 +4,6 @@ from pprint import pprint
|
||||
import random
|
||||
from typing import Iterable
|
||||
|
||||
from app.db.sqlite.albumcolors import SQLiteAlbumMethods as aldb
|
||||
from app.lib.tagger import create_albums
|
||||
from app.models import Album, Track
|
||||
from app.store.artists import ArtistStore
|
||||
@@ -21,9 +20,9 @@ ALBUM_LOAD_KEY = ""
|
||||
|
||||
|
||||
class AlbumMapEntry:
|
||||
def __init__(self, album: Album) -> None:
|
||||
def __init__(self, album: Album, trackhashes: set[str]) -> None:
|
||||
self.album = album
|
||||
self.trackhashes: set[str] = set()
|
||||
self.trackhashes = trackhashes
|
||||
|
||||
@property
|
||||
def basetitle(self):
|
||||
@@ -40,6 +39,9 @@ class AlbumMapEntry:
|
||||
|
||||
self.album.toggle_favorite_user(userid)
|
||||
|
||||
def set_color(self, color: str):
|
||||
self.album.color = color
|
||||
|
||||
|
||||
class AlbumStore:
|
||||
albums: list[Album] = CustomList()
|
||||
@@ -67,26 +69,9 @@ class AlbumStore:
|
||||
print("Loading albums... ", end="")
|
||||
|
||||
cls.albummap = {
|
||||
album.albumhash: AlbumMapEntry(album=album) for album in create_albums()
|
||||
album.albumhash: AlbumMapEntry(album=album, trackhashes=trackhashes)
|
||||
for album, trackhashes in create_albums()
|
||||
}
|
||||
tracks = remove_duplicates(TrackStore.get_flat_list())
|
||||
tracks = sorted(tracks, key=lambda t: t.albumhash)
|
||||
grouped = groupby(tracks, lambda t: t.albumhash)
|
||||
|
||||
for albumhash, tracks in grouped:
|
||||
cls.albummap[albumhash].trackhashes = {t.trackhash for t in tracks}
|
||||
|
||||
# db_albums: list[tuple] = aldb.get_all_albums()
|
||||
|
||||
# for album in db_albums:
|
||||
# albumhash = album[1]
|
||||
# colors = json.loads(album[2])
|
||||
|
||||
# for _al in cls.albums:
|
||||
# if _al.albumhash == albumhash:
|
||||
# _al.set_colors(colors)
|
||||
# break
|
||||
|
||||
print("Done!")
|
||||
|
||||
@classmethod
|
||||
|
||||
+18
-18
@@ -1,27 +1,22 @@
|
||||
import json
|
||||
from typing import Iterable
|
||||
|
||||
from app.db.sqlite.artistcolors import SQLiteArtistMethods as ardb
|
||||
from app.lib.tagger import create_artists
|
||||
from app.models import Artist
|
||||
from app.utils import flatten
|
||||
from app.utils.auth import get_current_userid
|
||||
from app.utils.bisection import use_bisection
|
||||
from app.utils.customlist import CustomList
|
||||
from app.utils.progressbar import tqdm
|
||||
from .tracks import TrackStore
|
||||
|
||||
# from .albums import AlbumStore
|
||||
from .tracks import TrackStore
|
||||
|
||||
ARTIST_LOAD_KEY = ""
|
||||
|
||||
|
||||
class ArtistMapEntry:
|
||||
def __init__(self, artist: Artist) -> None:
|
||||
def __init__(
|
||||
self, artist: Artist, albumhashes: set[str], trackhashes: set[str]
|
||||
) -> None:
|
||||
self.artist = artist
|
||||
self.albumhashes: set[str] = set()
|
||||
self.trackhashes: set[str] = set()
|
||||
self.albumhashes: set[str] = albumhashes
|
||||
self.trackhashes: set[str] = trackhashes
|
||||
|
||||
def increment_playcount(self, duration: int, timestamp: int):
|
||||
self.artist.lastplayed = timestamp
|
||||
@@ -34,6 +29,9 @@ class ArtistMapEntry:
|
||||
|
||||
self.artist.toggle_favorite_user(userid)
|
||||
|
||||
def set_color(self, color: str):
|
||||
self.artist.color = color
|
||||
|
||||
|
||||
class ArtistStore:
|
||||
artists: list[Artist] = CustomList()
|
||||
@@ -51,17 +49,19 @@ class ArtistStore:
|
||||
cls.artistmap.clear()
|
||||
|
||||
cls.artistmap = {
|
||||
artist.artisthash: ArtistMapEntry(artist=artist)
|
||||
for artist in create_artists()
|
||||
artist.artisthash: ArtistMapEntry(
|
||||
artist=artist, albumhashes=albumhashes, trackhashes=trackhashes
|
||||
)
|
||||
for artist, trackhashes, albumhashes in create_artists()
|
||||
}
|
||||
|
||||
for track in TrackStore.get_flat_list():
|
||||
if instance_key != ARTIST_LOAD_KEY:
|
||||
return
|
||||
# for track in TrackStore.get_flat_list():
|
||||
# if instance_key != ARTIST_LOAD_KEY:
|
||||
# return
|
||||
|
||||
for hash in track.artisthashes:
|
||||
cls.artistmap[hash].trackhashes.add(track.trackhash)
|
||||
cls.artistmap[hash].albumhashes.add(track.albumhash)
|
||||
# for hash in track.artisthashes:
|
||||
# cls.artistmap[hash].trackhashes.add(track.trackhash)
|
||||
# cls.artistmap[hash].albumhashes.add(track.albumhash)
|
||||
|
||||
print("Done!")
|
||||
# for artist in ardb.get_all_artists():
|
||||
|
||||
Reference in New Issue
Block a user