From c7a48d2bd9334f40b3380b54dc0cad3e0d4aefd3 Mon Sep 17 00:00:00 2001 From: scoobybejesus <21372487+scoobybejesus@users.noreply.github.com> Date: Sat, 7 Aug 2021 22:33:24 -0400 Subject: [PATCH 1/5] Add websocket route for current track --- ircradio/routes.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ircradio/routes.py b/ircradio/routes.py index 0a4fd09..9a56514 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,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) From 9716feab339fde7990d786f734fed5cef1da829b Mon Sep 17 00:00:00 2001 From: scoobybejesus <21372487+scoobybejesus@users.noreply.github.com> Date: Sat, 7 Aug 2021 22:36:47 -0400 Subject: [PATCH 2/5] Script to open websocket for #now_playing updates --- ircradio/templates/base.html | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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 @@