diff --git a/modules/active_modifier.py b/modules/active_modifier.py index 377bf30..5aef2dd 100644 --- a/modules/active_modifier.py +++ b/modules/active_modifier.py @@ -21,6 +21,7 @@ class Module(ActiveModifier): self.morning_start = self.day_end = 0 self.file_lock = Lock() self.crossfade = 5 + self.skip_next = False def on_new_playlist(self, playlist: list[Track], global_args: dict[str, str]): self.playlist = playlist self.crossfade = float(global_args.get("crossfade", 5.0)) @@ -108,6 +109,10 @@ class Module(ActiveModifier): logger.warning("Skipping track as it the next day") return (None, None), None if last_track_duration: logger.info("Track ends at", repr(future)) + if self.skip_next: + logger.info("Skip next flag was on, skipping this song.") + self.skip_next = False + return (None, None), None return (self.last_track, next_track), False def imc(self, imc: InterModuleCommunication) -> None: @@ -136,5 +141,8 @@ class Module(ActiveModifier): i += 1 with open(TOPLAY, "w") as f: f.write(first_line.strip() + "\n") return {"status": "ok", "data": [first_line.strip()]} + elif data.get("action") == "skip_next": + if data.get("set", True): self.skip_next = not self.skip_next + return {"status": "ok", "data": self.skip_next} activemod = Module() \ No newline at end of file diff --git a/modules/web.html b/modules/web.html index 1f85019..14ccabc 100644 --- a/modules/web.html +++ b/modules/web.html @@ -72,9 +72,10 @@
00:00 / 00:00 (00:00)
- - - + + + +
@@ -135,6 +136,7 @@ let selectedSubFile = null; let basePath = ""; let subbasePath = ""; + let skipNext = false; function connectWs(){ document.getElementById("server-status").textContent = "connecting..."; @@ -144,6 +146,7 @@ document.getElementById("server-status").textContent = "connected"; reconnectDelay = 1000; ws.send(JSON.stringify({action:"get_toplay"})); + ws.send(JSON.stringify({action:"skip_next",set:false})); }); ws.addEventListener("close", () => { @@ -185,6 +188,10 @@ renderPutQueue(); } else if(msg.event === "request_dir") { applySubdir(msg.data || {}) + } else if(msg.event === "skip_next") { + skip_next = msg.data.data || false; + renderPlaylist(); + renderPutQueue(); } else if(msg.status || msg.response || msg.error) { console.debug("ws ack", msg); } @@ -277,6 +284,9 @@ li.classList.add("current"); currentIndex = i; } + if(currentIndex+1 === i && skipNext) { + li.style.textDecoration = "line-through"; + } ul.appendChild(li); }); @@ -292,6 +302,9 @@ putQueue.forEach((element, i) => { const li = document.createElement("li"); li.textContent = element; + if(i === 0 && skipNext) { + li.style.textDecoration = "line-through"; + } ul.appendChild(li); }); } @@ -360,6 +373,10 @@ if(ws && ws.readyState === WebSocket.OPEN) ws.send(JSON.stringify({action:"skip"})); else console.error("WebSocket not connected."); }); + document.getElementById("skpn-btn").addEventListener("click", () => { + if(ws && ws.readyState === WebSocket.OPEN) ws.send(JSON.stringify({action:"skip_next"})); + else console.error("WebSocket not connected."); + }); document.getElementById("readd-btn").addEventListener("click", () => { if(selectedPlaylistIndex == null){ diff --git a/modules/web.py b/modules/web.py index a2de4cf..64df0ce 100644 --- a/modules/web.py +++ b/modules/web.py @@ -61,6 +61,10 @@ async def ws_handler(websocket: ServerConnection, shared_data: dict, imc_q: mult result = await get_imc("activemod", {"action": "clear_toplay"}) if result is None: await websocket.send(json.dumps({"error": "timeout", "code": 504})) else: await websocket.send(json.dumps({"data": result, "event": "toplay"})) # Yes, this is not an accident + elif action == "skip_next": + result = await get_imc("activemod", {"action": "skip_next", "set": msg.get("set",True)}) + if result is None: await websocket.send(json.dumps({"error": "timeout", "code": 504})) + else: await websocket.send(json.dumps({"data": result, "event": "skip_next"})) elif action == "request_state": # supports requesting specific parts if provided what = msg.get("what", "")