2025-01-13 20:47:39 -05:00
|
|
|
#!/usr/bin/env python3.12
|
2025-01-14 11:10:13 -05:00
|
|
|
# pylint: disable=wrong-import-order, wrong-import-position
|
2025-01-13 20:47:39 -05:00
|
|
|
|
|
|
|
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
|
2025-01-14 10:04:05 -05:00
|
|
|
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:
|
2025-01-14 14:17:18 -05:00
|
|
|
exclude_methods: list = []
|
2025-01-13 20:47:39 -05:00
|
|
|
self.exclude_methods = exclude_methods
|
|
|
|
|
2025-01-16 07:14:36 -05:00
|
|
|
async def search(self, artist: str, song: str, plain: bool = True) -> Optional[LyricsResult]:
|
2025-01-14 11:10:13 -05:00
|
|
|
"""Aggregate Search"""
|
2025-01-16 07:14:36 -05:00
|
|
|
if not plain:
|
|
|
|
logging.info("LRCs requested, limiting search to LRCLib")
|
|
|
|
self.exclude_methods = ["genius", "cache"]
|
2025-01-14 11:13:39 -05:00
|
|
|
logging.info("Performing aggregate search")
|
2025-01-13 20:47:39 -05:00
|
|
|
cache_search = cache.Cache()
|
|
|
|
genius_search = genius.Genius()
|
2025-01-14 10:04:05 -05:00
|
|
|
lrclib_search = lrclib.LRCLib()
|
2025-01-14 14:17:18 -05:00
|
|
|
sources: list = [cache_search,
|
2025-01-14 10:52:53 -05:00
|
|
|
lrclib_search,
|
|
|
|
genius_search]
|
2025-01-14 14:17:18 -05:00
|
|
|
search_result: Optional[LyricsResult] = None
|
2025-01-14 10:52:53 -05:00
|
|
|
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
|
2025-01-16 07:14:36 -05:00
|
|
|
search_result = await source.search(artist=artist, song=song,
|
|
|
|
plain=plain)
|
2025-01-14 10:52:53 -05:00
|
|
|
if search_result:
|
2025-01-15 20:17:49 -05:00
|
|
|
break
|
2025-01-14 10:57:25 -05:00
|
|
|
logging.info("%s: NOT FOUND!", source.label)
|
2025-01-14 10:52:53 -05:00
|
|
|
return search_result
|