mirror of
https://git.wownero.com/dsc/ircradio.git
synced 2024-08-15 01:03:15 +00:00
Add websocket route for current track
This commit is contained in:
parent
c0a1415eae
commit
c7a48d2bd9
1 changed files with 20 additions and 0 deletions
|
@ -4,6 +4,8 @@
|
|||
from datetime import datetime
|
||||
from typing import Tuple, Optional
|
||||
from quart import request, render_template, abort, jsonify
|
||||
import asyncio
|
||||
import json
|
||||
|
||||
import settings
|
||||
from ircradio.factory import app
|
||||
|
@ -108,3 +110,21 @@ async def user_library():
|
|||
by_karma = []
|
||||
|
||||
return await render_template("library.html", name=name, by_date=by_date, by_karma=by_karma)
|
||||
|
||||
|
||||
@app.websocket("/ws")
|
||||
+async def np():
|
||||
while True:
|
||||
"""get current song from history"""
|
||||
history = Radio.history()
|
||||
val = ""
|
||||
if not history:
|
||||
val = f"Nothing is playing?!"
|
||||
else:
|
||||
song = history[0]
|
||||
val = song.title
|
||||
|
||||
data = json.dumps({"now_playing": val})
|
||||
|
||||
await websocket.send(f"{data}")
|
||||
await asyncio.sleep(5)
|
||||
|
|
Loading…
Reference in a new issue