Check the audio's length, since the filename can agree and still be wrong

The file that got filed as Michael Jackson's "Chicago" had every textual signal
in its favour: the title matched exactly, and once approved it landed under the
right artist, album and track number. The only thing that disagreed was the
running time -- 359 seconds against Deezer's 245 -- because it was The Fall.

Duration is the one signal a stranger's filename cannot fake, and muse already
had it: Deezer supplies it at request time and it has been sitting unused in the
jobs table. On import the real length is read off the downloaded audio and
compared; a drift past MUSE_LENGTH_TOLERANCE multiplies confidence down and
explains itself in the review queue rather than leaving a bare number.

For this case that is 0.75 -> 0.26, which falls below REVIEW_CONFIDENCE and so
reads as "almost certainly wrong" instead of "worth a look". It runs on import
rather than in confidence() because the file does not exist when the candidate
is chosen.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Aryan SinghandClaude Opus 5 committed 2026-09-02 14:12:16 -05:00
1 parent 5b17d5fc8d
commit e9fba3bb1d
3 files changed
+96 -2

No files matched your search

+31
View File
@@ -8,6 +8,7 @@ the server filters -- can be exercised deterministically.
Run standalone: python tests/test_acquisition.py
"""
import asyncio, json, os, sys
from pathlib import Path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
os.environ.setdefault("MUSE_AUTH", "off")
@@ -311,6 +312,36 @@ def main() -> int:
print("\nsearch hygiene")
check("finished searches are cleaned up", len(flaky.deleted) >= 1)
print("\nlength cross-check")
# The signal a filename cannot fake. Every textual cue agreed on the file
# that got filed as Michael Jackson; only the running time disagreed.
class FakeInfo:
def __init__(self, n): self.length = n
class FakeAudio:
def __init__(self, n): self.info = FakeInfo(n)
real_file = mutagen_file = app.mutagen.File
try:
app.mutagen.File = lambda p: FakeAudio(359.0) # The Fall
got = app.length_check(Path("x.flac"), 245 * 1000) # Michael Jackson
check("a 47% length disagreement is caught", got is not None, got)
check("and it drops the file below the review floor",
got and round(0.75 * got[0], 3) < app.REVIEW_CONFIDENCE,
got and round(0.75 * got[0], 3))
check("the reason names both lengths",
got and "5:59" in got[1] and "4:05" in got[1], got and got[1])
app.mutagen.File = lambda p: FakeAudio(247.0)
check("a two-second drift is not flagged",
app.length_check(Path("x.flac"), 245 * 1000) is None)
app.mutagen.File = lambda p: FakeAudio(359.0)
check("nothing to compare against is not a failure",
app.length_check(Path("x.flac"), None) is None)
finally:
app.mutagen.File = mutagen_file
print("\nstall clock")
from datetime import datetime, timedelta, timezone
with app.db() as c: