Commit ec80a332 authored by codey's avatar codey
Browse files

misc/version bump

parent bc333b42
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -16,12 +16,12 @@ logger.setLevel(logging.INFO)

loop = asyncio.get_event_loop()
app = FastAPI(title="codey.lol API",
              version="0.1a",
              version="1.0",
              contact={
                  'name': 'codey'
              },
              redirect_slashes=False,
              loop=loop)
app.loop = loop

constants = importlib.import_module("constants").Constants()
util = importlib.import_module("util").Utilities(app, constants)
@@ -82,6 +82,7 @@ End Blacklisted Routes
"""
Actionable Routes
"""

randmsg_endpoint = importlib.import_module("endpoints.rand_msg").RandMsg(app, util, constants, glob_state)
transcription_endpoints = importlib.import_module("endpoints.transcriptions").Transcriptions(app, util, constants, glob_state)
ai_endpoints = importlib.import_module("endpoints.ai").AI(app, util, constants, glob_state)
+14 −11
Original line number Diff line number Diff line
@@ -64,22 +64,22 @@ class LastFM(FastAPI):
        self.lastfm = importlib.import_module("lastfm_wrapper").LastFM()

        self.endpoints = {
            "get_artist_by_name": self.artist_by_name_handler,
            "get_artist_albums": self.artist_album_handler,
            "get_release": self.release_detail_handler,
            "get_release_tracklist": self.release_tracklist_handler,
            "get_track_info": self.track_info_handler,
            "lastfm/get_artist_by_name": self.artist_by_name_handler,
            "lastfm/get_artist_albums": self.artist_album_handler,
            "lastfm/get_release": self.release_detail_handler,
            "lastfm/get_release_tracklist": self.release_tracklist_handler,
            "lastfm/get_track_info": self.track_info_handler,
            #tbd
            }

        for endpoint, handler in self.endpoints.items():
            app.add_api_route(f"/{endpoint}", handler, methods=["POST"],
                              include_in_schema=False)
                              include_in_schema=True)
    
    async def artist_by_name_handler(self, data: ValidArtistSearchRequest):
        """
        /get_artist_by_name/
        Get artist info
        - **a**: Artist to search
        """
        artist = data.a.strip()
        if not artist:
@@ -102,8 +102,8 @@ class LastFM(FastAPI):
    
    async def artist_album_handler(self, data: ValidArtistSearchRequest):
        """
        /get_artist_albums/
        Get artist's albums/releases
        - **a**: Artist to search
        """
        artist = data.a.strip()
        if not artist:
@@ -130,8 +130,9 @@ class LastFM(FastAPI):

    async def release_detail_handler(self, data: ValidAlbumDetailRequest):
        """
        /get_release/
        Get details of a particular release by an artist
        - **a**: Artist to search
        - **a2**: Release title to search (subject to change)
        """
        artist = data.a.strip()
        release = data.a2.strip()
@@ -158,8 +159,9 @@ class LastFM(FastAPI):
    
    async def release_tracklist_handler(self, data: ValidAlbumDetailRequest):
        """
        /get_release_tracklist/
        Get track list for a particular release by an artist
        - **a**: Artist to search
        - **a2**: Release title to search (subject to change)
        """
        artist = data.a.strip()
        release = data.a2.strip()
@@ -182,8 +184,9 @@ class LastFM(FastAPI):

    async def track_info_handler(self, data: ValidTrackInfoRequest):
        """
         /get_track_info/
         Get track info from Last.FM given an artist/track
         - **a**: Artist to search
         - **t**: Track title to search
         """    
        try:
            artist = data.a
+3 −31
Original line number Diff line number Diff line
@@ -59,15 +59,6 @@ class ValidTypeAheadRequest(BaseModel):
    pre_query: str|None = None
    query: str

        
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 CacheUtils:
    """Lyrics Cache DB Utils"""
    def __init__(self):
@@ -103,8 +94,8 @@ class LyricSearch(FastAPI):
        self.endpoints = {
            "typeahead/artist": self.artist_typeahead_handler,
            "typeahead/song": self.song_typeahead_handler,
            "lyric_search": self.lyric_search_handler,
            # "lyric_cache_list": self.lyric_cache_list_handler,
            "lyric_search": self.lyric_search_handler, # Preserving old endpoint path temporarily
            "lyric/search": self.lyric_search_handler,
        }

        self.acceptable_request_sources = [
@@ -122,18 +113,9 @@ class LyricSearch(FastAPI):
        self.lrc_regex = regex.compile(r'\[([0-9]{2}:[0-9]{2})\.[0-9]{1,3}\](\s(.*)){0,}')

        for endpoint, handler in self.endpoints.items():
            _schema_include = endpoint in ["lyric_search"]
            _schema_include = endpoint in ["lyric/search"]
            app.add_api_route(f"/{endpoint}", handler, methods=["POST"], include_in_schema=_schema_include)
    
    # async def lyric_cache_list_handler(self):
    #     """
    #     Get currently cached lyrics entries
    #     """
    #     return {
    #         'err': False,
    #         'data': await self.lyrics_engine.listCacheEntries()
    #     }
    
    async def artist_typeahead_handler(self, data: ValidTypeAheadRequest):
        """Artist Type  Ahead Handler"""
        if not isinstance(data.query, str) or len(data.query) < 2:
@@ -160,16 +142,6 @@ class LyricSearch(FastAPI):
        typeahead_list = [str(r.get('song')) for r in typeahead_result]
        return typeahead_list
    
    # async def lyric_search_log_handler(self, data: ValidLyricSearchLogRequest):
    #     """Lyric Search Log Handler"""
    #     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):
        """
        Search for lyrics
+1 −1
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ class Misc(FastAPI):
        
        #TODO: change URL below to dynamically populate based on listener
        async with ClientSession() as session:
            async with await session.post("http://127.0.0.1:52111/xc/", json=json_payload,
            async with await session.post("http://127.0.0.1:52111/xc", json=json_payload,
                                    headers=headers, timeout=ClientTimeout(connect=3, sock_read=2)) as request:
                request.raise_for_status()
                request_json = await request.json()
+0 −1
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ class RandMsg(FastAPI):
    
    async def randmsg_handler(self, data: RandMsgRequest = None):
        """
        /randmsg
        Get a randomly generated message
        """
        random.seed()
Loading