allowed_audio = ["mp3", "wav", "ogg", "flac"]
allowed_image = ["png", "jpg", "jpeg"]
-id_lock = threading.Lock()
-current_track_id = 1
-
critters_path = os.environ["CRITTERS_PATH"]
audio_path = critters_path + "/audio/"
cover_path = critters_path + "/cover/"
templates_path = critters_path + "/critters-api/templates/"
db_path = critters_path + "/../metadata.db"
+def get_current_track_id():
+ con = sqlite3.connect(db_path)
+ cur = con.cursor()
+ track_id = cur.execute(f"SELECT trackid FROM critters_global WHERE id=1;").fetchone()
+ return track_id[0]
+
+def set_current_track_id(track_id):
+ con = sqlite3.connect(db_path)
+ cur = con.cursor()
+ cur.execute(f"UPDATE critters_global SET trackid = {track_id} WHERE id=1;")
+ con.commit()
+
def check_files(track_id):
return {
"track_path": url_for("get_audio", track_id=track_id),
@app.route("/api/next")
@auth.login_required
def set_current_id():
- global current_track_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,
"outtime": 11
}
- with id_lock:
- track_id = current_track_id
+ track_id = get_current_track_id()
current_album = ""
current_artist = ""
if tracks is not None:
target_index = random.randint(0, len(tracks)-1)
- with id_lock:
- current_track_id = tracks[target_index][0]
+ set_current_track_id(tracks[target_index][0])
for key, i in server_data.items():
server_data[key] = tracks[target_index][i] # See note 1
global current_track_id
if track_id == 0:
- with id_lock:
- track_id = current_track_id
+ track_id = get_current_track_id()
con = sqlite3.connect(db_path)
cur = con.cursor()
track = cur.execute(f"SELECT * FROM critters WHERE id={track_id}").fetchone()
global current_track_id
if track_id == 0:
- with id_lock:
- track_id = current_track_id
+ track_id = get_current_track_id()
result = "Unknown"
if feild in db_keys:
con = sqlite3.connect(db_path)
return send_from_directory(cover_path, "default.png")
if __name__ == "__main__":
- app.run(host='127.0.0.1', port=5000, ssl_context='adhoc')
+ app.run(host='127.0.0.1', port=5000, debug=True)