Files
minstrel/internal/library/artistcredit_test.go
T
bvandeusenandClaude Opus 5.5 4e1807cbba
release / web (push) Failing after 1m16s
release / go (push) Successful in 1m48s
release / govulncheck (push) Successful in 20s
release / integration (push) Successful in 4m0s
release / android (push) Successful in 4m34s
release / Build signed APK (push) Successful in 5m9s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Skipped
release / Verify release artifacts (tag releases only) (push) Skipped
test: invented artists, albums and MusicBrainz ids in place of real ones
Test data and example comments named real artists, records and songs, and
carried real MusicBrainz ids. One mapping swaps them for invented ones
throughout (Fields of Ontario, Plastic Apes, Marlo Davies, ...), keeping
what each case tests: sort order, index letter, escaping, title keys,
artist-prefix stripping. A test username is no longer the operator's name.

The cover-art and Last.fm connection checks still query real releases;
they reach live services and need something that exists there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 13:21:34 -05:00

157 lines
5.3 KiB
Go

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.
{"Tiny Feat", "Tiny Feat"},
{"Tiny Feat featuring Bonnie Rains", "Tiny Feat"},
{"Deft Monks", "Deft Monks"},
{"Loft Cell", "Loft Cell"},
{"Featuring Fools", "Featuring Fools"},
{"Simone & Garfield", "Simone & Garfield"},
{"St. Mark & The Mended Bones", "St. Mark & The Mended 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. Mark & The Mended Bones",
raw: map[string]interface{}{"TXXX": &tag.Comm{Description: "ARTISTS", Text: "St. Mark & The Mended Bones"}},
want: artistCredit{Name: "St. Mark & The Mended Bones"},
},
{
name: "a v2.3 list has no separator, so a slash stays in the name",
artist: "AM/FM",
raw: map[string]interface{}{"TXXX_0": &tag.Comm{Description: "Artists", Text: "AM/FM"}},
want: artistCredit{Name: "AM/FM"},
},
{
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=Marisa & the Cats", "ARTISTS=Marisa & the Cats", "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: "Marisa & the Cats", 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)
}
}