refactor: only import DB_PATH once
This commit is contained in:
+2
-2
@@ -12,7 +12,7 @@ import unicodedata
|
||||
from typing import Optional
|
||||
from loguru import logger
|
||||
|
||||
from .config import DB_PATH, DURATION_TOLERANCE_MS
|
||||
from .config import DURATION_TOLERANCE_MS
|
||||
from .models import TrackMeta, LyricResult, CacheStatus
|
||||
|
||||
# Punctuation to strip for fuzzy matching (ASCII + fullwidth + CJK brackets/symbols)
|
||||
@@ -88,7 +88,7 @@ def _generate_key(track: TrackMeta, source: str) -> str:
|
||||
|
||||
|
||||
class CacheEngine:
|
||||
def __init__(self, db_path: str = DB_PATH):
|
||||
def __init__(self, db_path: str):
|
||||
self.db_path = db_path
|
||||
self._init_db()
|
||||
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ def launcher(
|
||||
if debug:
|
||||
enable_debug()
|
||||
_player = player
|
||||
_db_path = str(Path(db_path).resolve()) if db_path else None
|
||||
_db_path = str(Path(db_path).resolve()) if db_path else DB_PATH
|
||||
global manager
|
||||
manager = LrcManager(db_path=_db_path)
|
||||
app(tokens)
|
||||
|
||||
+3
-3
@@ -19,7 +19,7 @@ from .fetchers import FetcherMethodType, create_fetchers
|
||||
from .fetchers.base import BaseFetcher
|
||||
from .cache import CacheEngine
|
||||
from .lrc import normalize_tags, normalize_unsynced, detect_sync_status
|
||||
from .config import DB_PATH, TTL_SYNCED, TTL_UNSYNCED, TTL_NOT_FOUND, TTL_NETWORK_ERROR
|
||||
from .config import TTL_SYNCED, TTL_UNSYNCED, TTL_NOT_FOUND, TTL_NETWORK_ERROR
|
||||
from .models import TrackMeta, LyricResult, CacheStatus
|
||||
from .enrichers import enrich_track
|
||||
|
||||
@@ -36,8 +36,8 @@ _STATUS_TTL: dict[CacheStatus, Optional[int]] = {
|
||||
class LrcManager:
|
||||
"""Main entry point for fetching lyrics with caching."""
|
||||
|
||||
def __init__(self, db_path: Optional[str] = None) -> None:
|
||||
self.cache = CacheEngine(db_path=db_path if db_path else DB_PATH)
|
||||
def __init__(self, db_path: str) -> None:
|
||||
self.cache = CacheEngine(db_path=db_path)
|
||||
self.fetchers = create_fetchers(self.cache)
|
||||
|
||||
def _build_sequence(
|
||||
|
||||
Reference in New Issue
Block a user