feat(server/m7-379): extract MusicBrainz IDs from audio tags during scan

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-04 19:01:55 -04:00
parent 412a1c00ac
commit ab8fff834a
3 changed files with 144 additions and 6 deletions
+69
View File
@@ -0,0 +1,69 @@
package library
import "testing"
func TestExtractMBIDs_ID3v2(t *testing.T) {
raw := map[string]interface{}{
"TXXX:MusicBrainz Album Id": "abc-123",
"TXXX:MusicBrainz Artist Id": "def-456",
}
a, ar := extractMBIDs(raw)
if a != "abc-123" || ar != "def-456" {
t.Errorf("got (%q, %q), want (\"abc-123\", \"def-456\")", a, ar)
}
}
func TestExtractMBIDs_Vorbis(t *testing.T) {
raw := map[string]interface{}{
"MUSICBRAINZ_ALBUMID": "abc",
"MUSICBRAINZ_ARTISTID": "def",
}
a, ar := extractMBIDs(raw)
if a != "abc" || ar != "def" {
t.Errorf("got (%q, %q)", a, ar)
}
}
func TestExtractMBIDs_MP4(t *testing.T) {
raw := map[string]interface{}{
"----:com.apple.iTunes:MusicBrainz Album Id": "abc",
"----:com.apple.iTunes:MusicBrainz Artist Id": "def",
}
a, ar := extractMBIDs(raw)
if a != "abc" || ar != "def" {
t.Errorf("got (%q, %q)", a, ar)
}
}
func TestExtractMBIDs_MissingKeysReturnEmpty(t *testing.T) {
a, ar := extractMBIDs(map[string]interface{}{})
if a != "" || ar != "" {
t.Errorf("got (%q, %q), want empty", a, ar)
}
}
func TestExtractMBIDs_MultiValueArtistTakesFirst(t *testing.T) {
// Some FLAC tags list collaborators as multi-value MUSICBRAINZ_ARTISTID.
// Minstrel uses the primary release artist; first wins.
raw := map[string]interface{}{
"MUSICBRAINZ_ARTISTID": []string{"primary-mbid", "collab-mbid"},
}
_, ar := extractMBIDs(raw)
if ar != "primary-mbid" {
t.Errorf("got %q, want %q", ar, "primary-mbid")
}
}
func TestExtractMBIDs_NilEntryIgnored(t *testing.T) {
raw := map[string]interface{}{
"TXXX:MusicBrainz Album Id": nil,
"TXXX:MusicBrainz Artist Id": "real-id",
}
a, ar := extractMBIDs(raw)
if a != "" {
t.Errorf("nil album entry should be ignored, got %q", a)
}
if ar != "real-id" {
t.Errorf("artist = %q", ar)
}
}