mirror of
https://github.com/sanderfoobar/ircradio.git
synced 2024-12-23 03:02:46 +01:00
Add websocket route for current track
This commit is contained in:
parent
c0a1415eae
commit
c7a48d2bd9
@ -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 New Issue
Block a user