tweaks
This commit is contained in:
parent
915b77fe19
commit
d58f2f9413
@ -185,7 +185,8 @@ class LyricSearch(FastAPI):
|
||||
|
||||
excluded_sources = data.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:
|
||||
return {
|
||||
'err': True,
|
||||
|
@ -21,8 +21,11 @@ class Aggregate:
|
||||
exclude_methods: list = []
|
||||
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"""
|
||||
if not plain:
|
||||
logging.info("LRCs requested, limiting search to LRCLib")
|
||||
self.exclude_methods = ["genius", "cache"]
|
||||
logging.info("Performing aggregate search")
|
||||
cache_search = cache.Cache()
|
||||
genius_search = genius.Genius()
|
||||
@ -35,7 +38,8 @@ class Aggregate:
|
||||
if source.label.lower() in self.exclude_methods:
|
||||
logging.info("Skipping source: %s, excluded.", source.label)
|
||||
continue
|
||||
search_result = await source.search(artist, song)
|
||||
search_result = await source.search(artist=artist, song=song,
|
||||
plain=plain)
|
||||
if search_result:
|
||||
break
|
||||
logging.info("%s: NOT FOUND!", source.label)
|
||||
|
@ -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
|
||||
@artist: the artist to search
|
||||
|
@ -32,12 +32,12 @@ class Genius:
|
||||
self.genius_url: str = private.GENIUS_URL
|
||||
self.genius_search_url: str = f'{self.genius_url}api/search/song?q='
|
||||
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.matcher = utils.TrackMatcher()
|
||||
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
|
||||
@song: the song to search
|
||||
|
@ -32,7 +32,7 @@ class LRCLib:
|
||||
self.matcher = utils.TrackMatcher()
|
||||
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
|
||||
@song: the song to search
|
||||
@ -82,13 +82,17 @@ class LRCLib:
|
||||
if not isinstance(search_data[best_match_id]['trackName'], str):
|
||||
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_song: str = search_data[best_match_id]['trackName']
|
||||
returned_lyrics: str = search_data[best_match_id]['plainLyrics']
|
||||
returned_lyrics = self.datautils.scrub_lyrics(returned_lyrics)
|
||||
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 = 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}"
|
||||
(_matched, confidence) = self.matcher.find_best_match(input_track=input_track,
|
||||
candidate_tracks=[(0, returned_track)])
|
||||
|
Loading…
x
Reference in New Issue
Block a user