misc/radio

This commit is contained in:
2025-02-11 08:41:29 -05:00
parent 32009c9a99
commit 028cfc197b
4 changed files with 11 additions and 24 deletions

View File

@ -15,7 +15,7 @@ from lyric_search.sources import private, cache as LyricsCache, redis_cache
class Misc(FastAPI):
"""Misc Endpoints"""
def __init__(self, app: FastAPI, my_util, constants, glob_state): # pylint: disable=super-init-not-called
def __init__(self, app: FastAPI, my_util, constants, glob_state, radio): # pylint: disable=super-init-not-called
self.app = app
self.util = my_util
self.constants = constants
@ -24,6 +24,7 @@ class Misc(FastAPI):
self.lyr_cache = LyricsCache.Cache()
self.redis_cache = redis_cache.RedisCache()
self.redis_client = redis.Redis(password=private.REDIS_PW)
self.radio = radio
self.endpoints = {
"widget/redis": self.homepage_redis_widget,
"widget/sqlite": self.homepage_sqlite_widget,
@ -55,19 +56,10 @@ class Misc(FastAPI):
'content-type': 'application/json; charset=utf-8',
}
#TODO: change URL below to dynamically populate based on listener
async with ClientSession() as session:
async with await session.post("http://127.0.0.1:52111/xc", json=json_payload,
headers=headers, timeout=ClientTimeout(connect=3, sock_read=2)) as request:
request.raise_for_status()
request_json = await request.json()
request_json = request_json.get('response')
np_artist = request_json.get('artist')
np_song = request_json.get('title')
if not isinstance(np_artist, str)\
or not isinstance(np_song, str):
return "N/A - N/A"
return f"{np_artist} - {np_song}"
artistsong = self.radio.now_playing['artistsong']
if not isinstance(artistsong, str):
return "N/A - N/A"
return artistsong
async def homepage_redis_widget(self) -> dict: