From 1d7589ffbd1b0e2d3fafcd36dbdf5808ae1e3f70 Mon Sep 17 00:00:00 2001 From: codey Date: Tue, 1 Jul 2025 13:02:53 -0400 Subject: [PATCH] misc/formatting ++ resolve #33 (restructured radio DBs, combined genre into track_file_map, revised query w/ INNER JOIN) --- endpoints/lastfm.py | 8 +++++--- endpoints/lyric_search.py | 10 +++++----- endpoints/meme.py | 16 ++++++---------- endpoints/misc.py | 5 +++-- endpoints/rand_msg.py | 8 ++++---- endpoints/transcriptions.py | 8 +++++--- endpoints/yt.py | 8 +++++--- utils/radio_util.py | 20 ++++++++++---------- 8 files changed, 43 insertions(+), 40 deletions(-) diff --git a/endpoints/lastfm.py b/endpoints/lastfm.py index 46a20db..b20e213 100644 --- a/endpoints/lastfm.py +++ b/endpoints/lastfm.py @@ -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( diff --git a/endpoints/lyric_search.py b/endpoints/lyric_search.py index 9d9078c..965443f 100644 --- a/endpoints/lyric_search.py +++ b/endpoints/lyric_search.py @@ -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, diff --git a/endpoints/meme.py b/endpoints/meme.py index 27d0ae0..f048ac8 100644 --- a/endpoints/meme.py +++ b/endpoints/meme.py @@ -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: diff --git a/endpoints/misc.py b/endpoints/misc.py index 50dfb56..13d2d7d 100644 --- a/endpoints/misc.py +++ b/endpoints/misc.py @@ -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))], ) @@ -72,7 +74,6 @@ class Misc(FastAPI): except Exception as e: logging.debug("Exception: %s", str(e)) return "No." - async def no(self) -> JSONResponse: """NaaS""" diff --git a/endpoints/rand_msg.py b/endpoints/rand_msg.py index 15a729f..aa4eb03 100644 --- a/endpoints/rand_msg.py +++ b/endpoints/rand_msg.py @@ -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( diff --git a/endpoints/transcriptions.py b/endpoints/transcriptions.py index 9c740d8..b453024 100644 --- a/endpoints/transcriptions.py +++ b/endpoints/transcriptions.py @@ -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( diff --git a/endpoints/yt.py b/endpoints/yt.py index a4b870e..dd86b7c 100644 --- a/endpoints/yt.py +++ b/endpoints/yt.py @@ -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: diff --git a/utils/radio_util.py b/utils/radio_util.py index 3b17d52..0a99742 100644 --- a/utils/radio_util.py +++ b/utils/radio_util.py @@ -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)