misc/formatting ++ resolve #33 (restructured radio DBs, combined genre into track_file_map, revised query w/ INNER JOIN)

This commit is contained in:
2025-07-01 13:02:53 -04:00
parent c3f753a4f0
commit 1d7589ffbd
8 changed files with 43 additions and 40 deletions

View File

@ -33,9 +33,11 @@ class LastFM(FastAPI):
for endpoint, handler in self.endpoints.items():
app.add_api_route(
f"/{endpoint}", handler,
methods=["POST"], include_in_schema=True,
dependencies=[Depends(RateLimiter(times=2, seconds=2))]
f"/{endpoint}",
handler,
methods=["POST"],
include_in_schema=True,
dependencies=[Depends(RateLimiter(times=2, seconds=2))],
)
async def artist_by_name_handler(

View File

@ -77,7 +77,7 @@ class LyricSearch(FastAPI):
handler,
methods=["POST"],
include_in_schema=_schema_include,
dependencies=[Depends(RateLimiter(times=2, seconds=3))]
dependencies=[Depends(RateLimiter(times=2, seconds=3))],
)
async def typeahead_handler(self, data: ValidTypeAheadRequest) -> JSONResponse:
@ -170,10 +170,10 @@ class LyricSearch(FastAPI):
)
if not result:
if not data.lrc:
await self.notifier.send(
"DEBUG", f"Could not locate lyrics, request was:\n`{data}`"
)
# if not data.lrc:
# await self.notifier.send(
# "DEBUG", f"Could not locate lyrics, request was:\n`{data}`"
# )
return JSONResponse(
content={
"err": True,

View File

@ -1,9 +1,5 @@
import logging
from fastapi import (
FastAPI,
Request,
Response,
Depends)
from fastapi import FastAPI, Request, Response, Depends
from fastapi_throttle import RateLimiter
from fastapi.responses import JSONResponse
from utils.meme_util import MemeUtil
@ -27,11 +23,11 @@ class Meme(FastAPI):
for endpoint, handler in self.endpoints.items():
app.add_api_route(
f"/{endpoint}", handler,
methods=["GET"], include_in_schema=True,
dependencies=[Depends(
RateLimiter(times=2, seconds=2)
)]
f"/{endpoint}",
handler,
methods=["GET"],
include_in_schema=True,
dependencies=[Depends(RateLimiter(times=10, seconds=1))],
)
async def get_meme_by_id(self, id: int, request: Request) -> Response:

View File

@ -49,7 +49,9 @@ class Misc(FastAPI):
)
app.add_api_route(
"/misc/upload_activity_image", self.upload_activity_image, methods=["POST"],
"/misc/upload_activity_image",
self.upload_activity_image,
methods=["POST"],
dependencies=[Depends(RateLimiter(times=2, seconds=5))],
)
@ -73,7 +75,6 @@ class Misc(FastAPI):
logging.debug("Exception: %s", str(e))
return "No."
async def no(self) -> JSONResponse:
"""NaaS"""
return JSONResponse(content={"no": self.get_no()})

View File

@ -20,10 +20,10 @@ class RandMsg(FastAPI):
self.endpoint_name = "randmsg"
app.add_api_route(
f"/{self.endpoint_name}", self.randmsg_handler,
methods=["POST"], dependencies=[Depends(
RateLimiter(times=5, seconds=2)
)]
f"/{self.endpoint_name}",
self.randmsg_handler,
methods=["POST"],
dependencies=[Depends(RateLimiter(times=5, seconds=2))],
)
async def randmsg_handler(

View File

@ -25,9 +25,11 @@ class Transcriptions(FastAPI):
for endpoint, handler in self.endpoints.items():
app.add_api_route(
f"/{endpoint}", handler,
methods=["POST"], include_in_schema=True,
dependencies=[Depends(RateLimiter(times=2, seconds=2))]
f"/{endpoint}",
handler,
methods=["POST"],
include_in_schema=True,
dependencies=[Depends(RateLimiter(times=2, seconds=2))],
)
async def get_episodes_handler(

View File

@ -23,9 +23,11 @@ class YT(FastAPI):
for endpoint, handler in self.endpoints.items():
app.add_api_route(
f"/{endpoint}", handler,
methods=["POST"], include_in_schema=True,
dependencies=[Depends(RateLimiter(times=2, seconds=2))]
f"/{endpoint}",
handler,
methods=["POST"],
include_in_schema=True,
dependencies=[Depends(RateLimiter(times=2, seconds=2))],
)
async def yt_video_search_handler(self, data: ValidYTSearchRequest) -> JSONResponse:

View File

@ -377,7 +377,7 @@ class RadioUtil:
"artist": double_space.sub(" ", r["artist"]).strip(),
"song": double_space.sub(" ", r["song"]).strip(),
"album": double_space.sub(" ", r["album"]).strip(),
"genre": "N/A",
"genre": r["genre"],
"artistsong": double_space.sub(
" ", r["artistdashsong"]
).strip(),
@ -392,19 +392,19 @@ class RadioUtil:
len(self.active_playlist),
)
logging.info(
"Adding genre data..."
)
# logging.info(
# "Adding genre data..."
# )
artist_genre = self.get_genres([
str(r.get('artist')) for r in self.active_playlist])
# artist_genre = self.get_genres([
# str(r.get('artist')) for r in self.active_playlist])
for item in self.active_playlist:
artist = double_space.sub(" ", item["artist"]).strip()
item['genre'] = artist_genre[artist]
# for item in self.active_playlist:
# artist = double_space.sub(" ", item["artist"]).strip()
# item['genre'] = artist_genre[artist]
logging.info("Genre data added.")
# logging.info("Genre data added.")
random.shuffle(self.active_playlist)