revisions
This commit is contained in:
		| @@ -1,5 +1,5 @@ | |||||||
| #!/usr/bin/env python3.12 | #!/usr/bin/env python3.12 | ||||||
| # pylint: disable=wrong-import-order | # pylint: disable=wrong-import-order, wrong-import-position | ||||||
|  |  | ||||||
| from typing import Optional | from typing import Optional | ||||||
| from lyric_search_new.constructors import LyricsResult | from lyric_search_new.constructors import LyricsResult | ||||||
| @@ -22,6 +22,7 @@ class Aggregate: | |||||||
|         self.exclude_methods = exclude_methods |         self.exclude_methods = exclude_methods | ||||||
|      |      | ||||||
|     async def search(self, artist: str, song: str) -> Optional[LyricsResult]: |     async def search(self, artist: str, song: str) -> Optional[LyricsResult]: | ||||||
|  |         """Aggregate Search""" | ||||||
|         cache_search = cache.Cache() |         cache_search = cache.Cache() | ||||||
|         genius_search = genius.Genius() |         genius_search = genius.Genius() | ||||||
|         lrclib_search = lrclib.LRCLib() |         lrclib_search = lrclib.LRCLib() | ||||||
|   | |||||||
| @@ -1,8 +1,10 @@ | |||||||
| #!/usr/bin/env python3.12 | #!/usr/bin/env python3.12 | ||||||
| # pylint: disable=wrong-import-position | # pylint: disable=wrong-import-order, wrong-import-position bare-except, broad-exception-caught | ||||||
|  |  | ||||||
| import os | import os | ||||||
|  | import logging | ||||||
| import sys | import sys | ||||||
|  | import traceback | ||||||
| sys.path.insert(1,'..') | sys.path.insert(1,'..') | ||||||
| sys.path.insert(1,'.') | sys.path.insert(1,'.') | ||||||
| from typing import Optional | from typing import Optional | ||||||
| @@ -10,6 +12,9 @@ import aiosqlite as sqlite3 | |||||||
| from lyric_search_new import utils | from lyric_search_new import utils | ||||||
| from lyric_search_new.constructors import LyricsResult | from lyric_search_new.constructors import LyricsResult | ||||||
|  |  | ||||||
|  | logger = logging.getLogger() | ||||||
|  | log_level = logging.getLevelName(logger.level) | ||||||
|  |  | ||||||
| class Cache: | class Cache: | ||||||
|     """Cache Search Module""" |     """Cache Search Module""" | ||||||
|     def __init__(self): |     def __init__(self): | ||||||
| @@ -44,6 +49,7 @@ class Cache: | |||||||
|         """ |         """ | ||||||
|         artist = artist.strip().lower() |         artist = artist.strip().lower() | ||||||
|         song = song.strip().lower() |         song = song.strip().lower() | ||||||
|  |         try: | ||||||
|             async with sqlite3.connect(self.cache_db, timeout=2) as db_conn: |             async with sqlite3.connect(self.cache_db, timeout=2) as db_conn: | ||||||
|                 await db_conn.enable_load_extension(True) |                 await db_conn.enable_load_extension(True) | ||||||
|                 for ext in self.sqlite_exts: |                 for ext in self.sqlite_exts: | ||||||
| @@ -67,9 +73,14 @@ class Cache: | |||||||
|                         if not best_match: |                         if not best_match: | ||||||
|                             return None |                             return None | ||||||
|                         (candidate, confidence) = best_match |                         (candidate, confidence) = best_match | ||||||
|  |                         logging.info("Result found on %s", self.label) | ||||||
|                         return self.get_matched(sqlite_rows=results, |                         return self.get_matched(sqlite_rows=results, | ||||||
|                                                 matched_candidate=candidate, |                                                 matched_candidate=candidate, | ||||||
|                                                 confidence=confidence) |                                                 confidence=confidence) | ||||||
|  |         except: | ||||||
|  |             if log_level == "DEBUG": | ||||||
|  |                 traceback.print_exc() | ||||||
|  |             return | ||||||
|                                                  |                                                  | ||||||
|                  |                  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,9 +1,10 @@ | |||||||
| #!/usr/bin/env python3.12 | #!/usr/bin/env python3.12 | ||||||
| # pylint: disable=bare-except, broad-exception-caught, wrong-import-position | # pylint: disable=bare-except, broad-exception-caught, wrong-import-order, wrong-import-position | ||||||
|  |  | ||||||
| import sys | import sys | ||||||
| sys.path.insert(1,'..') | sys.path.insert(1,'..') | ||||||
| import traceback | import traceback | ||||||
|  | import logging | ||||||
| from aiohttp import ClientTimeout, ClientSession | from aiohttp import ClientTimeout, ClientSession | ||||||
| from bs4 import BeautifulSoup | from bs4 import BeautifulSoup | ||||||
| import html as htm | import html as htm | ||||||
| @@ -12,8 +13,12 @@ from . import common | |||||||
| from lyric_search_new import utils | from lyric_search_new import utils | ||||||
| from lyric_search_new.constructors import LyricsResult | from lyric_search_new.constructors import LyricsResult | ||||||
|  |  | ||||||
|  | logger = logging.getLogger() | ||||||
|  | log_level = logging.getLevelName(logger.level) | ||||||
|  |  | ||||||
| class InvalidResponseException(Exception): | class InvalidResponseException(Exception): | ||||||
|     """ |     """ | ||||||
|  |     InvalidResponseException | ||||||
|     """ |     """ | ||||||
|  |  | ||||||
| class Genius: | class Genius: | ||||||
| @@ -94,6 +99,7 @@ class Genius: | |||||||
|                         returned_lyrics = self.datautils.scrub_lyrics(returned_lyrics) |                         returned_lyrics = self.datautils.scrub_lyrics(returned_lyrics) | ||||||
|                         artist = track.split(" - ", maxsplit=1)[0] |                         artist = track.split(" - ", maxsplit=1)[0] | ||||||
|                         song = track.split(" - ", maxsplit=1)[1] |                         song = track.split(" - ", maxsplit=1)[1] | ||||||
|  |                         logging.info("Result found on %s", self.label) | ||||||
|                         return LyricsResult(artist=artist, |                         return LyricsResult(artist=artist, | ||||||
|                                             song=song, |                                             song=song, | ||||||
|                                             src=self.label, |                                             src=self.label, | ||||||
| @@ -101,6 +107,7 @@ class Genius: | |||||||
|                                             confidence=confidence) |                                             confidence=confidence) | ||||||
|  |  | ||||||
|         except: |         except: | ||||||
|  |             if log_level == "DEBUG": | ||||||
|                 traceback.print_exc() |                 traceback.print_exc() | ||||||
|             return |             return | ||||||
|                  |                  | ||||||
|   | |||||||
| @@ -4,11 +4,15 @@ | |||||||
| import sys | import sys | ||||||
| sys.path.insert(1,'..') | sys.path.insert(1,'..') | ||||||
| import traceback | import traceback | ||||||
|  | import logging | ||||||
| from aiohttp import ClientTimeout, ClientSession | from aiohttp import ClientTimeout, ClientSession | ||||||
| from lyric_search_new import utils | from lyric_search_new import utils | ||||||
| from lyric_search_new.constructors import LyricsResult | from lyric_search_new.constructors import LyricsResult | ||||||
| from . import common | from . import common | ||||||
|  |  | ||||||
|  | logger = logging.getLogger() | ||||||
|  | log_level = logging.getLevelName(logger.level) | ||||||
|  |  | ||||||
| class InvalidResponseException(Exception): | class InvalidResponseException(Exception): | ||||||
|     """ |     """ | ||||||
|     Invalid Response Exception |     Invalid Response Exception | ||||||
| @@ -68,13 +72,14 @@ class LRCLib: | |||||||
|                                                                         candidate_tracks=[(0, returned_track)]) |                                                                         candidate_tracks=[(0, returned_track)]) | ||||||
|                     if not confidence: |                     if not confidence: | ||||||
|                         return # No suitable match found |                         return # No suitable match found | ||||||
|                     print("Returning!") |                     logging.info("Result found on %s", self.label) | ||||||
|                     return LyricsResult(artist=returned_artist, |                     return LyricsResult(artist=returned_artist, | ||||||
|                                         song=returned_song, |                                         song=returned_song, | ||||||
|                                         src=self.label, |                                         src=self.label, | ||||||
|                                         lyrics=returned_lyrics, |                                         lyrics=returned_lyrics, | ||||||
|                                         confidence=confidence) |                                         confidence=confidence) | ||||||
|         except: |         except: | ||||||
|  |             if log_level == "DEBUG": | ||||||
|                 traceback.print_exc() |                 traceback.print_exc() | ||||||
|             return |             return | ||||||
|                  |                  | ||||||
|   | |||||||
| @@ -34,8 +34,6 @@ class TrackMatcher: | |||||||
|         # Normalize input track |         # Normalize input track | ||||||
|         input_track = self._normalize_string(input_track) |         input_track = self._normalize_string(input_track) | ||||||
|          |          | ||||||
|         print(f"input_track: {input_track}") |  | ||||||
|          |  | ||||||
|         best_match = None |         best_match = None | ||||||
|         best_score = 0 |         best_score = 0 | ||||||
|  |  | ||||||
| @@ -64,7 +62,6 @@ class TrackMatcher: | |||||||
|         """ |         """ | ||||||
|         # Remove special characters and convert 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 |         # Normalize spaces | ||||||
|         text = ' '.join(text.split()) |         text = ' '.join(text.split()) | ||||||
|         return text |         return text | ||||||
| @@ -89,7 +86,7 @@ class DataUtils: | |||||||
|     Data Utils |     Data Utils | ||||||
|     """ |     """ | ||||||
|     def scrub_lyrics(self, lyrics: str) -> str: |     def scrub_lyrics(self, lyrics: str) -> str: | ||||||
|         # Regex chain |         """Regex Chain""" | ||||||
|         lyrics = regex.sub(r'(\[.*?\])(\s){0,}(\:){0,1}', '', lyrics) |         lyrics = regex.sub(r'(\[.*?\])(\s){0,}(\:){0,1}', '', lyrics) | ||||||
|         lyrics = regex.sub(r'(\d?)(Embed\b)', '', lyrics, flags=regex.IGNORECASE) |         lyrics = regex.sub(r'(\d?)(Embed\b)', '', lyrics, flags=regex.IGNORECASE) | ||||||
|         lyrics = regex.sub(r'\n{2}', '\n', lyrics)  # Gaps between verses |         lyrics = regex.sub(r'\n{2}', '\n', lyrics)  # Gaps between verses | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user