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 # Below: Radio endpoint(s) - in development, sporadically loaded as needed
radio_endpoints = importlib.import_module("endpoints.radio").Radio(app, util, constants, glob_state) radio_endpoints = importlib.import_module("endpoints.radio").Radio(app, util, constants, glob_state)
# Below: Misc endpoints # 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 End Actionable Routes

View File

@ -15,7 +15,7 @@ from lyric_search.sources import private, cache as LyricsCache, redis_cache
class Misc(FastAPI): class Misc(FastAPI):
"""Misc Endpoints""" """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.app = app
self.util = my_util self.util = my_util
self.constants = constants self.constants = constants
@ -24,6 +24,7 @@ class Misc(FastAPI):
self.lyr_cache = LyricsCache.Cache() self.lyr_cache = LyricsCache.Cache()
self.redis_cache = redis_cache.RedisCache() self.redis_cache = redis_cache.RedisCache()
self.redis_client = redis.Redis(password=private.REDIS_PW) self.redis_client = redis.Redis(password=private.REDIS_PW)
self.radio = radio
self.endpoints = { self.endpoints = {
"widget/redis": self.homepage_redis_widget, "widget/redis": self.homepage_redis_widget,
"widget/sqlite": self.homepage_sqlite_widget, "widget/sqlite": self.homepage_sqlite_widget,
@ -55,19 +56,10 @@ class Misc(FastAPI):
'content-type': 'application/json; charset=utf-8', 'content-type': 'application/json; charset=utf-8',
} }
#TODO: change URL below to dynamically populate based on listener artistsong = self.radio.now_playing['artistsong']
async with ClientSession() as session: if not isinstance(artistsong, str):
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 "N/A - N/A"
return f"{np_artist} - {np_song}" return artistsong
async def homepage_redis_widget(self) -> dict: async def homepage_redis_widget(self) -> dict:

View File

@ -104,20 +104,15 @@ class Radio(FastAPI):
"radio/queue_shift": self.radio_queue_shift, "radio/queue_shift": self.radio_queue_shift,
"radio/reshuffle": self.radio_reshuffle, "radio/reshuffle": self.radio_reshuffle,
"radio/queue_remove": self.radio_queue_remove, "radio/queue_remove": self.radio_queue_remove,
# "widget/sqlite": self.homepage_sqlite_widget, "radio/ls._next_": self.radio_get_next,
# "widget/lyrics": self.homepage_lyrics_widget,
# "widget/radio": self.homepage_radio_widget,
} }
for endpoint, handler in self.endpoints.items(): for endpoint, handler in self.endpoints.items():
app.add_api_route(f"/{endpoint}", handler, methods=["POST"], 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 # NOTE: Not in loop because method is GET for this endpoint
app.add_api_route("/radio/album_art", self.album_art_handler, methods=["GET"], 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) include_in_schema=False)
asyncio.get_event_loop().run_until_complete(self.load_playlist()) 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 ClientSession() as session:
async with await session.post(sfm_hook, json=hook_data, async with await session.post(sfm_hook, json=hook_data,
timeout=ClientTimeout(connect=5, sock_read=5), headers={ timeout=ClientTimeout(connect=5, sock_read=5), headers={