This commit is contained in:
codey 2024-08-13 19:50:02 -04:00
parent 17da906826
commit 2f4daca71c

View File

@ -35,6 +35,41 @@ class ValidLyricRequest(BaseModel):
} }
} }
class ValidLyricRequest(BaseModel):
"""
- **a**: artist
- **s**: song
- **t**: track (artist and song combined) [used only if a & s are not used]
- **extra**: include extra details in response [optional, default: false]
- **sub**: text to search within lyrics, if found lyrics will begin at found verse [optional]
- **src**: the script/utility which initiated the request
"""
a: str | None = None
s: str | None = None
t: str | None = None
sub: str | None = None
extra: bool | None = False
src: str
class Config: # pylint: disable=missing-class-docstring too-few-public-methods
schema_extra = {
"example": {
"a": "eminem",
"s": "rap god",
"src": "WEB",
"extra": True
}
}
class ValidLyricSearchLogRequest(BaseModel):
"""
- **webradio**: whether or not to include requests generated automatically by the radio page on codey.lol, defaults to False
"""
webradio: bool = False
class LyricSearch(FastAPI): class LyricSearch(FastAPI):
"""Lyric Search Endpoint""" """Lyric Search Endpoint"""
def __init__(self, app: FastAPI, util, constants, glob_state): # pylint: disable=super-init-not-called def __init__(self, app: FastAPI, util, constants, glob_state): # pylint: disable=super-init-not-called
@ -50,6 +85,7 @@ class LyricSearch(FastAPI):
self.endpoints = { self.endpoints = {
"lyric_search": self.lyric_search_handler, "lyric_search": self.lyric_search_handler,
"lyric_cache_list": self.lyric_cache_list_handler, "lyric_cache_list": self.lyric_cache_list_handler,
"lyric_search_history": self.lyric_search_log_handler
} }
self.acceptable_request_sources = [ self.acceptable_request_sources = [
@ -74,6 +110,16 @@ class LyricSearch(FastAPI):
'data': await self.lyrics_engine.listCacheEntries() 'data': await self.lyrics_engine.listCacheEntries()
} }
async def lyric_search_log_handler(self, data: ValidLyricSearchLogRequest):
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): async def lyric_search_handler(self, data: ValidLyricRequest):
""" """
Search for lyrics Search for lyrics