This commit is contained in:
codey 2025-01-14 10:52:53 -05:00
parent f86d5a4fec
commit e2d1b69df5
4 changed files with 22 additions and 21 deletions

View File

@ -121,7 +121,7 @@ class LyricSearch(FastAPI):
if not data.a or not data.s: if not data.a or not data.s:
raise HTTPException(detail="Invalid request", status_code=500) raise HTTPException(detail="Invalid request", status_code=500)
aggregate_search = aggregate.Aggregate() aggregate_search = aggregate.Aggregate(exclude_methods=None)
result = await aggregate_search.search(data.a, data.s) result = await aggregate_search.search(data.a, data.s)
if not result: if not result:
return { return {

View File

@ -4,12 +4,15 @@
from typing import Optional from typing import Optional
from lyric_search_new.constructors import LyricsResult from lyric_search_new.constructors import LyricsResult
import sys import sys
sys.path.insert(1,'..') import logging
sys.path.insert(1,'..') sys.path.insert(1,'..')
from . import cache from . import cache
from . import genius from . import genius
from . import lrclib from . import lrclib
logger = logging.getLogger()
logger.setLevel(logging.INFO)
class Aggregate: class Aggregate:
"""Aggregate all source methods""" """Aggregate all source methods"""
@ -22,20 +25,17 @@ class Aggregate:
cache_search = cache.Cache() cache_search = cache.Cache()
genius_search = genius.Genius() genius_search = genius.Genius()
lrclib_search = lrclib.LRCLib() lrclib_search = lrclib.LRCLib()
search = None sources = [cache_search,
if "cache" not in self.exclude_methods: lrclib_search,
# First, try cache genius_search]
search = await cache_search.search(artist, song) search_result = None
if not search: for source in sources:
print("Cache: NOT FOUND!") if source.label.lower() in self.exclude_methods:
# Then try LRCLib logging.debug("Skipping source: %s, excluded.")
if "lrclib" not in self.exclude_methods: continue
search = await lrclib_search.search(artist, song) search_result = await source.search(artist, song)
if not search: if search_result:
print("LRCLib: Not found!") return search_result
# Then try Genius logging.debug("%s: NOT FOUND!", str(source))
if "genius" in self.exclude_methods:
return # Skipped last possible source, return None
search = await genius_search.search(artist, song)
return search return search_result

View File

@ -19,6 +19,7 @@ class Cache:
self.cache_pre_query = "pragma journal_mode = WAL; pragma synchronous = normal; pragma temp_store = memory; pragma mmap_size = 30000000000;" self.cache_pre_query = "pragma journal_mode = WAL; pragma synchronous = normal; pragma temp_store = memory; pragma mmap_size = 30000000000;"
self.sqlite_exts = ['/usr/local/lib/python3.11/dist-packages/spellfix1.cpython-311-x86_64-linux-gnu.so'] self.sqlite_exts = ['/usr/local/lib/python3.11/dist-packages/spellfix1.cpython-311-x86_64-linux-gnu.so']
self.label = "Cache"
def get_matched(self, sqlite_rows, matched_candidate, confidence) -> Optional[LyricsResult]: def get_matched(self, sqlite_rows, matched_candidate, confidence) -> Optional[LyricsResult]:
"""Get Matched Result""" """Get Matched Result"""

View File

@ -7,7 +7,7 @@ sys.path.insert(1, '.')
import sources.cache, sources.genius, sources.aggregate, sources.lrclib import sources.cache, sources.genius, sources.aggregate, sources.lrclib
test_artist = "hopsin" test_artist = "hopsin"
test_song = "ill mind of hopsin 5" test_song = "ill mind of fssfgdfhopsin 5"
async def test_cache(artist, song): async def test_cache(artist, song):
cache = sources.cache.Cache() cache = sources.cache.Cache()
@ -48,6 +48,6 @@ async def test_aggregate(artist=None, song=None):
loop = asyncio.new_event_loop() loop = asyncio.new_event_loop()
# loop.run_until_complete(test_genius()) # loop.run_until_complete(test_genius())
loop.run_until_complete(test_lrclib()) # loop.run_until_complete(test_lrclib())
# loop.run_until_complete(test_cache(artist=test_artist, song=test_song)) # loop.run_until_complete(test_cache(artist=test_artist, song=test_song))
# loop.run_until_complete(test_aggregate()) loop.run_until_complete(test_aggregate())