From 369e7c6b42e75c1f1d64c46722f19330e88e5a77 Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Sat, 11 Apr 2026 14:34:58 +0200 Subject: [PATCH] some changes --- modules/active_modifier.py | 1 + modules/web.html | 50 +++++++++++--------------------------- modules/web.py | 21 +++++++++++----- radioPlayer.py | 6 ++--- 4 files changed, 33 insertions(+), 45 deletions(-) diff --git a/modules/active_modifier.py b/modules/active_modifier.py index a3329b5..c40db0e 100644 --- a/modules/active_modifier.py +++ b/modules/active_modifier.py @@ -168,6 +168,7 @@ class Module(ActiveModifier): if (count := data.get("set", -1)) > -1: self.skip_next = count if (count2 := data.get("add", -1)) > -1: self.skip_next += count2 if (count3 := data.get("remove", 1)) < 0: self.skip_next += count3 + self.skip_next = max(self.skip_next, 0) return {"status": "ok", "data": self.skip_next} activemod = Module() diff --git a/modules/web.html b/modules/web.html index c675de1..23fd624 100644 --- a/modules/web.html +++ b/modules/web.html @@ -52,7 +52,6 @@ .controls{display:flex; gap:8px; margin-top:8px} .box{display:flex; flex-direction:column; gap:8px; flex-grow: 1; overflow: hidden;} - /* --- HIDE SCROLLBARS ON ALL LISTBOXES --- */ .listbox{ height:100%; min-height:100px; @@ -235,8 +234,7 @@ // UI Toggle Function function toggleSection(id) { - const el = document.getElementById(id); - el.classList.toggle('collapsed'); + document.getElementById(id).classList.toggle('collapsed'); } // Mobile Default Setup @@ -257,7 +255,6 @@ document.getElementById("server-status").textContent = "connected"; reconnectDelay = 1000; ws.send(JSON.stringify({action:"get_toplay"})); - ws.send(JSON.stringify({action:"skipc",set:0})); }); ws.addEventListener("close", () => { @@ -292,15 +289,12 @@ } else if(msg.event === "new_track"){ applyTrackState(msg.data); ws.send(JSON.stringify({action:"get_toplay"})); - ws.send(JSON.stringify({action:"skipc",set:0})); - } else if(msg.event === "progress"){ - applyProgressState(msg.data); - } else if(msg.event === "toplay") { + } else if(msg.event === "progress") applyProgressState(msg.data); + else if(msg.event === "toplay") { Queue = msg.data.data || []; renderQueue(); - } else if(msg.event === "request_dir") { - applySubdir(msg.data || {}) - } else if(msg.event === "skipc") { + } else if(msg.event === "request_dir") applySubdir(msg.data || {}) + else if(msg.event === "skipc") { skipCount = msg.data?.data ?? 0; document.getElementById("skpn-count").textContent = skipCount; renderPlaylist(); @@ -332,10 +326,7 @@ if(track.path){ currentTrackPath = (track.official ? "" : "!") + track.path; document.getElementById("now-track").textContent = `${track.official ? "(official) " : ""}${track.path}`; - } - if(next_track.path){ - document.getElementById("next-track").textContent = `${next_track.official ? "(official) " : ""}${next_track.path}`; - } + } if(next_track.path) document.getElementById("next-track").textContent = `${next_track.official ? "(official) " : ""}${next_track.path}`; } function applySubdir(payload) { @@ -498,21 +489,11 @@ ws.send(JSON.stringify({action:"request_dir", what: selectedDir})) } - document.getElementById("skip-btn").addEventListener("click", () => { - ws.send(JSON.stringify({action:"skip"})); - }); - document.getElementById("skpn-inc").addEventListener("click", () => { - ws.send(JSON.stringify({action:"skipc", add: 1})); - }); - document.getElementById("skpn-dec").addEventListener("click", () => { - ws.send(JSON.stringify({action:"skipc", remove: -1})); - }); - document.getElementById("jingle-btn").addEventListener("click", () => { - ws.send(JSON.stringify({action:"jingle"})); - }); - document.getElementById("clear-btn").addEventListener("click", () => { - ws.send(JSON.stringify({action:"clear_toplay"})) - }); + document.getElementById("skip-btn").addEventListener("click", () => ws.send(JSON.stringify({action:"skip"}))); + document.getElementById("skpn-inc").addEventListener("click", () => ws.send(JSON.stringify({action:"skipc", add: 1}))); + document.getElementById("skpn-dec").addEventListener("click", () => ws.send(JSON.stringify({action:"skipc", remove: -1}))}); + document.getElementById("jingle-btn").addEventListener("click", () => ws.send(JSON.stringify({action:"jingle"}))); + document.getElementById("clear-btn").addEventListener("click", () => ws.send(JSON.stringify({action:"clear_toplay"}))); function addSelectedFileToQueue(top) { let fullPath = null; @@ -523,14 +504,11 @@ const path = (selected.official ? "" : "!") + selected.path; ws.send(JSON.stringify({ action: "add_to_toplay", songs: [path], top: top })); success = true; - } else if (selectedSubFile && selectedDir) { - fullPath = subbasePath.replace(/\/$/, '') + '/' + selectedSubFile; - } else { + } else if (selectedSubFile && selectedDir) fullPath = subbasePath.replace(/\/$/, '') + '/' + selectedSubFile; + else { const dirEls = document.getElementById("dirs-box").children; const selectedItem = Array.from(dirEls).find(el => el.classList.contains("selected")); - if (selectedItem && selectedItem.dataset.type === "file") { - fullPath = basePath.replace(/\/$/, '') + '/' + selectedItem.textContent; - } + if (selectedItem && selectedItem.dataset.type === "file") fullPath = basePath.replace(/\/$/, '') + '/' + selectedItem.textContent; } if (fullPath) { diff --git a/modules/web.py b/modules/web.py index d5de41c..7426de8 100644 --- a/modules/web.py +++ b/modules/web.py @@ -34,11 +34,11 @@ async def ws_handler(websocket: ServerConnection, shared_data: dict, imc_q: mult imc_q.put({"name": name, "data": data, "key": key}) start = time.monotonic() result = None - while time.monotonic() - start < 1.5: + while time.monotonic() - start < 1: if key in shared_data: result = shared_data.pop(key) break - await asyncio.sleep(0.05) + await asyncio.sleep(0.1) return result action = msg.get("action") @@ -69,11 +69,11 @@ async def ws_handler(websocket: ServerConnection, shared_data: dict, imc_q: mult elif action == "skip_next": result = await get_imc("activemod", msg) if result is None: await websocket.send(json.dumps({"error": "timeout", "code": 504})) - else: await websocket.send(json.dumps({"data": result, "event": "skip_next"})) + else: await websocket.send(json.dumps({"data": result, "event": action})) elif action == "skipc": result = await get_imc("activemod", msg) if result is None: await websocket.send(json.dumps({"error": "timeout", "code": 504})) - else: await websocket.send(json.dumps({"data": result, "event": "skip_next"})) + else: await websocket.send(json.dumps({"data": result, "event": action})) elif action == "jingle": result = await get_imc("jingle", msg.get("top", False)) if result is None: await websocket.send(json.dumps({"error": "timeout", "code": 504})) @@ -155,6 +155,14 @@ def websocket_server_process(shared_data: dict, imc_q: multiprocessing.Queue, ws Headers([("Content-Type", "text/html"), ("Content-Length", f"{len(data)}")]), data ) + if request.path == "/favicon.ico": + data = b"Not Found" + return Response( + 404, + "Not Found", + Headers([("Content-Length", f"{len(data)}")]), + data + ) if not "upgrade" in request.headers.get("Connection", "").lower(): return Response( 426, @@ -192,6 +200,7 @@ class Module(PlayerModule): self.ws_process = multiprocessing.Process(target=websocket_server_process, args=(self.data, self.imc_q, self.ws_q), daemon=False) self.ws_process.start() if os.name == "posix": + # We have to manage the process ourselves. Linux sends signals to everyone in the process group, meaning a CTRL+C would not kill the main one, but this one would die try: os.setpgid(self.ws_process.pid, self.ws_process.pid) except Exception: pass @@ -210,7 +219,6 @@ class Module(PlayerModule): except Exception: pass def on_new_playlist(self, playlist: list[Track], global_args: dict[str, str]) -> None: - # TODO: add global args to data api_data = [] for track in playlist: api_data.append({ @@ -220,7 +228,8 @@ class Module(PlayerModule): "official": track.official, "args": track.args, "offset": track.offset, - "focus_time_offset": track.focus_time_offset + "focus_time_offset": track.focus_time_offset, + "global_args": global_args }) self.data["playlist"] = json.dumps(api_data) try: self.ws_q.put({"event": "playlist", "data": api_data}) diff --git a/radioPlayer.py b/radioPlayer.py index 7e1c03c..36aec7b 100644 --- a/radioPlayer.py +++ b/radioPlayer.py @@ -246,7 +246,7 @@ class RadioPlayer: prefetch(track.path) def loop(self): - """Main loop of the player. This does not return and may or not raise an SystemExit""" + """Main loop of the player. This does not return and may or not raise a SystemExit""" try: while True: self.play_once() @@ -256,11 +256,11 @@ class RadioPlayer: raise class RotatingLog(io.TextIOWrapper): - def write(self, s: str) -> int: + def write(self, *args, **kwargs) -> int: if self.tell() > 2_500_000: self.truncate(0) self.seek(0) - return super().write(s) + return super().write(*args, **kwargs) def main(): log_file_path = Path("/tmp/radioPlayer_log")