diff --git a/endpoints/lyric_search.py b/endpoints/lyric_search.py index 1c8c91c..2a45503 100644 --- a/endpoints/lyric_search.py +++ b/endpoints/lyric_search.py @@ -206,7 +206,7 @@ class LyricSearch(FastAPI): logging.debug("Found %s at %s, match for %s!", line, seeked_found_line, data.sub) # REMOVEME: DEBUG break - + if not seeked_found_line: return { 'failed_seek': True, @@ -214,7 +214,7 @@ class LyricSearch(FastAPI): result['lyrics'] = " / ".join(lyric_lines[seeked_found_line:]) result['lyrics'] = regex.sub(r'(\s/\s|\n)', '
', result['lyrics']).strip() - result['confidence'] = f'{float(result.get('confidence', 0)):.2f}' + result['confidence'] = int(result.get('confidence', 0)) result['time'] = f'{float(result['time']):.4f}' if "cached" in result['src']: result['from_cache'] = True diff --git a/lyric_search_new/constructors.py b/lyric_search_new/constructors.py index e1fd767..a95c5cc 100644 --- a/lyric_search_new/constructors.py +++ b/lyric_search_new/constructors.py @@ -9,7 +9,7 @@ class LyricsResult: song: str src: str lyrics: str - confidence: float + confidence: int time: float = 0.00 def dict(self): diff --git a/lyric_search_new/sources/cache.py b/lyric_search_new/sources/cache.py index 93fc82a..33ceb77 100644 --- a/lyric_search_new/sources/cache.py +++ b/lyric_search_new/sources/cache.py @@ -29,7 +29,7 @@ class Cache: self.sqlite_exts: list[str] = ['/usr/local/lib/python3.11/dist-packages/spellfix1.cpython-311-x86_64-linux-gnu.so'] self.label: str = "Cache" - def get_matched(self, sqlite_rows: list[sqlite3.Row], matched_candidate: tuple, confidence: float) -> Optional[LyricsResult]: + def get_matched(self, sqlite_rows: list[sqlite3.Row], matched_candidate: tuple, confidence: int) -> Optional[LyricsResult]: """Get Matched Result""" matched_id: int = matched_candidate[0] for row in sqlite_rows: @@ -148,7 +148,7 @@ class Cache: best_match: tuple|None = matcher.find_best_match(input_track=input_track, candidate_tracks=result_tracks) else: - best_match = (result_tracks[0], float(1)) + best_match = (result_tracks[0], 100) if not best_match: return None (candidate, confidence) = best_match diff --git a/lyric_search_new/utils.py b/lyric_search_new/utils.py index 627e6fc..cac1088 100644 --- a/lyric_search_new/utils.py +++ b/lyric_search_new/utils.py @@ -2,6 +2,7 @@ from difflib import SequenceMatcher from typing import List, Optional, Tuple +import logging import regex class TrackMatcher: @@ -28,6 +29,8 @@ class TrackMatcher: Optional[Tuple[int, str, float]]: Tuple of (best matching track, similarity score) or None if no good match found """ + + if not input_track or not candidate_tracks: return None @@ -53,7 +56,7 @@ class TrackMatcher: best_match = candidate # Return the match only if it meets the threshold - return (best_match, round(best_score, 2)) if best_score >= self.threshold else None + return (best_match, round(best_score *100)) if best_score >= self.threshold else None def _normalize_string(self, text: str) -> str: """