mirror of
https://github.com/radio95-rnt/RadioPlayer.git
synced 2026-07-30 15:59:16 +02:00
swap rtp, and also update user count on disconnect
This commit is contained in:
+18
-9
@@ -86,16 +86,25 @@ def update_rds(track_name: str):
|
|||||||
artist = artist.encode("radiodatasystem", "replace")
|
artist = artist.encode("radiodatasystem", "replace")
|
||||||
|
|
||||||
rtp = []
|
rtp = []
|
||||||
rtp.append(1) # type 2
|
def do_title():
|
||||||
rtp.append(prt.find(title)) # start 2
|
rtp.append(1) # type 2
|
||||||
rtp.append(len(title) - 1) # len 2
|
rtp.append(prt.find(title)) # start 2
|
||||||
rtp.append(4) # type 1
|
rtp.append(len(title) - 1) # len 2
|
||||||
rtp.append(prt.find(artist)) # start 1
|
def do_artist():
|
||||||
rtp.append(len(artist) - 1) # len 1
|
rtp.append(4) # type 1
|
||||||
|
rtp.append(prt.find(artist)) # start 1
|
||||||
|
rtp.append(len(artist) - 1) # len 1
|
||||||
|
if len(artist) > len(title):
|
||||||
|
do_artist()
|
||||||
|
do_title()
|
||||||
|
else:
|
||||||
|
#len(artist) < len(title)
|
||||||
|
do_title()
|
||||||
|
do_artist()
|
||||||
|
|
||||||
rtp = [j_size if i_rt > j_size else i_rt for i_rt,j_size in zip(rtp, [255,0x3f,0x3f,255,0x3f,0x1f])]
|
rtp = [j_size if i_rt > j_size else i_rt for i_rt,j_size in zip(rtp, [255,0x3f,0x3f,255,0x3f,0x1f])]
|
||||||
|
|
||||||
rtp = ','.join(list(map(str, rtp)))
|
rtp_str = ','.join(list(map(str, rtp)))
|
||||||
|
|
||||||
prt = prt[:64]
|
prt = prt[:64]
|
||||||
|
|
||||||
@@ -104,14 +113,14 @@ def update_rds(track_name: str):
|
|||||||
f.settimeout(1.0)
|
f.settimeout(1.0)
|
||||||
uecp_frame = uecp.frame.UECPFrame()
|
uecp_frame = uecp.frame.UECPFrame()
|
||||||
uecp_frame.add_command(RT_Set(prt))
|
uecp_frame.add_command(RT_Set(prt))
|
||||||
uecp_frame.add_command(ASCII(f"RTP={rtp}".encode()))
|
uecp_frame.add_command(ASCII(f"RTP={rtp_str}".encode()))
|
||||||
|
|
||||||
data = uecp_frame.encode()
|
data = uecp_frame.encode()
|
||||||
f.sendto(data, udp_host)
|
f.sendto(data, udp_host)
|
||||||
logger.debug("Sending", str(data))
|
logger.debug("Sending", str(data))
|
||||||
except Exception as e: logger.error(f"Error updating RDS: {e}")
|
except Exception as e: logger.error(f"Error updating RDS: {e}")
|
||||||
|
|
||||||
return prt.decode("radiodatasystem", "ignore"), rtp
|
return prt.decode("radiodatasystem", "ignore"), rtp_str
|
||||||
|
|
||||||
class Module(PlayerModule):
|
class Module(PlayerModule):
|
||||||
def on_new_track(self, index: int, track: Track, next_track: Track | None):
|
def on_new_track(self, index: int, track: Track, next_track: Track | None):
|
||||||
|
|||||||
+6
-3
@@ -134,13 +134,15 @@ async def broadcast_worker(ws_q: multiprocessing.Queue, clients: set):
|
|||||||
payload = json.dumps(msg)
|
payload = json.dumps(msg)
|
||||||
if clients:
|
if clients:
|
||||||
coros = []
|
coros = []
|
||||||
for ws in list(clients): coros.append(_safe_send(ws, payload, clients))
|
for ws in list(clients): coros.append(_safe_send(ws, payload, clients, ws_q))
|
||||||
await asyncio.gather(*coros)
|
await asyncio.gather(*coros)
|
||||||
|
|
||||||
async def _safe_send(ws, payload: str, clients: set):
|
async def _safe_send(ws, payload: str, clients: set, ws_q: multiprocessing.Queue):
|
||||||
try: await ws.send(payload)
|
try: await ws.send(payload)
|
||||||
except Exception:
|
except Exception:
|
||||||
try: clients.discard(ws)
|
try:
|
||||||
|
clients.discard(ws)
|
||||||
|
await asyncio.get_event_loop().run_in_executor(None, ws_q.put, {"event": "users", "data": len(clients)})
|
||||||
except Exception: pass
|
except Exception: pass
|
||||||
|
|
||||||
def websocket_server_process(shared_data: dict, imc_q: multiprocessing.Queue, ws_q: multiprocessing.Queue):
|
def websocket_server_process(shared_data: dict, imc_q: multiprocessing.Queue, ws_q: multiprocessing.Queue):
|
||||||
@@ -154,6 +156,7 @@ def websocket_server_process(shared_data: dict, imc_q: multiprocessing.Queue, ws
|
|||||||
finally:
|
finally:
|
||||||
await websocket.close(1001, "")
|
await websocket.close(1001, "")
|
||||||
clients.discard(websocket)
|
clients.discard(websocket)
|
||||||
|
await asyncio.get_event_loop().run_in_executor(None, ws_q.put, {"event": "users", "data": len(clients)})
|
||||||
async def process_request(websocket: ServerConnection, request: Request):
|
async def process_request(websocket: ServerConnection, request: Request):
|
||||||
if request.path == "/ws":
|
if request.path == "/ws":
|
||||||
if not "upgrade" in request.headers.get("Connection", "").lower():
|
if not "upgrade" in request.headers.get("Connection", "").lower():
|
||||||
|
|||||||
Reference in New Issue
Block a user