mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
98720466aa
+ add: get mixes + handle mixes on recently played + move modules around to fix circular deps
82 lines
2.7 KiB
Python
82 lines
2.7 KiB
Python
from typing import Any
|
|
|
|
from app.store.homepageentries import (
|
|
BecauseYouListenedToArtistHomepageEntry,
|
|
GenericRecoverableEntry,
|
|
HomepageEntry,
|
|
MixHomepageEntry,
|
|
RecentlyAddedHomepageEntry,
|
|
RecentlyPlayedHomepageEntry,
|
|
)
|
|
from app.utils.auth import get_current_userid
|
|
|
|
|
|
class HomepageStore:
|
|
"""
|
|
Stores the homepage items.
|
|
"""
|
|
|
|
entries: dict[str, HomepageEntry] = {
|
|
"recently_played": RecentlyPlayedHomepageEntry(
|
|
title="Recently played",
|
|
),
|
|
"artist_mixes": MixHomepageEntry(
|
|
title="Artist mixes for you",
|
|
description="Based on artists you have been listening to",
|
|
),
|
|
"custom_mixes": MixHomepageEntry(
|
|
title="Mixes for you",
|
|
description="Because artist mixes alone aren't enough",
|
|
),
|
|
"top_streamed_weekly_artists": GenericRecoverableEntry(
|
|
title="Top artists this week",
|
|
description="Your most played artists since Monday",
|
|
),
|
|
"top_streamed_monthly_artists": GenericRecoverableEntry(
|
|
title="Top artists this month",
|
|
description="Your most played artists since the start of the month",
|
|
),
|
|
"because_you_listened_to_artist": BecauseYouListenedToArtistHomepageEntry(
|
|
title="",
|
|
description="Artists similar to the artist you listened to",
|
|
),
|
|
"artists_you_might_like": BecauseYouListenedToArtistHomepageEntry(
|
|
title="Artists you might like",
|
|
description="Artists similar to the artists you have listened to",
|
|
),
|
|
"recently_added": RecentlyAddedHomepageEntry(
|
|
title="Recently added",
|
|
description="New music added to your library",
|
|
),
|
|
}
|
|
|
|
@classmethod
|
|
def set_mixes(cls, items: list[Any], entrykey: str, userid: int | None = None):
|
|
idmap = {item.id: item for item in items}
|
|
cls.entries[entrykey].items[userid or get_current_userid()] = idmap
|
|
|
|
@classmethod
|
|
def get_mix(cls, mixkey: str, mixid: str):
|
|
mix = cls.entries[mixkey].items.get(get_current_userid(), {}).get(mixid)
|
|
return mix.to_full_dict() if mix else None
|
|
|
|
@classmethod
|
|
def get_homepage_items(cls, limit: int):
|
|
# return a dict of entry name to entry items
|
|
return [
|
|
{entry: cls.entries[entry].get_items(get_current_userid(), limit)}
|
|
for entry in cls.entries.keys()
|
|
if len(cls.entries[entry].items)
|
|
]
|
|
|
|
@classmethod
|
|
def find_mix(cls, mixid: str):
|
|
mixentries = ["artist_mixes", "custom_mixes"]
|
|
|
|
for entry in mixentries:
|
|
mix = cls.entries[entry].items.get(get_current_userid(), {}).get(mixid)
|
|
if mix:
|
|
return mix
|
|
|
|
return None
|