diff --git a/ircradio/routes.py b/ircradio/routes.py index 0a4fd09..eadaa80 100644 --- a/ircradio/routes.py +++ b/ircradio/routes.py @@ -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,24 @@ 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(): + last_song = "" + 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 + + if val != last_song: + data = json.dumps({"now_playing": val}) + await websocket.send(f"{data}") + + last_song = val + await asyncio.sleep(5) diff --git a/ircradio/templates/base.html b/ircradio/templates/base.html index 7c4cd48..e13f44e 100644 --- a/ircradio/templates/base.html +++ b/ircradio/templates/base.html @@ -30,9 +30,29 @@