feat: MusicBrainz-aware intake and completeness check against canonical track count

This commit is contained in:
Jonathan
2026-07-10 23:17:06 +02:00
parent cf5632aa5f
commit c16e9f1035
4 changed files with 96 additions and 2 deletions
+8 -2
View File
@@ -101,6 +101,7 @@ def run_pipeline(
conn: psycopg.Connection,
job_id: str,
adapters: Sequence[SourceAdapter],
resolver=None,
min_confidence: float = 0.7,
dest_root: str = "/music",
) -> None:
@@ -112,6 +113,10 @@ def run_pipeline(
# 1. intake
_set_state(conn, job_id, "matching", "intake")
target = _load_target(conn, job_id)
if resolver is not None:
resolved = resolver.resolve(target.artist, target.album)
if resolved is not None:
target = resolved
if _already_in_library(conn, target):
_set_state(conn, job_id, "imported", "import")
with conn.cursor() as cur:
@@ -161,9 +166,10 @@ def run_pipeline(
_fail(conn, job_id, "all downloads failed")
return
# 5. tag (integrity check; real tagging is Plan 4)
# 5. tag (integrity check against the canonical track count when known)
_set_state(conn, job_id, "tagging", "tag")
if result.track_count != winner.track_count:
expected = target.track_count if target.track_count is not None else winner.track_count
if result.track_count < expected:
_fail(conn, job_id, "incomplete download")
return
+9
View File
@@ -0,0 +1,9 @@
from typing import Protocol
from lyra_worker.types import MBTarget
class MbResolver(Protocol):
def resolve(self, artist: str, album: str) -> MBTarget | None:
"""Return a canonical MBTarget (with track_count) or None if no confident match."""
...
+1
View File
@@ -7,6 +7,7 @@ class MBTarget:
album: str
track_count: int | None = None
total_duration_s: int | None = None
year: int | None = None
@dataclass(frozen=True)