requests_async
This commit is contained in:
@ -67,8 +67,8 @@ class ValidLyricSearchLogRequest(BaseModel):
|
||||
class CacheUtils:
|
||||
"""Lyrics Cache DB Utils"""
|
||||
def __init__(self):
|
||||
self.lyrics_db_path = os.path.join("/", "var", "lib",
|
||||
"singerdbs", "cached_lyrics.db")
|
||||
self.lyrics_db_path = os.path.join("/", "usr", "local", "share",
|
||||
"sqlite_dbs", "cached_lyrics.db")
|
||||
|
||||
async def check_typeahead(self, s: str, pre_query: str | None = None):
|
||||
"""Check s against artists stored - for typeahead"""
|
||||
@ -94,16 +94,13 @@ class LyricSearch(FastAPI):
|
||||
self.glob_state = glob_state
|
||||
self.cache_utils = CacheUtils()
|
||||
self.notifier = notifier.DiscordNotifier()
|
||||
self.lyrics_engine = importlib.import_module("lyrics_engine").LyricsEngine()
|
||||
|
||||
self.endpoint_name = "lyric_search"
|
||||
self.endpoint2_name = "lyric_cache_list"
|
||||
|
||||
self.endpoints = {
|
||||
"typeahead/artist": self.artist_typeahead_handler,
|
||||
"typeahead/song": self.song_typeahead_handler,
|
||||
"lyric_search": self.lyric_search_handler,
|
||||
"lyric_cache_list": self.lyric_cache_list_handler,
|
||||
# "lyric_cache_list": self.lyric_cache_list_handler,
|
||||
}
|
||||
|
||||
self.acceptable_request_sources = [
|
||||
@ -123,14 +120,14 @@ class LyricSearch(FastAPI):
|
||||
for endpoint, handler in self.endpoints.items():
|
||||
app.add_api_route(f"/{endpoint}/", handler, methods=["POST"])
|
||||
|
||||
async def lyric_cache_list_handler(self):
|
||||
"""
|
||||
Get currently cached lyrics entries
|
||||
"""
|
||||
return {
|
||||
'err': False,
|
||||
'data': await self.lyrics_engine.listCacheEntries()
|
||||
}
|
||||
# async def lyric_cache_list_handler(self):
|
||||
# """
|
||||
# Get currently cached lyrics entries
|
||||
# """
|
||||
# return {
|
||||
# 'err': False,
|
||||
# 'data': await self.lyrics_engine.listCacheEntries()
|
||||
# }
|
||||
|
||||
async def artist_typeahead_handler(self, data: ValidTypeAheadRequest):
|
||||
"""Artist Type Ahead Handler"""
|
||||
@ -158,15 +155,15 @@ class LyricSearch(FastAPI):
|
||||
typeahead_list = [str(r.get('song')) for r in typeahead_result]
|
||||
return typeahead_list
|
||||
|
||||
async def lyric_search_log_handler(self, data: ValidLyricSearchLogRequest):
|
||||
"""Lyric Search Log Handler"""
|
||||
include_radio = data.webradio
|
||||
await self.glob_state.increment_counter('lyrichistory_requests')
|
||||
last_10k_sings = await self.lyrics_engine.getHistory(limit=10000, webradio=include_radio)
|
||||
return {
|
||||
'err': False,
|
||||
'history': last_10k_sings
|
||||
}
|
||||
# async def lyric_search_log_handler(self, data: ValidLyricSearchLogRequest):
|
||||
# """Lyric Search Log Handler"""
|
||||
# include_radio = data.webradio
|
||||
# await self.glob_state.increment_counter('lyrichistory_requests')
|
||||
# last_10k_sings = await self.lyrics_engine.getHistory(limit=10000, webradio=include_radio)
|
||||
# return {
|
||||
# 'err': False,
|
||||
# 'history': last_10k_sings
|
||||
# }
|
||||
|
||||
async def lyric_search_handler(self, data: ValidLyricRequest):
|
||||
"""
|
||||
|
Reference in New Issue
Block a user