radio_util: open tracks SQLite DB in readonly mode; black: reformat files

This commit is contained in:
2025-04-17 07:28:05 -04:00
parent 96add377df
commit 6c88c23a4d
25 changed files with 1913 additions and 1340 deletions

View File

@ -4,12 +4,13 @@ from fastapi.responses import JSONResponse
from typing import Optional, Union
from .constructors import ValidYTSearchRequest
class YT(FastAPI):
"""
YT Endpoints
"""
def __init__(self, app: FastAPI, util,
constants) -> None:
"""
def __init__(self, app: FastAPI, util, constants) -> None:
self.app: FastAPI = app
self.util = util
self.constants = constants
@ -17,28 +18,34 @@ class YT(FastAPI):
self.endpoints: dict = {
"yt/search": self.yt_video_search_handler,
}
}
for endpoint, handler in self.endpoints.items():
app.add_api_route(f"/{endpoint}", handler, methods=["POST"],
include_in_schema=True)
app.add_api_route(
f"/{endpoint}", handler, methods=["POST"], include_in_schema=True
)
async def yt_video_search_handler(self, data: ValidYTSearchRequest) -> JSONResponse:
"""
Search for YT Video by Title (closest match returned)
- **t**: Title to search
"""
title: str = data.t
yts_res: Optional[list[dict]] = await self.ytsearch.search(title)
if not yts_res:
return JSONResponse(status_code=404, content={
'err': True,
'errorText': 'No result.',
})
yt_video_id: Union[str, bool] = yts_res[0].get('id', False)
return JSONResponse(
status_code=404,
content={
"err": True,
"errorText": "No result.",
},
)
yt_video_id: Union[str, bool] = yts_res[0].get("id", False)
return JSONResponse(content={
'video_id': yt_video_id,
'extras': yts_res[0],
})
return JSONResponse(
content={
"video_id": yt_video_id,
"extras": yts_res[0],
}
)