From e82ca841a83a0285f60355ce4b978e0f0ed4706a Mon Sep 17 00:00:00 2001 From: codey Date: Sat, 15 Feb 2025 21:18:20 -0500 Subject: [PATCH] whoopsies --- endpoints/lyric_search.py | 2 +- lyric_search/sources/lrclib.py | 6 +++--- lyric_search/utils.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/endpoints/lyric_search.py b/endpoints/lyric_search.py index 101d01f..58a29b3 100644 --- a/endpoints/lyric_search.py +++ b/endpoints/lyric_search.py @@ -106,7 +106,7 @@ class LyricSearch(FastAPI): pre_query: str = data.pre_query query: str = data.query typeahead_result: list[dict] = await self.cache_utils.check_typeahead(query, pre_query) - typeahead_list: list[str] = [str(r.get('song')) for r in typeahead_result] + typeahead_list: list[str] = [str(r['song']) for r in typeahead_result] return JSONResponse(content=typeahead_list) async def lyric_search_handler(self, data: ValidLyricRequest) -> JSONResponse: diff --git a/lyric_search/sources/lrclib.py b/lyric_search/sources/lrclib.py index 53db76a..7948280 100644 --- a/lyric_search/sources/lrclib.py +++ b/lyric_search/sources/lrclib.py @@ -6,7 +6,7 @@ import time sys.path.insert(1,'..') import traceback import logging -from typing import Optional +from typing import Optional, Union from aiohttp import ClientTimeout, ClientSession from lyric_search import utils from lyric_search.constructors import LyricsResult @@ -69,8 +69,8 @@ class LRCLib: if len(text) < 100: raise InvalidResponseException("Search response text was invalid (len < 100 chars.)") - search_data: Optional[dict] = await request.json() - if not isinstance(search_data, dict): + search_data: Optional[Union[list, dict]] = await request.json() + if not isinstance(search_data, list|dict): raise InvalidResponseException("No JSON search data.") # logging.info("Search Data:\n%s", search_data) diff --git a/lyric_search/utils.py b/lyric_search/utils.py index 2690c6f..a289a31 100644 --- a/lyric_search/utils.py +++ b/lyric_search/utils.py @@ -57,7 +57,7 @@ class TrackMatcher: best_match = candidate # Return the match only if it meets the threshold - if best_score >= self.threshold: + if best_score < self.threshold: return None match: tuple = (best_match, round(best_score * 100)) return match @@ -106,7 +106,7 @@ class DataUtils: self.lrc_regex = regex.compile(r'\[([0-9]{2}:[0-9]{2})\.[0-9]{1,3}\](\s(.*)){0,}') self.scrub_regex_1: Pattern = regex.compile(r'(\[.*?\])(\s){0,}(\:){0,1}') self.scrub_regex_2: Pattern = regex.compile(r'(\d?)(Embed\b)', - flags=regex.IGNORECASe) + flags=regex.IGNORECASE) self.scrub_regex_3: Pattern = regex.compile(r'\n{2}') self.scrub_regex_4: Pattern = regex.compile(r'[0-9]\b$')