misc/radio

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

View File

@ -99,7 +99,7 @@ karma_endpoints = importlib.import_module("endpoints.karma").Karma(app, util, co
# Below: Radio endpoint(s) - in development, sporadically loaded as needed
radio_endpoints = importlib.import_module("endpoints.radio").Radio(app, util, constants, glob_state)
# Below: Misc endpoints
misc_endpoints = importlib.import_module("endpoints.misc").Misc(app, util, constants, glob_state)
misc_endpoints = importlib.import_module("endpoints.misc").Misc(app, util, constants, glob_state, radio_endpoints)
"""
End Actionable Routes

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:

View File

@ -104,20 +104,15 @@ class Radio(FastAPI):
"radio/queue_shift": self.radio_queue_shift,
"radio/reshuffle": self.radio_reshuffle,
"radio/queue_remove": self.radio_queue_remove,
# "widget/sqlite": self.homepage_sqlite_widget,
# "widget/lyrics": self.homepage_lyrics_widget,
# "widget/radio": self.homepage_radio_widget,
"radio/ls._next_": self.radio_get_next,
}
for endpoint, handler in self.endpoints.items():
app.add_api_route(f"/{endpoint}", handler, methods=["POST"],
include_in_schema=True) # change include_in_schema to False
include_in_schema=False) # change include_in_schema to False
# NOTE: Not in loop because method is GET for this endpoint
app.add_api_route("/radio/album_art", self.album_art_handler, methods=["GET"],
include_in_schema=True)
#NOTE: Not in loop because include_in_schema is False for this endpoint, private
app.add_api_route("/radio/ls._next_", self.radio_get_next, methods=["POST"],
include_in_schema=False)
asyncio.get_event_loop().run_until_complete(self.load_playlist())

View File

@ -87,7 +87,7 @@ class RadioUtil:
}]
}
sfm_hook = self.webhooks['gpt'].get('hook')
sfm_hook = self.webhooks['sfm'].get('hook')
async with ClientSession() as session:
async with await session.post(sfm_hook, json=hook_data,
timeout=ClientTimeout(connect=5, sock_read=5), headers={