From 5c8c770f962290ab5a1e748af04c4f3667d5e1ea Mon Sep 17 00:00:00 2001 From: iou1name Date: Wed, 15 Jan 2025 12:48:45 -0500 Subject: [PATCH] add artists to ui --- database.py | 10 ++++++++++ pyrite.py | 3 ++- static/pyrite.css | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/database.py b/database.py index 62c6640..af5862a 100644 --- a/database.py +++ b/database.py @@ -32,6 +32,16 @@ async def get_random_track(request): return track +async def get_artists(request): + """Returns all artists in the database.""" + async with request.app.state.db_pool.acquire() as conn: + artists = await conn.fetch( + "SELECT DISTINCT albumartist FROM track ORDER BY albumartist" + ) + artists = [a['albumartist'] for a in artists] + return artists + + def convert_filepath(path): """Convert a filepath to a URL.""" path = os.path.relpath(path, config.music_dir) diff --git a/pyrite.py b/pyrite.py index d705a7d..0d53bdb 100644 --- a/pyrite.py +++ b/pyrite.py @@ -23,7 +23,8 @@ templates = Jinja2Templates(directory="templates") @app.get("/", response_class=HTMLResponse) async def index(request: Request): - context = {"request": request} + artists = await db.get_artists(request) + context = {'request': request, 'artists': artists} return templates.TemplateResponse('index.html', context) diff --git a/static/pyrite.css b/static/pyrite.css index ba9d6d0..1d39532 100644 --- a/static/pyrite.css +++ b/static/pyrite.css @@ -57,6 +57,7 @@ input[type="radio"]:checked+div { display: flex; align-items: center; gap: 0.5em; + background-color: white; } .list_item:hover {