misc/formatting ++ resolve #33 (restructured radio DBs, combined genre into track_file_map, revised query w/ INNER JOIN)
This commit is contained in:
@ -33,9 +33,11 @@ class LastFM(FastAPI):
|
|||||||
|
|
||||||
for endpoint, handler in self.endpoints.items():
|
for endpoint, handler in self.endpoints.items():
|
||||||
app.add_api_route(
|
app.add_api_route(
|
||||||
f"/{endpoint}", handler,
|
f"/{endpoint}",
|
||||||
methods=["POST"], include_in_schema=True,
|
handler,
|
||||||
dependencies=[Depends(RateLimiter(times=2, seconds=2))]
|
methods=["POST"],
|
||||||
|
include_in_schema=True,
|
||||||
|
dependencies=[Depends(RateLimiter(times=2, seconds=2))],
|
||||||
)
|
)
|
||||||
|
|
||||||
async def artist_by_name_handler(
|
async def artist_by_name_handler(
|
||||||
|
@ -77,7 +77,7 @@ class LyricSearch(FastAPI):
|
|||||||
handler,
|
handler,
|
||||||
methods=["POST"],
|
methods=["POST"],
|
||||||
include_in_schema=_schema_include,
|
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:
|
async def typeahead_handler(self, data: ValidTypeAheadRequest) -> JSONResponse:
|
||||||
@ -170,10 +170,10 @@ class LyricSearch(FastAPI):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if not result:
|
if not result:
|
||||||
if not data.lrc:
|
# if not data.lrc:
|
||||||
await self.notifier.send(
|
# await self.notifier.send(
|
||||||
"DEBUG", f"Could not locate lyrics, request was:\n`{data}`"
|
# "DEBUG", f"Could not locate lyrics, request was:\n`{data}`"
|
||||||
)
|
# )
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
content={
|
content={
|
||||||
"err": True,
|
"err": True,
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
from fastapi import (
|
from fastapi import FastAPI, Request, Response, Depends
|
||||||
FastAPI,
|
|
||||||
Request,
|
|
||||||
Response,
|
|
||||||
Depends)
|
|
||||||
from fastapi_throttle import RateLimiter
|
from fastapi_throttle import RateLimiter
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
from utils.meme_util import MemeUtil
|
from utils.meme_util import MemeUtil
|
||||||
@ -27,11 +23,11 @@ class Meme(FastAPI):
|
|||||||
|
|
||||||
for endpoint, handler in self.endpoints.items():
|
for endpoint, handler in self.endpoints.items():
|
||||||
app.add_api_route(
|
app.add_api_route(
|
||||||
f"/{endpoint}", handler,
|
f"/{endpoint}",
|
||||||
methods=["GET"], include_in_schema=True,
|
handler,
|
||||||
dependencies=[Depends(
|
methods=["GET"],
|
||||||
RateLimiter(times=2, seconds=2)
|
include_in_schema=True,
|
||||||
)]
|
dependencies=[Depends(RateLimiter(times=10, seconds=1))],
|
||||||
)
|
)
|
||||||
|
|
||||||
async def get_meme_by_id(self, id: int, request: Request) -> Response:
|
async def get_meme_by_id(self, id: int, request: Request) -> Response:
|
||||||
|
@ -49,7 +49,9 @@ class Misc(FastAPI):
|
|||||||
)
|
)
|
||||||
|
|
||||||
app.add_api_route(
|
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))],
|
dependencies=[Depends(RateLimiter(times=2, seconds=5))],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -73,7 +75,6 @@ class Misc(FastAPI):
|
|||||||
logging.debug("Exception: %s", str(e))
|
logging.debug("Exception: %s", str(e))
|
||||||
return "No."
|
return "No."
|
||||||
|
|
||||||
|
|
||||||
async def no(self) -> JSONResponse:
|
async def no(self) -> JSONResponse:
|
||||||
"""NaaS"""
|
"""NaaS"""
|
||||||
return JSONResponse(content={"no": self.get_no()})
|
return JSONResponse(content={"no": self.get_no()})
|
||||||
|
@ -20,10 +20,10 @@ class RandMsg(FastAPI):
|
|||||||
self.endpoint_name = "randmsg"
|
self.endpoint_name = "randmsg"
|
||||||
|
|
||||||
app.add_api_route(
|
app.add_api_route(
|
||||||
f"/{self.endpoint_name}", self.randmsg_handler,
|
f"/{self.endpoint_name}",
|
||||||
methods=["POST"], dependencies=[Depends(
|
self.randmsg_handler,
|
||||||
RateLimiter(times=5, seconds=2)
|
methods=["POST"],
|
||||||
)]
|
dependencies=[Depends(RateLimiter(times=5, seconds=2))],
|
||||||
)
|
)
|
||||||
|
|
||||||
async def randmsg_handler(
|
async def randmsg_handler(
|
||||||
|
@ -25,9 +25,11 @@ class Transcriptions(FastAPI):
|
|||||||
|
|
||||||
for endpoint, handler in self.endpoints.items():
|
for endpoint, handler in self.endpoints.items():
|
||||||
app.add_api_route(
|
app.add_api_route(
|
||||||
f"/{endpoint}", handler,
|
f"/{endpoint}",
|
||||||
methods=["POST"], include_in_schema=True,
|
handler,
|
||||||
dependencies=[Depends(RateLimiter(times=2, seconds=2))]
|
methods=["POST"],
|
||||||
|
include_in_schema=True,
|
||||||
|
dependencies=[Depends(RateLimiter(times=2, seconds=2))],
|
||||||
)
|
)
|
||||||
|
|
||||||
async def get_episodes_handler(
|
async def get_episodes_handler(
|
||||||
|
@ -23,9 +23,11 @@ class YT(FastAPI):
|
|||||||
|
|
||||||
for endpoint, handler in self.endpoints.items():
|
for endpoint, handler in self.endpoints.items():
|
||||||
app.add_api_route(
|
app.add_api_route(
|
||||||
f"/{endpoint}", handler,
|
f"/{endpoint}",
|
||||||
methods=["POST"], include_in_schema=True,
|
handler,
|
||||||
dependencies=[Depends(RateLimiter(times=2, seconds=2))]
|
methods=["POST"],
|
||||||
|
include_in_schema=True,
|
||||||
|
dependencies=[Depends(RateLimiter(times=2, seconds=2))],
|
||||||
)
|
)
|
||||||
|
|
||||||
async def yt_video_search_handler(self, data: ValidYTSearchRequest) -> JSONResponse:
|
async def yt_video_search_handler(self, data: ValidYTSearchRequest) -> JSONResponse:
|
||||||
|
@ -377,7 +377,7 @@ class RadioUtil:
|
|||||||
"artist": double_space.sub(" ", r["artist"]).strip(),
|
"artist": double_space.sub(" ", r["artist"]).strip(),
|
||||||
"song": double_space.sub(" ", r["song"]).strip(),
|
"song": double_space.sub(" ", r["song"]).strip(),
|
||||||
"album": double_space.sub(" ", r["album"]).strip(),
|
"album": double_space.sub(" ", r["album"]).strip(),
|
||||||
"genre": "N/A",
|
"genre": r["genre"],
|
||||||
"artistsong": double_space.sub(
|
"artistsong": double_space.sub(
|
||||||
" ", r["artistdashsong"]
|
" ", r["artistdashsong"]
|
||||||
).strip(),
|
).strip(),
|
||||||
@ -392,19 +392,19 @@ class RadioUtil:
|
|||||||
len(self.active_playlist),
|
len(self.active_playlist),
|
||||||
)
|
)
|
||||||
|
|
||||||
logging.info(
|
# logging.info(
|
||||||
"Adding genre data..."
|
# "Adding genre data..."
|
||||||
)
|
# )
|
||||||
|
|
||||||
artist_genre = self.get_genres([
|
# artist_genre = self.get_genres([
|
||||||
str(r.get('artist')) for r in self.active_playlist])
|
# str(r.get('artist')) for r in self.active_playlist])
|
||||||
|
|
||||||
|
|
||||||
for item in self.active_playlist:
|
# for item in self.active_playlist:
|
||||||
artist = double_space.sub(" ", item["artist"]).strip()
|
# artist = double_space.sub(" ", item["artist"]).strip()
|
||||||
item['genre'] = artist_genre[artist]
|
# item['genre'] = artist_genre[artist]
|
||||||
|
|
||||||
logging.info("Genre data added.")
|
# logging.info("Genre data added.")
|
||||||
|
|
||||||
random.shuffle(self.active_playlist)
|
random.shuffle(self.active_playlist)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user