feat: able to set confidence for certain source via cli

This commit is contained in:
2026-04-02 19:28:20 +02:00
parent 1fc06bf2c7
commit 70f3118b8c
6 changed files with 91 additions and 15 deletions
+27 -1
View File
@@ -133,7 +133,7 @@ class CacheEngine:
elif status == CacheStatus.SUCCESS_UNSYNCED:
confidence = LEGACY_CONFIDENCE_UNSYNCED
else:
confidence = 100.0 # negative statuses: value irrelevant
confidence = 0.0 # negative statuses: no confidence
return LyricResult(
status=status,
@@ -399,6 +399,32 @@ class CacheEngine:
return matches
# Update
def update_confidence(
self,
track: TrackMeta,
confidence: float,
source: str,
) -> int:
"""Update confidence for a specific source's cache entry matching *track*.
Returns the number of rows updated.
"""
conditions, params = self._track_where(track)
if not conditions:
return 0
conditions.append("source = ?")
params.append(source)
where = " AND ".join(conditions)
with sqlite3.connect(self.db_path) as conn:
cur = conn.execute(
f"UPDATE cache SET confidence = ? WHERE {where}",
[confidence] + params,
)
conn.commit()
return cur.rowcount
# Query / inspect
def query_track(self, track: TrackMeta) -> list[dict]:
+24
View File
@@ -401,6 +401,30 @@ def stats():
print(f" {label:>{label_w}} : {count}")
@cache_app.command
def confidence(
source: Annotated[
str, cyclopts.Parameter(help="Source to update (e.g. spotify, netease).")
],
score: Annotated[float, cyclopts.Parameter(help="Confidence score (0-100).")],
):
"""Set confidence score for the current track's cache entry from a specific source."""
if not 0 <= score <= 100:
logger.error("Score must be between 0 and 100.")
sys.exit(1)
track = get_current_track(_player)
if not track:
logger.error("No active playing track found.")
sys.exit(1)
updated = manager.cache.update_confidence(track, score, source=source)
if updated:
print(f"Updated [{source}] confidence to {score:.0f}.")
else:
print(f"No cache entry found for [{source}].")
@cache_app.command
def insert(
*,