You've already forked RadioPlayer
mirror of
https://github.com/radio95-rnt/RadioPlayer.git
synced 2026-02-27 14:13:55 +01:00
jingle
This commit is contained in:
@@ -8,7 +8,9 @@ Reacts to the 'no_jingle' argument, for global usage it does not add jingles to
|
|||||||
|
|
||||||
import random
|
import random
|
||||||
|
|
||||||
from . import PlaylistModifierModule, Track, Path
|
from modules import BaseIMCModule, InterModuleCommunication
|
||||||
|
|
||||||
|
from . import PlaylistModifierModule, Track, Path, PlayerModule
|
||||||
|
|
||||||
class Module(PlaylistModifierModule):
|
class Module(PlaylistModifierModule):
|
||||||
def __init__(self, primary: Path, secondary: list[Path] | None = None) -> None:
|
def __init__(self, primary: Path, secondary: list[Path] | None = None) -> None:
|
||||||
@@ -33,4 +35,21 @@ class Module(PlaylistModifierModule):
|
|||||||
last_jingiel = False
|
last_jingiel = False
|
||||||
return out
|
return out
|
||||||
|
|
||||||
playlistmod = (Module(Path("/home/user/Jingiel.mp3"), [Path("/home/user/jing2.opus"), Path("Jing3.opus")]), 1)
|
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]})
|
||||||
|
|
||||||
|
options = Path("/home/user/Jingiel.mp3"), [Path("/home/user/jing2.opus"), Path("Jing3.opus")]
|
||||||
|
module = Module2(*options)
|
||||||
|
playlistmod = (Module(*options), 1)
|
||||||
@@ -76,6 +76,7 @@
|
|||||||
<button id="readd-btn" class="btn">↺ Re-add Selected</button>
|
<button id="readd-btn" class="btn">↺ Re-add Selected</button>
|
||||||
<button id="clear-btn" class="btn">✖ Clear the PUT Queue</button>
|
<button id="clear-btn" class="btn">✖ Clear the PUT Queue</button>
|
||||||
<button id="skpn-btn" class="btn">⏭? Toggle skip next</button>
|
<button id="skpn-btn" class="btn">⏭? Toggle skip next</button>
|
||||||
|
<button id="jingle-btn" class="btn">🕭 Add Jingle</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -378,6 +379,10 @@
|
|||||||
if(ws && ws.readyState === WebSocket.OPEN) ws.send(JSON.stringify({action:"skip_next"}));
|
if(ws && ws.readyState === WebSocket.OPEN) ws.send(JSON.stringify({action:"skip_next"}));
|
||||||
else console.error("WebSocket not connected.");
|
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", () => {
|
document.getElementById("readd-btn").addEventListener("click", () => {
|
||||||
if(selectedPlaylistIndex == null){
|
if(selectedPlaylistIndex == null){
|
||||||
|
|||||||
@@ -60,11 +60,21 @@ async def ws_handler(websocket: ServerConnection, shared_data: dict, imc_q: mult
|
|||||||
elif action == "clear_toplay":
|
elif action == "clear_toplay":
|
||||||
result = await get_imc("activemod", {"action": "clear_toplay"})
|
result = await get_imc("activemod", {"action": "clear_toplay"})
|
||||||
if result is None: await websocket.send(json.dumps({"error": "timeout", "code": 504}))
|
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":
|
elif action == "skip_next":
|
||||||
result = await get_imc("activemod", {"action": "skip_next", "set": msg.get("set",True)})
|
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}))
|
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": "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":
|
elif action == "request_state":
|
||||||
# supports requesting specific parts if provided
|
# supports requesting specific parts if provided
|
||||||
what = msg.get("what", "")
|
what = msg.get("what", "")
|
||||||
|
|||||||
Reference in New Issue
Block a user