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>
This commit is contained in:
+19
-55
@@ -1,59 +1,23 @@
|
||||
package library
|
||||
|
||||
// MusicBrainz tag keys vary by audio format. dhowden/tag's Raw() map exposes
|
||||
// the format-specific entries as-is — so we look up multiple candidates and
|
||||
// take the first non-empty match.
|
||||
import (
|
||||
"github.com/dhowden/tag"
|
||||
"github.com/dhowden/tag/mbz"
|
||||
)
|
||||
|
||||
// extractMBIDs reads MusicBrainz album and artist IDs from a tag.Metadata.
|
||||
//
|
||||
// References:
|
||||
// - ID3v2 (MP3): TXXX frames keyed by description.
|
||||
// - Vorbis (FLAC/OGG): all-caps comment names.
|
||||
// - MP4 (M4A): iTunes freeform atoms ("----:com.apple.iTunes:...").
|
||||
|
||||
var albumMBIDKeys = []string{
|
||||
"TXXX:MusicBrainz Album Id",
|
||||
"MUSICBRAINZ_ALBUMID",
|
||||
"----:com.apple.iTunes:MusicBrainz Album Id",
|
||||
}
|
||||
|
||||
var artistMBIDKeys = []string{
|
||||
"TXXX:MusicBrainz Artist Id",
|
||||
"MUSICBRAINZ_ARTISTID",
|
||||
"----:com.apple.iTunes:MusicBrainz Artist Id",
|
||||
}
|
||||
|
||||
// extractMBIDs reads MusicBrainz album and artist IDs from a tag.Metadata
|
||||
// Raw() map. Returns ("", "") when the keys are absent. Multi-value keys
|
||||
// (some formats list multiple artist IDs for collaborations) take only the
|
||||
// first value — Minstrel uses the primary release artist for MBCAA lookup.
|
||||
func extractMBIDs(raw map[string]interface{}) (albumMBID, artistMBID string) {
|
||||
albumMBID = firstStringValue(raw, albumMBIDKeys)
|
||||
artistMBID = firstStringValue(raw, artistMBIDKeys)
|
||||
return
|
||||
}
|
||||
|
||||
func firstStringValue(raw map[string]interface{}, keys []string) string {
|
||||
for _, k := range keys {
|
||||
v, ok := raw[k]
|
||||
if !ok || v == nil {
|
||||
continue
|
||||
}
|
||||
switch x := v.(type) {
|
||||
case string:
|
||||
if x != "" {
|
||||
return x
|
||||
}
|
||||
case []string:
|
||||
if len(x) > 0 && x[0] != "" {
|
||||
return x[0]
|
||||
}
|
||||
case []interface{}:
|
||||
if len(x) == 0 {
|
||||
continue
|
||||
}
|
||||
if s, ok := x[0].(string); ok && s != "" {
|
||||
return s
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
// 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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user