fix(scanner): a featured guest or a listed collaborator is a credit on the track, not an artist of their own
release / web (push) Successful in 1m13s
release / go (push) Successful in 1m46s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 3m52s
release / android (push) Successful in 4m11s
release / Build signed APK (push) Successful in 4m42s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 29s
release / Verify release artifacts (tag releases only) (push) Skipped

A track tagged "Low Tide Choir feat. Ruby Calloway" was filed under an
artist of that whole name, with its own page, its own place in the artist
list and its own "Songs like" mix. It is now filed under Low Tide Choir and
keeps "Low Tide Choir feat. Ruby Calloway" as its credit, shown wherever the
track is listed, sent to Subsonic apps and scrobbled.

A collaboration is split only when the file lists its artists one by one
(Picard's ARTISTS tag, read from FLAC, Ogg, Opus, MP3 and M4A). "A & B" on
its own may be one band, so it stays whole. A Vorbis file's artist id is now
its first, not the guest's.

Tag-read version 10 re-reads the library once; the scan's tidy-up removes
the credit-named artists it leaves empty.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 12:08:55 -05:00
co-authored by Claude Opus 5.5
parent 2bc6c60938
commit 6351b4651a
22 changed files with 555 additions and 108 deletions
+156
View File
@@ -0,0 +1,156 @@
package library
import (
"bytes"
"testing"
"github.com/dhowden/tag"
)
func TestWithoutGuests(t *testing.T) {
tests := []struct{ credit, want string }{
{"Low Tide Choir feat. Ruby Calloway", "Low Tide Choir"},
{"Low Tide Choir ft. Ruby Calloway", "Low Tide Choir"},
{"Low Tide Choir featuring Ruby Calloway", "Low Tide Choir"},
{"Low Tide Choir (feat. Ruby Calloway)", "Low Tide Choir"},
{"Low Tide Choir [ft Ruby Calloway]", "Low Tide Choir"},
{"Low Tide Choir FEAT. Ruby Calloway & Mae", "Low Tide Choir"},
// Names that only look like a credit stay whole.
{"Little Feat", "Little Feat"},
{"Little Feat featuring Bonnie Raitt", "Little Feat"},
{"Daft Punk", "Daft Punk"},
{"Soft Cell", "Soft Cell"},
{"Featuring Fools", "Featuring Fools"},
{"Simon & Garfunkel", "Simon & Garfunkel"},
{"St. Paul & The Broken Bones", "St. Paul & The Broken Bones"},
}
for _, tc := range tests {
if got := withoutGuests(tc.credit); got != tc.want {
t.Errorf("withoutGuests(%q) = %q, want %q", tc.credit, got, tc.want)
}
}
}
// id3Meta is an ID3v2 file's tags as dhowden/tag presents them.
type id3Meta struct {
tag.Metadata
artist string
raw map[string]interface{}
}
func (m id3Meta) Format() tag.Format { return tag.ID3v2_4 }
func (m id3Meta) FileType() tag.FileType { return tag.MP3 }
func (m id3Meta) Artist() string { return m.artist }
func (m id3Meta) Raw() map[string]interface{} { return m.raw }
func TestReadArtistCredit_ID3(t *testing.T) {
tests := []struct {
name string
artist string
raw map[string]interface{}
mbid string
want artistCredit
}{
{
name: "a guest is cut from the credit",
artist: "Low Tide Choir feat. Ruby Calloway",
mbid: "id-choir",
want: artistCredit{Name: "Low Tide Choir", MBID: "id-choir", Credit: "Low Tide Choir feat. Ruby Calloway"},
},
{
name: "a collaboration the file lists is filed under its first artist",
artist: "Paper Lanterns & Ruby Calloway",
raw: map[string]interface{}{"TXXX": &tag.Comm{Description: "ARTISTS", Text: "Paper Lanterns\x00Ruby Calloway"}},
want: artistCredit{Name: "Paper Lanterns", Credit: "Paper Lanterns & Ruby Calloway"},
},
{
name: "an & the file does not list is one artist",
artist: "St. Paul & The Broken Bones",
raw: map[string]interface{}{"TXXX": &tag.Comm{Description: "ARTISTS", Text: "St. Paul & The Broken Bones"}},
want: artistCredit{Name: "St. Paul & The Broken Bones"},
},
{
name: "a v2.3 list has no separator, so a slash stays in the name",
artist: "AC/DC",
raw: map[string]interface{}{"TXXX_0": &tag.Comm{Description: "Artists", Text: "AC/DC"}},
want: artistCredit{Name: "AC/DC"},
},
{
name: "no artist at all",
want: artistCredit{Name: "Unknown Artist"},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
got := readArtistCredit(id3Meta{artist: tc.artist, raw: tc.raw}, nil, TagMBIDs{Artist: tc.mbid})
if got != tc.want {
t.Errorf("readArtistCredit = %+v, want %+v", got, tc.want)
}
})
}
}
// A FLAC credited to two artists, as Picard writes it: ARTIST is the credit,
// and ARTISTS and MUSICBRAINZ_ARTISTID list the artists in credit order.
// dhowden/tag keeps the last of each repeated field, so it alone would file
// the track under the second artist's id.
func TestReadArtistCredit_FLACListsItsArtists(t *testing.T) {
data := buildFLAC(false,
"TITLE=Undertow",
"ARTIST=Paper Lanterns & Ruby Calloway",
"ARTISTS=Paper Lanterns",
"ARTISTS=Ruby Calloway",
"MUSICBRAINZ_ARTISTID=id-lanterns",
"MUSICBRAINZ_ARTISTID=id-ruby",
)
rs := bytes.NewReader(data)
meta, err := tag.ReadFrom(rs)
if err != nil {
t.Fatalf("tag.ReadFrom: %v", err)
}
got := readArtistCredit(meta, rs, ReadTagMBIDs(meta))
want := artistCredit{Name: "Paper Lanterns", MBID: "id-lanterns", Credit: "Paper Lanterns & Ruby Calloway"}
if got != want {
t.Errorf("readArtistCredit = %+v, want %+v", got, want)
}
}
func TestReadArtistCredit_FLACWithOneArtist(t *testing.T) {
data := buildFLAC(false, "ARTIST=Marina & the Kats", "ARTISTS=Marina & the Kats", "MUSICBRAINZ_ARTISTID=id-kats")
rs := bytes.NewReader(data)
meta, err := tag.ReadFrom(rs)
if err != nil {
t.Fatalf("tag.ReadFrom: %v", err)
}
got := readArtistCredit(meta, rs, ReadTagMBIDs(meta))
if want := (artistCredit{Name: "Marina & the Kats", MBID: "id-kats"}); got != want {
t.Errorf("readArtistCredit = %+v, want %+v", got, want)
}
}
func TestReadMP4FreeformValues(t *testing.T) {
freeform := func(name string, values ...string) []byte {
children := [][]byte{
mp4Box("mean", []byte{0, 0, 0, 0}, []byte("com.apple.iTunes")),
mp4Box("name", []byte{0, 0, 0, 0}, []byte(name)),
}
for _, v := range values {
children = append(children, mp4Text(v))
}
return mp4Box("----", children...)
}
data := buildMP4(true,
freeform("MusicBrainz Artist Id", "id-lanterns"),
freeform("ARTISTS", "Paper Lanterns", "Ruby Calloway"),
)
got, err := readMP4FreeformValues(bytes.NewReader(data), "artists")
if err != nil {
t.Fatalf("readMP4FreeformValues: %v", err)
}
if want := []string{"Paper Lanterns", "Ruby Calloway"}; !equalStrings(got, want) {
t.Errorf("ARTISTS = %q, want %q", got, want)
}
if got, err := readMP4FreeformValues(bytes.NewReader(buildMP4(true)), "ARTISTS"); err != nil || got != nil {
t.Errorf("no ARTISTS item: got %q, %v; want nil, nil", got, err)
}
}