radio_util: open tracks SQLite DB in readonly mode; black: reformat files

This commit is contained in:
2025-04-17 07:28:05 -04:00
parent 96add377df
commit 6c88c23a4d
25 changed files with 1913 additions and 1340 deletions

View File

@ -4,23 +4,26 @@ from lyric_search import notifier
import sys
import logging
import traceback
sys.path.insert(1,'..')
sys.path.insert(1, "..")
from . import cache, redis_cache, genius, lrclib
class Aggregate:
"""
Aggregate all source methods
"""
def __init__(self, exclude_methods=None) -> None:
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: Optional[bool] = True) -> Optional[LyricsResult]:
async def search(
self, artist: str, song: str, plain: Optional[bool] = True
) -> Optional[LyricsResult]:
"""
Aggregate Search
Args:
@ -41,37 +44,41 @@ class Aggregate:
cache_search,
lrclib_search,
genius_search,
]
]
if not plain:
sources = [lrclib_search] # Only LRCLib supported for synced lyrics
sources = [lrclib_search] # Only LRCLib supported for synced lyrics
search_result: Optional[LyricsResult] = None
for source in sources:
if source.label.lower() in self.exclude_methods:
if not plain:
logging.info("Exclude conditions rejected - source requested to exclude: %s, plain: %s",
source.label, plain)
logging.info(
"Exclude conditions rejected - source requested to exclude: %s, plain: %s",
source.label,
plain,
)
else:
if plain:
logging.info("Skipping source: %s, excluded.", source.label)
continue
search_result = await source.search(artist=artist, song=song,
plain=plain)
search_result = await source.search(artist=artist, song=song, plain=plain)
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)
if plain: # do not record LRC fails
try:
logging.info("%s - %s: all sources exhausted, not found.", artist, song)
if plain: # do not record LRC fails
try:
await self.redis_cache.increment_found_count("failed")
self.notifier.send("WARNING",
f"Could not find {artist} - {song} via queried sources.")
self.notifier.send(
"WARNING",
f"Could not find {artist} - {song} via queried sources.",
)
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
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