From 2ee501cc6467ca4d173c612e212ef9a8de3e5c6a Mon Sep 17 00:00:00 2001 From: cwilvx Date: Tue, 29 Oct 2024 01:57:01 +0300 Subject: [PATCH] minor edits --- app/models/mix.py | 6 ++++-- app/plugins/mixes.py | 29 ++++++++++++++--------------- app/store/homepage.py | 2 ++ 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/app/models/mix.py b/app/models/mix.py index 9af84e7a..0eb4efd2 100644 --- a/app/models/mix.py +++ b/app/models/mix.py @@ -13,7 +13,6 @@ class Mix: title: str description: str tracks: list[str] - image: dict timestamp: int = field(default_factory=lambda: int(time.time())) extra: dict = field(default_factory=dict) @@ -25,7 +24,10 @@ class Mix: _dict = asdict(self) _dict["tracks"] = serialized_tracks - _dict["images"] = get_first_4_images(tracks) + + if not self.extra.get("image"): + _dict["images"] = get_first_4_images(tracks) + _dict["duration"] = seconds_to_time_string(sum(t.duration for t in tracks)) _dict["trackcount"] = len(tracks) diff --git a/app/plugins/mixes.py b/app/plugins/mixes.py index 8aaafad5..806e61bd 100644 --- a/app/plugins/mixes.py +++ b/app/plugins/mixes.py @@ -42,8 +42,8 @@ class MixesPlugin(Plugin): :param with_help: Whether to include the help flag in the query. The flag tells the server to find more data using other tracks from the same album. - - + + """ queries = [ { @@ -96,7 +96,7 @@ class MixesPlugin(Plugin): return self.get_track_mix(tracks[: self.MAX_TRACKS_TO_FETCH]) @plugin_method - def create_artist_mixes(self, limit: int = 10): + def create_artist_mixes(self): mixes: list[Mix] = [] indexed = set() @@ -107,7 +107,7 @@ class MixesPlugin(Plugin): artists = { "today": { - "max": 2, + "max": 3, "artists": get_artists_in_period(today_start, today_end), "created": 0, }, @@ -178,29 +178,29 @@ class MixesPlugin(Plugin): """ Given an artist dict, creates an artist mix. """ - mix_tracks = self.get_artist_mix(artist["artisthash"]) - - if len(mix_tracks) < self.MIN_TRACK_MIX_LENGTH: - return None - _artist = ArtistStore.get_artist_by_hash(artist["artisthash"]) if not _artist: return None + mix_tracks = self.get_artist_mix(artist["artisthash"]) + + if len(mix_tracks) < self.MIN_TRACK_MIX_LENGTH: + return None + return Mix( # the a prefix indicates that this is an artist mix id=f"a{artist['artisthash']}", - title=artist["artist"], + title=artist["artist"] + " Radio", description=self.get_mix_description(mix_tracks, artist["artisthash"]), tracks=[t.trackhash for t in mix_tracks], extra={ "type": "artist", "artisthash": artist["artisthash"], - }, - image={ - "image": _artist.image, - "color": _artist.color, + "image": { + "image": _artist.image, + "color": _artist.color, + }, }, ) @@ -243,4 +243,3 @@ class MixesPlugin(Plugin): # Since the artisthashes are ordered by similarity score, we iterate from the start # and go forward collecting tracks that aren't in the mix yet. # - \ No newline at end of file diff --git a/app/store/homepage.py b/app/store/homepage.py index 5691fb62..380d745a 100644 --- a/app/store/homepage.py +++ b/app/store/homepage.py @@ -10,6 +10,8 @@ class HomepageStore: @classmethod def set_artist_mixes(cls, mixes: list[Mix], userid: int = 1): + print(f"⭐⭐⭐⭐ Setting {len(mixes)} artist mixes") + print("mix artists", [mix.title for mix in mixes]) idmap = {mix.id: mix for mix in mixes} cls.entries["artist_mixes"][userid] = idmap