42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
#!/usr/bin/env python3.12
|
|
# pylint: disable=wrong-import-order
|
|
|
|
from typing import Optional
|
|
from lyric_search_new.constructors import LyricsResult
|
|
import sys
|
|
import logging
|
|
sys.path.insert(1,'..')
|
|
from . import cache
|
|
from . import genius
|
|
from . import lrclib
|
|
|
|
logger = logging.getLogger()
|
|
logger.setLevel(logging.INFO)
|
|
|
|
class Aggregate:
|
|
"""Aggregate all source methods"""
|
|
|
|
def __init__(self, exclude_methods=None):
|
|
if not exclude_methods:
|
|
exclude_methods = []
|
|
self.exclude_methods = exclude_methods
|
|
|
|
async def search(self, artist: str, song: str) -> Optional[LyricsResult]:
|
|
cache_search = cache.Cache()
|
|
genius_search = genius.Genius()
|
|
lrclib_search = lrclib.LRCLib()
|
|
sources = [cache_search,
|
|
lrclib_search,
|
|
genius_search]
|
|
search_result = None
|
|
for source in sources:
|
|
if source.label.lower() in self.exclude_methods:
|
|
logging.debug("Skipping source: %s, excluded.", source.label)
|
|
continue
|
|
search_result = await source.search(artist, song)
|
|
if search_result:
|
|
return search_result
|
|
logging.debug("%s: NOT FOUND!", str(source))
|
|
|
|
return search_result
|