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