]> OzVa Git service - critters-api/commitdiff
Added tracknumber and deleting files when track deleted
authorMax Value <greenwoodw50@gmail.com>
Mon, 9 Dec 2024 23:48:54 +0000 (23:48 +0000)
committerMax Value <greenwoodw50@gmail.com>
Mon, 9 Dec 2024 23:48:54 +0000 (23:48 +0000)
critters.py
schema
static/admin.js
templates/admin.html

index 24b4f2156f3bc97139628a70debb133d86e6ecf2..3472b0cb24c5a8cd0e39bafa2a907693b3354237 100755 (executable)
@@ -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 e9b93f814d506b1f4e40f243ce6826ff1272ffdf..fb6c3d3e12b4c86bb0bf105fcd8ff1b25b9980e4 100644 (file)
--- 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,
index 7693cf3c3d6f31601738acfc2d1e0eaef747fbae..948f160fa498a208d068aa9e40657c81a7f37493 100644 (file)
@@ -59,7 +59,7 @@ function getTrackList () {
                     <td><img class="smallIcon" src="${track.icon_path}" /></td>
                     <td>${track.id}</td>
                     <td>${track.title}</td>
-                    <td>${track.album}</td>
+                    <td>${track.album} (track ${track.tracknumber})</td>
                     <td>${track.artist}</td>
                     <td>${track.category}</td>
                     <td>${trackPlaying}</td>
index 99518096260b40dcd5671c53de6773edf51e8da6..d029c9b92e971395c7536ac3db970f600f07e909 100644 (file)
@@ -73,6 +73,10 @@ th {
                         <td><label for="album">Album</label></td>
                         <td><input type="text" id="album" class="mainForm" name="album"></input></td>
                     </tr>
+                    <tr>
+                        <td><label for="tracknumber">Track number</label></td>
+                        <td><input type="text" id="tracknumber" class="mainForm" name="tracknumber"></input></td>
+                    </tr>
                     <tr>
                         <td><label for="artist">Artist</label></td>
                         <td><input type="text" id="artist" class="mainForm" name="artist"></input></td>