32 lines
974 B
Python
32 lines
974 B
Python
|
#!/usr/bin/env python3.12
|
||
|
# pylint: disable=wrong-import-order
|
||
|
|
||
|
from typing import Optional
|
||
|
from lyric_search_new.constructors import LyricsResult
|
||
|
import sys
|
||
|
sys.path.insert(1,'..')
|
||
|
sys.path.insert(1,'..')
|
||
|
from . import cache
|
||
|
from . import genius
|
||
|
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()
|
||
|
search = None
|
||
|
if "cache" not in self.exclude_methods:
|
||
|
# First, try cache
|
||
|
search = await cache_search.search(artist, song)
|
||
|
if not search:
|
||
|
print("Cache: NOT FOUND!")
|
||
|
# Then try Genius
|
||
|
search = await genius_search.search(artist, song)
|
||
|
|
||
|
return search
|