This commit is contained in:
codey 2025-01-16 07:14:36 -05:00
parent 915b77fe19
commit d58f2f9413
5 changed files with 21 additions and 12 deletions

View File

@ -185,7 +185,8 @@ class LyricSearch(FastAPI):
excluded_sources = data.excluded_sources excluded_sources = data.excluded_sources
aggregate_search = aggregate.Aggregate(exclude_methods=excluded_sources) aggregate_search = aggregate.Aggregate(exclude_methods=excluded_sources)
result = await aggregate_search.search(data.a, data.s) plain_lyrics = not data.lrc
result = await aggregate_search.search(data.a, data.s, plain_lyrics)
if not result: if not result:
return { return {
'err': True, 'err': True,

View File

@ -21,8 +21,11 @@ class Aggregate:
exclude_methods: list = [] exclude_methods: list = []
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, plain: bool = True) -> Optional[LyricsResult]:
"""Aggregate Search""" """Aggregate Search"""
if not plain:
logging.info("LRCs requested, limiting search to LRCLib")
self.exclude_methods = ["genius", "cache"]
logging.info("Performing aggregate search") logging.info("Performing aggregate search")
cache_search = cache.Cache() cache_search = cache.Cache()
genius_search = genius.Genius() genius_search = genius.Genius()
@ -35,7 +38,8 @@ class Aggregate:
if source.label.lower() in self.exclude_methods: if source.label.lower() in self.exclude_methods:
logging.info("Skipping source: %s, excluded.", source.label) logging.info("Skipping source: %s, excluded.", source.label)
continue continue
search_result = await source.search(artist, song) search_result = await source.search(artist=artist, song=song,
plain=plain)
if search_result: if search_result:
break break
logging.info("%s: NOT FOUND!", source.label) logging.info("%s: NOT FOUND!", source.label)

View File

@ -100,7 +100,7 @@ class Cache:
async def search(self, artist: str, song: str) -> Optional[LyricsResult]: async def search(self, artist: str, song: str, **kwargs) -> Optional[LyricsResult]:
""" """
search search
@artist: the artist to search @artist: the artist to search

View File

@ -32,12 +32,12 @@ class Genius:
self.genius_url: str = private.GENIUS_URL self.genius_url: str = private.GENIUS_URL
self.genius_search_url: str = f'{self.genius_url}api/search/song?q=' self.genius_search_url: str = f'{self.genius_url}api/search/song?q='
self.headers: dict = common.SCRAPE_HEADERS self.headers: dict = common.SCRAPE_HEADERS
self.timeout = ClientTimeout(connect=2, sock_read=4) self.timeout = ClientTimeout(connect=3, sock_read=5)
self.datautils = utils.DataUtils() self.datautils = utils.DataUtils()
self.matcher = utils.TrackMatcher() self.matcher = utils.TrackMatcher()
self.cache = cache.Cache() self.cache = cache.Cache()
async def search(self, artist: str, song: str) -> Optional[LyricsResult]: async def search(self, artist: str, song: str, **kwargs) -> Optional[LyricsResult]:
""" """
@artist: the artist to search @artist: the artist to search
@song: the song to search @song: the song to search

View File

@ -32,7 +32,7 @@ class LRCLib:
self.matcher = utils.TrackMatcher() self.matcher = utils.TrackMatcher()
self.cache = cache.Cache() self.cache = cache.Cache()
async def search(self, artist: str, song: str) -> Optional[LyricsResult]: async def search(self, artist: str, song: str, plain: bool = True) -> Optional[LyricsResult]:
""" """
@artist: the artist to search @artist: the artist to search
@song: the song to search @song: the song to search
@ -82,13 +82,17 @@ class LRCLib:
if not isinstance(search_data[best_match_id]['trackName'], str): if not isinstance(search_data[best_match_id]['trackName'], str):
raise InvalidResponseException(f"Invalid JSON: Cannot find trackName key.\n{search_data}") raise InvalidResponseException(f"Invalid JSON: Cannot find trackName key.\n{search_data}")
if not isinstance(search_data[best_match_id]['plainLyrics'], str):
raise InvalidResponseException(f"Invalid JSON: Cannot find plainLyrics key.\n{search_data}")
returned_artist: str = search_data[best_match_id]['artistName'] returned_artist: str = search_data[best_match_id]['artistName']
returned_song: str = search_data[best_match_id]['trackName'] returned_song: str = search_data[best_match_id]['trackName']
if plain:
if not isinstance(search_data[best_match_id]['plainLyrics'], str):
raise InvalidResponseException(f"Invalid JSON: Cannot find plainLyrics key.\n{search_data}")
returned_lyrics: str = search_data[best_match_id]['plainLyrics'] returned_lyrics: str = search_data[best_match_id]['plainLyrics']
returned_lyrics = self.datautils.scrub_lyrics(returned_lyrics) returned_lyrics = self.datautils.scrub_lyrics(returned_lyrics)
else:
if not isinstance(search_data[best_match_id]['syncedLyrics'], str):
raise InvalidResponseException(f"Invalid JSON: Cannot find syncedLyrics key.\n{search_data}")
returned_lyrics: str = search_data[best_match_id]['syncedLyrics']
returned_track: str = f"{returned_artist} - {returned_song}" returned_track: str = f"{returned_artist} - {returned_song}"
(_matched, confidence) = self.matcher.find_best_match(input_track=input_track, (_matched, confidence) = self.matcher.find_best_match(input_track=input_track,
candidate_tracks=[(0, returned_track)]) candidate_tracks=[(0, returned_track)])