42 lines
1.3 KiB
Python
Raw Normal View History

2025-01-13 20:47:39 -05:00
#!/usr/bin/env python3.12
# pylint: disable=wrong-import-order
from typing import Optional
from lyric_search_new.constructors import LyricsResult
import sys
2025-01-14 10:52:53 -05:00
import logging
2025-01-13 20:47:39 -05:00
sys.path.insert(1,'..')
from . import cache
from . import genius
from . import lrclib
2025-01-14 07:45:34 -05:00
2025-01-14 10:52:53 -05:00
logger = logging.getLogger()
logger.setLevel(logging.INFO)
2025-01-13 20:47:39 -05:00
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()
2025-01-14 10:52:53 -05:00
sources = [cache_search,
lrclib_search,
genius_search]
search_result = None
for source in sources:
if source.label.lower() in self.exclude_methods:
2025-01-14 10:57:25 -05:00
logging.info("Skipping source: %s, excluded.", source.label)
2025-01-14 10:52:53 -05:00
continue
search_result = await source.search(artist, song)
if search_result:
return search_result
2025-01-14 10:57:25 -05:00
logging.info("%s: NOT FOUND!", source.label)
2025-01-13 20:47:39 -05:00
2025-01-14 10:52:53 -05:00
return search_result