Rearranged and removed comments

This commit is contained in:
Kristy Fournier 2025-10-10 15:30:01 -04:00
parent b20f0ecad0
commit 86e3e9cce8
2 changed files with 9 additions and 14 deletions

View file

@ -59,9 +59,12 @@ if args.art.lower() == "true" and not(args.apikey == ""):
else: else:
print("ETA "+ str(x) + " seconds") print("ETA "+ str(x) + " seconds")
# will be used soon
validFormats = [".mp3",".flac",".wav"]
for i in songFiles: for i in songFiles:
if i[-4:].lower() != ".mp3": if i[-4:].lower() != ".mp3":
# skip any non-mp3's (like directories or cover art) # skip any non music files (like directories or cover art)
continue continue
try: try:
# get the metadata # get the metadata
@ -105,7 +108,7 @@ for i in songFiles:
if len(songFiles) != 1: if len(songFiles) != 1:
index = (songFiles.index(i))%4 index = (songFiles.index(i))%4
print("\r" + str(loading[index] + str(math.floor((songFiles.index(i)/(len(songFiles)-1))*100))+ "%"), end='', flush=True) print("\r" + str(loading[index] + str(math.floor((songFiles.index(i)/(len(songFiles)-1))*100))+ "%"), end='', flush=True)
# each "song" is stored as a dictionary/JSON entry following the format seen in the readME # each "song" is stored as a SQLite entry following the format seen in the readME
songDatabase.execute(f"INSERT INTO songs (filename, title, artist, art, length) VALUES (?,?,?,?,?)",(i,title,artist,image,length)) songDatabase.execute(f"INSERT INTO songs (filename, title, artist, art, length) VALUES (?,?,?,?,?)",(i,title,artist,image,length))
fileOfDB.commit() fileOfDB.commit()

View file

@ -5,8 +5,6 @@ import sqlite3 as sql
import vlc,threading,time,random, argparse 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
# parser.add_argument('-d','--directory',help="Directory of the song files (make sure this matches the directory used for the databaseGenerator)", default="./sound/")
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')
parser.add_argument('-a','--admin',help="Add an admin password to be used in the client. DO NOT use a password you use elsewhere",default="") parser.add_argument('-a','--admin',help="Add an admin password to be used in the client. DO NOT use a password you use elsewhere",default="")
args = parser.parse_args() args = parser.parse_args()
@ -20,9 +18,7 @@ ADMIN_PASS = args.admin
if not(ADMIN_PASS): if not(ADMIN_PASS):
ADMIN_PASS = None ADMIN_PASS = None
# True = everyone, False = admin only. Change in client while in use. # True = everyone, False = admin only. Change in client while in use.
"""PP,SK,AS,PM,VOL all set to True or False # play-pause,skip,addsong,partymode,volume in order
False is admin only
True is all users"""
controlPerms = { controlPerms = {
"PP":True, #done "PP":True, #done
"SK":True, #done "SK":True, #done
@ -37,14 +33,12 @@ songDatabase = fileofDB.cursor()
#song directory #song directory
songDatabase.execute("SELECT * FROM meta WHERE id='songDirectory';") songDatabase.execute("SELECT * FROM meta WHERE id='songDirectory';")
soundLocation = songDatabase.fetchall()[0][1] soundLocation = songDatabase.fetchall()[0][1]
if soundLocation[-1] == "/" or soundLocation[-1] == "\\": if soundLocation[-1] == "/" or soundLocation[-1] == "\\":
pass pass
elif "/" in soundLocation: elif "/" in soundLocation:
soundLocation += "/" soundLocation += "/"
else: else:
soundLocation += "\\" soundLocation += "\\"
#print(soundLocation)
#Create Virtual table for searching #Create Virtual table for searching
songDatabase.execute("DROP TABLE virtualSongs;") songDatabase.execute("DROP TABLE virtualSongs;")
songDatabase.execute("CREATE VIRTUAL TABLE virtualSongs USING fts5(filename, title, artist, art, length);") songDatabase.execute("CREATE VIRTUAL TABLE virtualSongs USING fts5(filename, title, artist, art, length);")
@ -180,7 +174,7 @@ def searchSongDB():
songDatabase.execute("SELECT * FROM virtualSongs WHERE virtualSongs MATCH ?",[recieveData['search']]) songDatabase.execute("SELECT * FROM virtualSongs WHERE virtualSongs MATCH ?",[recieveData['search']])
results = songDatabase.fetchall() results = songDatabase.fetchall()
tempdata = {} tempdata = {}
# this is a temporary solution so i dont have to change the # this is a temporary solution so i dont have to change the client
for i in results: for i in results:
tempdata[i[0]] = { tempdata[i[0]] = {
"title": i[1], "title": i[1],
@ -188,7 +182,6 @@ def searchSongDB():
"art": i[3], "art": i[3],
"length": i[4] "length": i[4]
} }
# print(tempData)
fileofDB.close() fileofDB.close()
return tempdata return tempdata
@ -196,11 +189,11 @@ def searchSongDB():
def songadd(): def songadd():
recieveData=request.get_json(force=True) recieveData=request.get_json(force=True)
if (ADMIN_PASS and ADMIN_PASS == recieveData['password']) or controlPerms["AS"]: if (ADMIN_PASS and ADMIN_PASS == recieveData['password']) or controlPerms["AS"]:
# Pass exists and is correct, or it's not restricted # Password exists and is correct, or it's not restricted
queueSong(recieveData['song']) queueSong(recieveData['song'])
return "200" return "200"
else: else:
# the pass is incorrect (technically a pass not existing falls into the above case because controlPerms is never changed) # the password is incorrect (technically a password not existing falls into the above case because controlPerms is never changed)
return ERR_NO_ADMIN return ERR_NO_ADMIN
@app.route("/playlist", methods=["POST"]) @app.route("/playlist", methods=["POST"])
@ -234,7 +227,6 @@ def getPlaylist():
"length": result[4] "length": result[4]
} }
tempPlaylist.append({i:k}) tempPlaylist.append({i:k})
# print(tempPlaylist)
fileofDB.close() fileofDB.close()
return tempPlaylist return tempPlaylist