migrate homepage items to homepage routine

+ add Mix db model
This commit is contained in:
cwilvx
2024-11-10 19:38:51 +03:00
parent 38d08f07bb
commit 498d0688b0
11 changed files with 292 additions and 442 deletions
-1
View File
@@ -10,7 +10,6 @@ from typing import Any
from PIL import Image, ImageSequence
from app import settings
from app.db.libdata import TrackTable
from app.models.track import Track
from app.store.albums import AlbumStore
from app.store.tracks import TrackStore
+66
View File
@@ -0,0 +1,66 @@
"""
Recipes are a way to create mixes.
"""
from abc import ABC, abstractmethod
from typing import Any, Dict, List
from app.db.userdata import UserTable
from app.models.mix import Mix
from app.plugins.mixes import MixesPlugin
from app.store.homepage import HomepageStore
class HomepageRoutine(ABC):
"""
A routine creates a row of homepage items.
"""
title: str
description: str
items: List[Mix]
extra: Dict[str, Any]
@property
@abstractmethod
def is_valid(self) -> bool: ...
def __init__(self) -> None:
if not self.is_valid:
return
self.items = self.run()
@abstractmethod
def run(self) -> List[Mix]:
"""
Creates the homepage items and saves them to the
homepage store if self.is_valid is true.
"""
...
class ArtistMixes(HomepageRoutine):
items: List[Mix] = []
extra: Dict[str, Any] = {}
store_key = "artist_mixes"
@property
def is_valid(self):
return MixesPlugin().enabled
def run(self):
users = UserTable.get_all()
for user in users:
mix = MixesPlugin()
mixes = mix.create_artist_mixes(user.id)
if not mixes:
continue
HomepageStore.set_mixes(mixes, mixkey=self.store_key, userid=user.id)
def __init__(self) -> None:
super().__init__()