minor edits

This commit is contained in:
cwilvx
2024-10-29 01:57:01 +03:00
parent f6373292aa
commit 2ee501cc64
3 changed files with 20 additions and 17 deletions
+3 -1
View File
@@ -13,7 +13,6 @@ class Mix:
title: str title: str
description: str description: str
tracks: list[str] tracks: list[str]
image: dict
timestamp: int = field(default_factory=lambda: int(time.time())) timestamp: int = field(default_factory=lambda: int(time.time()))
extra: dict = field(default_factory=dict) extra: dict = field(default_factory=dict)
@@ -25,7 +24,10 @@ class Mix:
_dict = asdict(self) _dict = asdict(self)
_dict["tracks"] = serialized_tracks _dict["tracks"] = serialized_tracks
if not self.extra.get("image"):
_dict["images"] = get_first_4_images(tracks) _dict["images"] = get_first_4_images(tracks)
_dict["duration"] = seconds_to_time_string(sum(t.duration for t in tracks)) _dict["duration"] = seconds_to_time_string(sum(t.duration for t in tracks))
_dict["trackcount"] = len(tracks) _dict["trackcount"] = len(tracks)
+10 -11
View File
@@ -96,7 +96,7 @@ class MixesPlugin(Plugin):
return self.get_track_mix(tracks[: self.MAX_TRACKS_TO_FETCH]) return self.get_track_mix(tracks[: self.MAX_TRACKS_TO_FETCH])
@plugin_method @plugin_method
def create_artist_mixes(self, limit: int = 10): def create_artist_mixes(self):
mixes: list[Mix] = [] mixes: list[Mix] = []
indexed = set() indexed = set()
@@ -107,7 +107,7 @@ class MixesPlugin(Plugin):
artists = { artists = {
"today": { "today": {
"max": 2, "max": 3,
"artists": get_artists_in_period(today_start, today_end), "artists": get_artists_in_period(today_start, today_end),
"created": 0, "created": 0,
}, },
@@ -178,30 +178,30 @@ class MixesPlugin(Plugin):
""" """
Given an artist dict, creates an artist mix. 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"]) _artist = ArtistStore.get_artist_by_hash(artist["artisthash"])
if not _artist: if not _artist:
return None return None
mix_tracks = self.get_artist_mix(artist["artisthash"])
if len(mix_tracks) < self.MIN_TRACK_MIX_LENGTH:
return None
return Mix( return Mix(
# the a prefix indicates that this is an artist mix # the a prefix indicates that this is an artist mix
id=f"a{artist['artisthash']}", id=f"a{artist['artisthash']}",
title=artist["artist"], title=artist["artist"] + " Radio",
description=self.get_mix_description(mix_tracks, artist["artisthash"]), description=self.get_mix_description(mix_tracks, artist["artisthash"]),
tracks=[t.trackhash for t in mix_tracks], tracks=[t.trackhash for t in mix_tracks],
extra={ extra={
"type": "artist", "type": "artist",
"artisthash": artist["artisthash"], "artisthash": artist["artisthash"],
}, "image": {
image={
"image": _artist.image, "image": _artist.image,
"color": _artist.color, "color": _artist.color,
}, },
},
) )
def fallback_create_artist_mix( def fallback_create_artist_mix(
@@ -243,4 +243,3 @@ class MixesPlugin(Plugin):
# Since the artisthashes are ordered by similarity score, we iterate from the start # 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. # and go forward collecting tracks that aren't in the mix yet.
# #
+2
View File
@@ -10,6 +10,8 @@ class HomepageStore:
@classmethod @classmethod
def set_artist_mixes(cls, mixes: list[Mix], userid: int = 1): 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} idmap = {mix.id: mix for mix in mixes}
cls.entries["artist_mixes"][userid] = idmap cls.entries["artist_mixes"][userid] = idmap