From faac93b1f6f2754d9c4ac0ffecfbae5c4b8647f3 Mon Sep 17 00:00:00 2001 From: Kristy Fournier <124598538+kristy-fournier@users.noreply.github.com> Date: Fri, 10 Oct 2025 18:39:56 -0400 Subject: [PATCH] flac and wav support --- Client/scripts.js | 11 ++++++++--- Server/databaseGenerator.py | 20 +++++++++++++++----- wishlist.md | 2 +- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Client/scripts.js b/Client/scripts.js index 3db547d..f0fea6c 100644 --- a/Client/scripts.js +++ b/Client/scripts.js @@ -3,7 +3,7 @@ let ip; let alertTime = 2; let adminPass = ""; const ERR_NO_ADMIN = "401"; // gonna use this later to refactor - +const VALID_FILE_EXT = ["mp3","flac","wav"] async function alertText(text="Song Added!") { alertbox = document.getElementById("alert"); alertbox.innerHTML = text; @@ -41,7 +41,7 @@ async function getFromServer(bodyInfo, source="",password=adminPass) { } else if(e == "") { } else { - alertText("Error: " + e) + alertText("Error: " + e); } const response=null; return response; @@ -320,7 +320,9 @@ function checkWhatSongWasClicked(e) { //i feel like later kristy won't apreciate this //one of my files was "file.MP3" so it didn't work //windows be like - if (itemId.slice(-4).toLowerCase() == ".mp3") { + let filenameSep = itemId.split('.') + + if (VALID_FILE_EXT.includes(filenameSep[filenameSep.length-1].toLowerCase())) { submitSong(itemId); } } @@ -388,6 +390,8 @@ document.getElementById("volumerange").onchange = async function() { } } +//bit of a cheat code for clearing the alerts when they don't clear normally +document.getElementById("title").addEventListener('click',function(){document.getElementById("alert").innerHTML = ""}) document.getElementById("settings-button").addEventListener('click',function(){controlButton("st")}); document.getElementById("play-pause-button").addEventListener('click', function(){controlButton("pp")}); document.getElementById("playlist-button").addEventListener('click', function(){controlButton("pl")}); @@ -402,6 +406,7 @@ document.getElementById("admincheckholder").addEventListener('click',function(e) document.getElementById("partymode-button").addEventListener('click',function(){controlButton("pm")}) //sets the fact that clicking a song needs to return its id to the function to find it document.getElementById("songlist").addEventListener('click', function(e){checkWhatSongWasClicked(e)}); + //makes the controls look mostly normal on all screens, best solution i could find, idk man let tempWidth = document.getElementById('controls').clientWidth; document.getElementById("controls").style.marginLeft = "-"+String(parseInt(tempWidth/2))+"px"; diff --git a/Server/databaseGenerator.py b/Server/databaseGenerator.py index f9e4782..e8c1915 100644 --- a/Server/databaseGenerator.py +++ b/Server/databaseGenerator.py @@ -1,6 +1,8 @@ import os from mutagen.easyid3 import EasyID3 from mutagen.mp3 import MP3 +import mutagen.flac +import mutagen.wave import sqlite3 as sql import requests, ast, time, math, argparse @@ -60,15 +62,23 @@ if args.art.lower() == "true" and not(args.apikey == ""): print("ETA "+ str(x) + " seconds") # will be used soon -validFormats = [".mp3",".flac",".wav"] +validFormats = ["mp3","flac","wav"] for i in songFiles: - if i[-4:].lower() != ".mp3": + global song + extension = i.split(".") + extension = extension[len(extension)-1] + if not(extension.lower() in validFormats): # skip any non music files (like directories or cover art) continue try: - # get the metadata - song = EasyID3(soundLocation+i) + if(extension.lower() == "mp3"): + # get the metadata + song = EasyID3(soundLocation+i) + elif(extension.lower() == "flac"): + song = mutagen.flac.FLAC(soundLocation+i) + elif(extension.lower() in ["wav","wave"]): + song = mutagen.wave.WAVE(soundLocation+i) title = song['title'][0] artist = song['artist'][0] except: @@ -102,7 +112,7 @@ for i in songFiles: else: image=None try: - length = math.ceil(MP3(soundLocation+i).info.length) + length = math.ceil(song.info.length) except: length = 0 if len(songFiles) != 1: diff --git a/wishlist.md b/wishlist.md index bb3161d..c207fcf 100644 --- a/wishlist.md +++ b/wishlist.md @@ -5,7 +5,7 @@ - [ ] Refactoring existing code - [ ] Update the SQL -> Server -> Client pipeline when searching and building playlist - [ ] Verify all if-else sequences are correct and not redundant - - [ ] Remove old comments + - [x] Remove old comments - [ ] Secure Password * Actually use SSL for stuff that should be using it - [ ] GUI update for client