SQLite is Completely done, json is not used at all anymore

This commit is contained in:
Kristy Fournier 2025-07-06 12:46:01 -04:00
parent 488f426d02
commit ea183794c1
4 changed files with 57 additions and 24 deletions

1
.gitignore vendored
View file

@ -1,4 +1,3 @@
server/sound/ server/sound/
server/songDatabase.json
*.db *.db
start.bat start.bat

View file

@ -314,9 +314,9 @@ document.addEventListener('keydown', function(e){
document.getElementById("playlist-mode").style.display = "none"; document.getElementById("playlist-mode").style.display = "none";
document.getElementById("settings-mode").style.display = "none"; document.getElementById("settings-mode").style.display = "none";
//.ontouch for mobile?? //.ontouch for mobile??
document.getElementById("volumerange").onchange = function() { document.getElementById("volumerange").onchange = async function() {
let returnValue = getFromServer({setting:"volume",level:this.value}, "settings") let returnValue = await getFromServer({setting:"volume",level:this.value}, "settings")
if (returnValue !=0) { if (returnValue["volumePassed"] !=0) {
alertText("Nothing is playing") alertText("Nothing is playing")
document.getElementById("volumerange").value = -1 document.getElementById("volumerange").value = -1
} }

View file

@ -2,7 +2,7 @@ import os
from mutagen.easyid3 import EasyID3 from mutagen.easyid3 import EasyID3
from mutagen.mp3 import MP3 from mutagen.mp3 import MP3
import sqlite3 as sql import sqlite3 as sql
import requests, ast, time, math, argparse, json import requests, ast, time, math, argparse
loading = ["-","\\","|","/"] loading = ["-","\\","|","/"]

View file

@ -1,7 +1,8 @@
from flask import Flask from flask import Flask
from flask import request from flask import request
from flask_cors import CORS from flask_cors import CORS
import json,vlc,threading,time,random, argparse import sqlite3 as sql
import vlc,threading,time,random, argparse
# Argparse Stuff # Argparse Stuff
parser=argparse.ArgumentParser(description="Options for the Webby Bits") parser=argparse.ArgumentParser(description="Options for the Webby Bits")
# this is no longer needed assuming my file works correctly with the generator # this is no longer needed assuming my file works correctly with the generator
@ -9,10 +10,12 @@ parser=argparse.ArgumentParser(description="Options for the Webby Bits")
parser.add_argument('-p','--port',help="Port to host on, not the same as the web (client) port",default='19054') parser.add_argument('-p','--port',help="Port to host on, not the same as the web (client) port",default='19054')
portTheUserPicked=parser.parse_args().port portTheUserPicked=parser.parse_args().port
# open the json file as a dictionary fileofDB = sql.connect("songDatabase.db")
with open('./songDatabase.json', 'r') as handle: songDatabase = fileofDB.cursor()
songDatabaseList = json.load(handle)
soundLocation = songDatabaseList["songDirectory"] #song directory
songDatabase.execute("SELECT * FROM meta WHERE id='songDirectory';")
soundLocation = songDatabase.fetchall()[0][1]
if soundLocation[-1] == "/" or soundLocation[-1] == "\\": if soundLocation[-1] == "/" or soundLocation[-1] == "\\":
pass pass
@ -20,6 +23,12 @@ elif "/" in soundLocation:
soundLocation += "/" soundLocation += "/"
else: else:
soundLocation += "\\" soundLocation += "\\"
#Create Virtual table for searching
songDatabase.execute("DROP TABLE virtualSongs;")
songDatabase.execute("CREATE VIRTUAL TABLE virtualSongs USING fts5(filename, title, artist, art, length);")
songDatabase.execute("INSERT INTO virtualSongs SELECT * FROM songs;")
fileofDB.commit()
fileofDB.close()
#Initializing all the global stuff #Initializing all the global stuff
random.seed() random.seed()
global partyMode global partyMode
@ -115,21 +124,27 @@ def settingsControl():
@app.route("/search", methods=['POST']) @app.route("/search", methods=['POST'])
def searchSongDB(): def searchSongDB():
recieveData=request.get_json(force=True) recieveData=request.get_json(force=True)
tempData = {} fileofDB = sql.connect("songDatabase.db")
songDatabase = fileofDB.cursor()
results = []
if (recieveData['search'] == ""): if (recieveData['search'] == ""):
tempData = songDatabaseList["songData"].copy() songDatabase.execute("SELECT * FROM virtualSongs")
results = songDatabase.fetchall()
else: else:
for i in songDatabaseList["songData"]: songDatabase.execute("SELECT * FROM virtualSongs WHERE virtualSongs MATCH ?",[recieveData['search']])
if ((songDatabaseList["songData"][i]["title"].lower().find(recieveData['search'].lower())) > -1): results = songDatabase.fetchall()
tempData[i] = songDatabaseList["songData"][i] tempdata = {}
# this is a temporary solution so i dont have to change the
try: for i in results:
if (songDatabaseList["songData"][i]["artist"].lower().find(recieveData['search'].lower()) > -1): tempdata[i[0]] = {
tempData[i] = songDatabaseList["songData"][i] "title": i[1],
except: "artist": i[2],
pass "art": i[3],
"length": i[4]
}
# print(tempData) # print(tempData)
return tempData fileofDB.close()
return tempdata
@app.route("/songadd", methods=["POST"]) @app.route("/songadd", methods=["POST"])
def songadd(): def songadd():
@ -139,17 +154,36 @@ def songadd():
@app.route("/playlist", methods=["POST"]) @app.route("/playlist", methods=["POST"])
def getPlaylist(): def getPlaylist():
global songNext global songNext
fileofDB = sql.connect("songDatabase.db")
songDatabase = fileofDB.cursor()
tempPlaylist = [] tempPlaylist = []
if songNext != None: if songNext != None:
# Adds the currently playing song # Adds the currently playing song
k = songDatabaseList["songData"][songNext] songDatabase.execute("SELECT * FROM songs WHERE filename = ?",[songNext])
result = songDatabase.fetchall()[0]
# again, this is still using the old JSON format to avoid client changes
k = {
"title": result[1],
"artist": result[2],
"art": result[3],
"length": result[4]
}
temp = k.copy() temp = k.copy()
temp["playing"] = True temp["playing"] = True
temp["time"] = player.get_time()/1000 temp["time"] = player.get_time()/1000
tempPlaylist.append({songNext:temp}) tempPlaylist.append({songNext:temp})
for i in playlist: for i in playlist:
tempPlaylist.append({i:songDatabaseList["songData"][i]}) songDatabase.execute("SELECT * FROM songs WHERE filename = ?",[i])
result = songDatabase.fetchall()
k = {
"title": result[1],
"artist": result[2],
"art": result[3],
"length": result[4]
}
tempPlaylist.append({i:k})
# print(tempPlaylist) # print(tempPlaylist)
fileofDB.close()
return tempPlaylist return tempPlaylist
if __name__ == "__main__": if __name__ == "__main__":