0
1
mirror of https://github.com/radio95-rnt/RadioPlayer.git synced 2026-02-26 21:53:54 +01:00
This commit is contained in:
2025-12-14 12:23:33 +01:00
parent 4ca9a77d25
commit ea7740e7fa
3 changed files with 39 additions and 5 deletions

View File

@@ -8,7 +8,9 @@ Reacts to the 'no_jingle' argument, for global usage it does not add jingles to
import random
from . import PlaylistModifierModule, Track, Path
from modules import BaseIMCModule, InterModuleCommunication
from . import PlaylistModifierModule, Track, Path, PlayerModule
class Module(PlaylistModifierModule):
def __init__(self, primary: Path, secondary: list[Path] | None = None) -> None:
@@ -32,5 +34,22 @@ class Module(PlaylistModifierModule):
out.append(Track(track.path, crossfade, crossfade, True, track.args,focus_time_offset=-crossfade))
last_jingiel = False
return out
class Module2(PlayerModule):
def __init__(self, primary: Path, secondary: list[Path] | None = None) -> None:
if secondary is None: secondary = []
self.primary = primary.absolute()
assert primary.exists()
self.secondary = [f.absolute() for f in secondary if f.exists()]
def imc(self, imc: InterModuleCommunication) -> None:
super().imc(imc)
self._imc.register(self, "jingle")
def imc_data(self, source: BaseIMCModule, source_name: str | None, data: object, broadcast: bool) -> object:
if broadcast: return
jingle = self.primary
if self.secondary and (random.randint(1,3) == 1): jingle = random.choice(self.secondary)
return self._imc.send(self, "activemod", {"action": "add_to_toplay", "songs": [jingle]})
playlistmod = (Module(Path("/home/user/Jingiel.mp3"), [Path("/home/user/jing2.opus"), Path("Jing3.opus")]), 1)
options = Path("/home/user/Jingiel.mp3"), [Path("/home/user/jing2.opus"), Path("Jing3.opus")]
module = Module2(*options)
playlistmod = (Module(*options), 1)

View File

@@ -76,6 +76,7 @@
<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>
<button id="jingle-btn" class="btn">🕭 Add Jingle</button>
</div>
</div>
@@ -378,6 +379,10 @@
if(ws && ws.readyState === WebSocket.OPEN) ws.send(JSON.stringify({action:"skip_next"}));
else console.error("WebSocket not connected.");
});
document.getElementById("jingle-btn").addEventListener("click", () => {
if(ws && ws.readyState === WebSocket.OPEN) ws.send(JSON.stringify({action:"jingle"}));
else console.error("WebSocket not connected.");
});
document.getElementById("readd-btn").addEventListener("click", () => {
if(selectedPlaylistIndex == null){

View File

@@ -51,7 +51,7 @@ async def ws_handler(websocket: ServerConnection, shared_data: dict, imc_q: mult
await websocket.send(json.dumps({"status": "ok", "message": f"{len(songs)} song(s) queued"}))
result = await get_imc("activemod", {"action": "get_toplay"})
if result is not None:
if result is not None:
await websocket.loop.run_in_executor(None, ws_q.put, {"data": result, "event": "toplay"})
elif action == "get_toplay":
result = await get_imc("activemod", {"action": "get_toplay"})
@@ -60,11 +60,21 @@ async def ws_handler(websocket: ServerConnection, shared_data: dict, imc_q: mult
elif action == "clear_toplay":
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
else:
await websocket.send(json.dumps({"data": result, "event": "toplay"})) # Yes, this is not an accident
await websocket.loop.run_in_executor(None, ws_q.put, {"data": result, "event": "toplay"})
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 == "jingle":
result = await get_imc("jingle", None)
if result is None: await websocket.send(json.dumps({"error": "timeout", "code": 504}))
else:
await websocket.send(json.dumps(result))
result = await get_imc("activemod", {"action": "get_toplay"})
if result is not None:
await websocket.loop.run_in_executor(None, ws_q.put, {"data": result, "event": "toplay"})
elif action == "request_state":
# supports requesting specific parts if provided
what = msg.get("what", "")
@@ -224,7 +234,7 @@ class Module(PlayerModule):
self.data["progress"] = json.dumps(payload)
try: self.ws_q.put({"event": "progress", "data": payload})
except Exception: pass
def imc_data(self, source: BaseIMCModule, source_name: str | None, data: object, broadcast: bool) -> object:
try: self.ws_q.put({"event": "imc", "data": {"name": source_name, "data": data, "broadcast": broadcast}})
except Exception: pass