first recommendation draft

This commit is contained in:
cwilvx
2024-10-25 23:26:08 +03:00
parent a26373669d
commit c4a73f0d63
15 changed files with 393 additions and 6 deletions
+2
View File
@@ -14,6 +14,7 @@ from app.config import UserConfig
from app.db.userdata import UserTable
from app.settings import Info as AppInfo
from .plugins import lyrics as lyrics_plugin
from .plugins import mixes as mixes_plugin
from app.api import (
album,
artist,
@@ -113,6 +114,7 @@ def create_api():
# Plugins
app.register_api(plugins.api)
app.register_api(lyrics_plugin.api)
app.register_api(mixes_plugin.api)
# Logger
app.register_api(scrobble.api)
+13
View File
@@ -5,6 +5,7 @@ from flask_openapi3 import APIBlueprint
from app.api.apischemas import GenericLimitSchema
from app.lib.home.recentlyadded import get_recently_added_items
from app.lib.home.recentlyplayed import get_recently_played
from app.store.homepage import HomepageStore
bp_tag = Tag(name="Home", description="Homepage items")
api = APIBlueprint("home", __name__, url_prefix="/home", abp_tags=[bp_tag])
@@ -24,3 +25,15 @@ def get_recent_plays(query: GenericLimitSchema):
Get recently played
"""
return {"items": get_recently_played(query.limit)}
@api.get("/")
def homepage_items():
return {
"artist_mixes": {
"title": "Artist mixes for you",
"description": "Curated based on artists you have played in the past",
"items": HomepageStore.get_artist_mixes(),
"extra": {},
},
}
+63
View File
@@ -0,0 +1,63 @@
from flask_openapi3 import Tag
from flask_openapi3 import APIBlueprint
from pydantic import BaseModel, Field
from app.plugins.mixes import MixesPlugin
from app.store.homepage import HomepageStore
from app.store.tracks import TrackStore
bp_tag = Tag(name="Mixes Plugin", description="Mixes plugin hehe")
api = APIBlueprint(
"mixesplugin", __name__, url_prefix="/plugins/mixes", abp_tags=[bp_tag]
)
@api.post("/track")
def get_track_mix():
"""
Get a track mix
"""
mixes = MixesPlugin()
track = TrackStore.trackhashmap["9eeee292264ad01b"].get_best()
tracks = mixes.get_track_mix(track)
return {
"total": len(tracks),
"tracks": tracks,
}
@api.post("/artist")
def get_artist_mix():
mixes = MixesPlugin()
return mixes.get_artists()
# tracks = mixes.get_artist_mix("09306be8039b98ad")
# return {
# "total": len(tracks),
# "tracks": tracks,
# }
return "hi"
class MixQuery(BaseModel):
mixid: str = Field(description="The mix id")
@api.get("/")
def get_mix(query: MixQuery):
mixtype = ""
match query.mixid[0]:
case "a":
mixtype = "artist_mixes"
case _:
raise ValueError(f"Invalid mix ID: {query.mixid}")
mix = HomepageStore.get_mix(mixtype, query.mixid[1:])
if mix:
return mix, 200
return {"msg": "Mix not found"}, 404