From 1f0966509ccb746a208dae9bd7255b63e4bed850 Mon Sep 17 00:00:00 2001 From: Max Value Date: Mon, 9 Dec 2024 23:48:54 +0000 Subject: [PATCH] Added tracknumber and deleting files when track deleted --- critters.py | 25 ++++++++++++++++++++----- schema | 1 + static/admin.js | 2 +- templates/admin.html | 4 ++++ 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/critters.py b/critters.py index 24b4f21..3472b0c 100755 --- a/critters.py +++ b/critters.py @@ -90,11 +90,12 @@ def admin(): cur.execute(f""" INSERT INTO critters - (id, title, album, artist, year, link, info, category, playing, intime, outtime) + (id, title, album, tracknumber, artist, year, link, info, category, playing, intime, outtime) VALUES ( {commit_id}, '{request.form["title"]}', '{request.form["album"]}', + '{request.form["tracknumber"]}', '{request.form["artist"]}', '{request.form["year"]}', '{request.form["link"]}', @@ -109,10 +110,21 @@ def admin(): else: if "delete" in request.form: + + for f in [ + f"{audio_path}{request.form['id']}.mp3", + f"{audio_path}{request.form['id']}-front.mp3", + f"{audio_path}{request.form['id']}-back.mp3", + f"{cover_path}{request.form['id']}.png", + f"{icon_path}{request.form['id']}.png", + ]: + if os.path.exists(f): + os.remove(f) + cur.execute(f"DELETE FROM critters WHERE id={request.form['id']};") con.commit() - con.close() + return "" else: @@ -120,6 +132,7 @@ def admin(): UPDATE critters SET title = '{request.form["title"]}', album = '{request.form["album"]}', + tracknumber = '{request.form["tracknumber"]}', artist = '{request.form["artist"]}', year = '{request.form["year"]}', link = '{request.form["link"]}', @@ -180,9 +193,9 @@ def set_current_id(): server_data = { # The value for each of the keys is the position in the database columns that peice of data can be found "id": 0, # (Note 1) "title": 1, - "artist": 3, - "intime": 9, - "outtime": 10 + "artist": 4, + "intime": 10, + "outtime": 11 } with current_track_id.get_lock(): # Lock for entire function @@ -227,6 +240,7 @@ def get_tracks(): "id": 0, "title": "Unknown", "album": "Unknown", + "tracknumber": "1", "artist": "Unknown", "year": "Unknown", "link": "https://treecritters.bandcamp.com", @@ -257,6 +271,7 @@ def get_single_track(track_id): "id": 0, "title": "Unknown", "album": "Unknown", + "tracknumber": "1", "artist": "Unknown", "year": "Unknown", "link": "https://treecritters.bandcamp.com", diff --git a/schema b/schema index e9b93f8..fb6c3d3 100644 --- a/schema +++ b/schema @@ -2,6 +2,7 @@ CREATE TABLE critters ( id INTEGER PRIMARY KEY, title TEXT, album TEXT, + tracknumber TEXT, artist TEXT, year TEXT, link TEXT, diff --git a/static/admin.js b/static/admin.js index 7693cf3..948f160 100644 --- a/static/admin.js +++ b/static/admin.js @@ -59,7 +59,7 @@ function getTrackList () { ${track.id} ${track.title} - ${track.album} + ${track.album} (track ${track.tracknumber}) ${track.artist} ${track.category} ${trackPlaying} diff --git a/templates/admin.html b/templates/admin.html index 9951809..d029c9b 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -73,6 +73,10 @@ th { + + + + -- 2.39.2