This commit is contained in:
2025-01-23 13:02:03 -05:00
parent 2df8250ba2
commit e55485e7e8
11 changed files with 37 additions and 22 deletions

View File

@@ -3,12 +3,12 @@
from typing import Optional
from lyric_search_new.constructors import LyricsResult
from lyric_search_new import notifier
import sys
import logging
import traceback
sys.path.insert(1,'..')
from . import cache
from . import genius
from . import lrclib
from . import cache, redis_cache, genius, lrclib
logger = logging.getLogger()
logger.setLevel(logging.INFO)
@@ -22,6 +22,8 @@ class Aggregate:
if not exclude_methods:
exclude_methods: list = []
self.exclude_methods = exclude_methods
self.redis_cache = redis_cache.RedisCache()
self.notifier = notifier.DiscordNotifier()
async def search(self, artist: str, song: str, plain: bool = True) -> Optional[LyricsResult]:
"""
@@ -63,4 +65,15 @@ class Aggregate:
if search_result:
break
logging.info("%s: NOT FOUND!", source.label)
if not search_result:
logging.info("%s - %s: all sources exhausted, not found.",
artist, song)
try:
await self.redis_cache.increment_found_count("failed")
except Exception as e:
traceback.print_exc()
logging.info("Could not increment redis failed counter: %s",
str(e))
self.notifier.send(f"ERROR @ {__file__.rsplit("/", maxsplit=1)[-1]}",
f"Could not increment redis failed counter: {str(e)}")
return search_result

View File

@@ -53,7 +53,7 @@ class LRCLib:
input_track: str = f"{artist} - {song}"
returned_lyrics: str = ''
async with ClientSession() as client:
async with client.get(self.lrclib_url,
async with await client.get(self.lrclib_url,
params = {
'artist_name': artist,
'track_name': song,

View File

@@ -97,19 +97,18 @@ class RedisCache:
async def get_found_counts(self) -> dict:
"""
Get found counts for all sources
Get found counts for all sources (and failed count)
Args:
None
Returns:
dict: In the form {'source': count, 'source2': count, ...}
"""
try:
sources: list = ["cache", "lrclib", "genius"]
sources: list = ["cache", "lrclib", "genius", "failed"]
counts: dict = {}
for src in sources:
src_found_count = await self.redis_client.get(f"returned:{src}")
counts[src] = src_found_count
logging.info("Returning: %s", counts)
return counts
except Exception as e:
await self.notifier.send(f"ERROR @ {__file__.rsplit("/", maxsplit=1)[-1]}", f"{str(e)}")
@@ -204,11 +203,11 @@ class RedisCache:
jsonset = await self.redis_client.json().set(newkey, Path.root_path(),
redis_mapping)
if not jsonset:
raise RedisException(f"Failed to store {lyr_result.artist} - {lyr_result.song} (SQLite id: {sqlite_id}):\n{jsonset}")
raise RedisException(f"Failed to store {lyr_result.artist} - {lyr_result.song} (SQLite id: {sqlite_id}) to redis:\n{jsonset}")
logging.info("Stored %s - %s (related SQLite Row ID: %s) to %s",
lyr_result.artist, lyr_result.song, sqlite_id, newkey)
await self.notifier.send("INFO",
f"Stored {lyr_result.artist} - {lyr_result.song} (related SQLite Row ID: {sqlite_id}) to {newkey}")
f"Stored {lyr_result.artist} - {lyr_result.song} (related SQLite Row ID: {sqlite_id}) to redis: {newkey}")
except Exception as e:
await self.notifier.send(f"ERROR @ {__file__.rsplit("/", maxsplit=1)[-1]}",
f"Failed to store {lyr_result.artist} - {lyr_result.song}\