diff --git a/endpoints/lyric_search.py b/endpoints/lyric_search.py index 290c4de..e9d899b 100644 --- a/endpoints/lyric_search.py +++ b/endpoints/lyric_search.py @@ -123,7 +123,9 @@ class LyricSearch(FastAPI): aggregate_search = aggregate.Aggregate() result = await aggregate_search.search(data.a, data.s) - return result.dict() + result = result.dict() + result['lyrics'] = regex.sub(r'(\s/\s|\n)', '
', result['lyrics']).strip() + return result diff --git a/lyric_search_new/__init__.py b/lyric_search_new/__init__.py index e69de29..5a4829a 100644 --- a/lyric_search_new/__init__.py +++ b/lyric_search_new/__init__.py @@ -0,0 +1,2 @@ +""" +""" \ No newline at end of file diff --git a/lyric_search_new/sources/aggregate.py b/lyric_search_new/sources/aggregate.py index 819ea5b..591a9e6 100644 --- a/lyric_search_new/sources/aggregate.py +++ b/lyric_search_new/sources/aggregate.py @@ -8,6 +8,7 @@ sys.path.insert(1,'..') sys.path.insert(1,'..') from . import cache from . import genius + class Aggregate: """Aggregate all source methods""" diff --git a/lyric_search_new/sources/cache.py b/lyric_search_new/sources/cache.py index 8f80baa..0b19e6b 100644 --- a/lyric_search_new/sources/cache.py +++ b/lyric_search_new/sources/cache.py @@ -1,12 +1,12 @@ #!/usr/bin/env python3.12 +# pylint: disable=wrong-import-position import os import sys sys.path.insert(1,'..') -import aiosqlite as sqlite3 +sys.path.insert(1,'.') from typing import Optional -from . import private -from . import common +import aiosqlite as sqlite3 from lyric_search_new import utils from lyric_search_new.constructors import LyricsResult @@ -21,6 +21,7 @@ class Cache: self.sqlite_exts = ['/usr/local/lib/python3.11/dist-packages/spellfix1.cpython-311-x86_64-linux-gnu.so'] def get_matched(self, sqlite_rows, matched_candidate, confidence) -> Optional[LyricsResult]: + """Get Matched Result""" matched_id = matched_candidate[0] for row in sqlite_rows: if row[0] == matched_id: @@ -40,6 +41,8 @@ class Cache: Returns: - LyricsResult corresponding to nearest match found (if found), **None** otherwise """ + artist = artist.strip().lower() + song = song.strip().lower() async with sqlite3.connect(self.cache_db, timeout=2) as db_conn: await db_conn.enable_load_extension(True) for ext in self.sqlite_exts: @@ -47,7 +50,9 @@ class Cache: async with await db_conn.executescript(self.cache_pre_query) as _db_cursor: search_query = 'SELECT id, artist, song, lyrics, src, confidence FROM lyrics WHERE editdist3((artist || " " || song), (? || " " || ?))\ <= 410 ORDER BY editdist3((artist || " " || song), ?) ASC LIMIT 10' - async with await _db_cursor.execute(search_query, (artist.strip(), song.strip(), f"{artist.strip()} {song.strip()}")) as db_cursor: + search_params = (artist.strip(), song.strip(), + f"{artist.strip()} {song.strip()}") + async with await _db_cursor.execute(search_query, search_params) as db_cursor: results = await db_cursor.fetchall() result_tracks = [] for track in results: diff --git a/lyric_search_new/sources/genius.py b/lyric_search_new/sources/genius.py index 89c6324..a0e4dca 100644 --- a/lyric_search_new/sources/genius.py +++ b/lyric_search_new/sources/genius.py @@ -33,6 +33,8 @@ class Genius: @song: the song to search """ try: + artist = artist.strip().lower() + song = song.strip().lower() search_term = f'{artist}%20{song}' returned_lyrics = '' async with ClientSession() as client: diff --git a/lyric_search_new/tests.py b/lyric_search_new/tests.py index bb8ef41..a697af5 100644 --- a/lyric_search_new/tests.py +++ b/lyric_search_new/tests.py @@ -3,8 +3,8 @@ import asyncio import sys +sys.path.insert(1, '.') import sources.cache, sources.genius, sources.aggregate -import utils test_artist = "hopsin" test_song = "ill mind of hopsin 5" @@ -39,6 +39,6 @@ async def test_aggregate(artist=None, song=None): loop = asyncio.new_event_loop() -loop.run_until_complete(test_genius()) +# loop.run_until_complete(test_genius()) loop.run_until_complete(test_cache(artist=test_artist, song=test_song)) -loop.run_until_complete(test_aggregate()) +# loop.run_until_complete(test_aggregate()) diff --git a/lyric_search_new/utils.py b/lyric_search_new/utils.py index f439fc1..043448a 100644 --- a/lyric_search_new/utils.py +++ b/lyric_search_new/utils.py @@ -63,7 +63,8 @@ class TrackMatcher: extra spaces, and converting to lowercase. """ # Remove special characters and convert to lowercase - text = regex.sub(r'[^\w\s-]', '', text.lower()) + text = regex.sub(r'[^\w\s-]', '', text).lower() + print(f"Text: {text}") # Normalize spaces text = ' '.join(text.split()) return text