mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 04:53:01 +00:00
migrate homepage items to homepage routine
+ add Mix db model
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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__()
|
||||
Reference in New Issue
Block a user