0
1
mirror of https://github.com/radio95-rnt/RadioPlayer.git synced 2026-02-26 21:53:54 +01:00

skip next

This commit is contained in:
2025-12-14 11:37:37 +01:00
parent 2b5e6d7c03
commit 101beed96a
3 changed files with 32 additions and 3 deletions

View File

@@ -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()

View File

@@ -72,9 +72,10 @@
<div class="small" id="time-label">00:00 / 00:00 (00:00)</div>
</div>
<div class="controls" style="margin-top:10px">
<button id="skip-btn" class="btn">⏭ Skip Track</button>
<button id="readd-btn" class="btn">↺ Re-add Selected</button>
<button id="clear-btn" class="btn">✖ Clear the PUT Queue</button>
<button id="skip-btn" class="btn">⏭ Skip Track</button>
<button id="readd-btn" class="btn">↺ Re-add Selected</button>
<button id="clear-btn" class="btn">✖ Clear the PUT Queue</button>
<button id="skpn-btn" class="btn">⏭? Toggle skip next</button>
</div>
</div>
@@ -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){

View File

@@ -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", "")