Files
minstrel/internal/library/mbids.go
T
bvandeusen 947f944fe9 fix(server/m7-382): MBID extraction never matched dhowden/tag's Raw() keys
The hand-rolled extractor in internal/library/mbids.go looked up keys that
dhowden/tag never produces, for every supported audio format:

  Vorbis (FLAC/OGG): dhowden lowercases keys at parse time (vorbis.go:59),
    we looked up MUSICBRAINZ_ALBUMID. Always missed.
  ID3v2 (MP3): dhowden stores TXXX frames under bare TXXX/TXXX_N keys
    with *tag.Comm values; the Picard tag name is on the value's
    Description field, not part of the key. We looked up
    TXXX:MusicBrainz Album Id. Always missed.
  MP4 (M4A): dhowden stores freeform iTunes atoms under their bare
    sub-name. We looked up ----:com.apple.iTunes:MusicBrainz Album Id.
    Always missed.

Net effect: every album in the m7-380 boot backfill reported
processed=N, healed=0, skipped=N. The m7-379 enricher gate then
short-circuited NULL on every album, so MBCAA was never queried.
Symptom: "all albums skipped" during cover enrichment.

The pre-existing unit tests passed because they hand-built Raw() maps
with the intended-but-incorrect keys, never round-tripping through
dhowden's parser.

Replace the hand-rolled extractor with dhowden's own mbz sub-package,
which knows the per-format Raw() conventions and uses lowercase
canonical keys (mbz.Album, mbz.Artist). Update both call sites to pass
the full tag.Metadata instead of just Raw(). Rewrite the test with a
stubMeta implementing tag.Metadata, asserting against the actual
per-format Raw() shape, plus a regression guard that pins "uppercase
Vorbis keys must not match" so the v0 bug can't sneak back.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 21:15:51 -04:00

24 lines
951 B
Go

package library
import (
"github.com/dhowden/tag"
"github.com/dhowden/tag/mbz"
)
// extractMBIDs reads MusicBrainz album and artist IDs from a tag.Metadata.
//
// Delegates to dhowden/tag/mbz, which knows the per-format Raw() conventions:
// - Vorbis (FLAC/OGG) keys are lowercased by the parser.
// - ID3v2 (MP3) TXXX frames are stored under "TXXX"/"TXXX_N" with
// a *tag.Comm value whose Description holds the Picard tag name.
// - MP4 (M4A) freeform iTunes atoms are stored under their bare sub-name.
//
// We previously hand-rolled this lookup against guessed keys
// ("MUSICBRAINZ_ALBUMID", "TXXX:MusicBrainz Album Id", ...), none of which
// dhowden actually produces — so every extraction returned ("",""), which
// fed an empty MBID into both the scanner and the boot-time backfill.
func extractMBIDs(m tag.Metadata) (albumMBID, artistMBID string) {
info := mbz.Extract(m)
return info.Get(mbz.Album), info.Get(mbz.Artist)
}