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
+93 -40
View File
@@ -74,9 +74,92 @@ func findMP4Child(rs io.ReadSeeker, start, end int64, kind string) (mp4Atom, boo
// readMP4GenreValues returns every ©gen value, in file order. rs is seeked
// as needed, so it is safe to call after dhowden/tag has consumed the reader.
func readMP4GenreValues(rs io.ReadSeeker) ([]string, error) {
ilst, found, err := findMP4Ilst(rs)
if err != nil || !found {
return nil, err
}
var out []string
err = eachMP4Item(rs, ilst, func(kind string, body []byte) bool {
if kind != "\xa9gen" {
return true
}
values, ok := mp4DataValues(body)
out = append(out, values...)
return ok
})
return out, err
}
// readMP4FreeformValues returns the values of the freeform "----" item called
// name (com.apple.iTunes:ARTISTS is Picard's), in file order. Names compare
// case-insensitively, as taggers differ in case.
func readMP4FreeformValues(rs io.ReadSeeker, name string) ([]string, error) {
ilst, found, err := findMP4Ilst(rs)
if err != nil || !found {
return nil, err
}
var out []string
err = eachMP4Item(rs, ilst, func(kind string, body []byte) bool {
if kind != "----" || !strings.EqualFold(mp4FreeformName(body), name) {
return true
}
values, ok := mp4DataValues(body)
out = append(out, values...)
return ok
})
return out, err
}
// mp4FreeformName is the text of the "name" atom in a freeform item's body:
// size, "name", four bytes of version and flags, then the name.
func mp4FreeformName(b []byte) string {
for len(b) >= 8 {
size := binary.BigEndian.Uint32(b[0:4])
if size < 8 || uint64(size) > uint64(len(b)) {
return ""
}
if string(b[4:8]) == "name" && size >= 12 {
return string(b[12:size])
}
b = b[size:]
}
return ""
}
// eachMP4Item calls fn with the kind and body of each item in ilst, in file
// order, until fn returns false (a malformed body). Each body is capped at
// maxMP4GenreAtomSize.
func eachMP4Item(rs io.ReadSeeker, ilst mp4Atom, fn func(kind string, body []byte) bool) error {
for pos := ilst.body; pos+8 <= ilst.limit; {
a, err := readMP4Atom(rs, pos, ilst.limit)
if err != nil {
return errNoGenreFrame
}
pos = a.limit
n := a.limit - a.body
if n > maxMP4GenreAtomSize {
return errNoGenreFrame
}
if _, err := rs.Seek(a.body, io.SeekStart); err != nil {
return errNoGenreFrame
}
body := make([]byte, n)
if _, err := io.ReadFull(rs, body); err != nil {
return errNoGenreFrame
}
if !fn(a.kind, body) {
return errNoGenreFrame
}
}
return nil
}
// findMP4Ilst finds the iTunes item list, moov > udta > meta > ilst.
// found is false for a file with no iTunes metadata.
func findMP4Ilst(rs io.ReadSeeker) (ilst mp4Atom, found bool, err error) {
end, err := rs.Seek(0, io.SeekEnd)
if err != nil {
return nil, err
return mp4Atom{}, false, err
}
// moov may sit after mdat; walking headers and seeking past bodies finds
// it either way without reading the audio.
@@ -84,10 +167,10 @@ func readMP4GenreValues(rs io.ReadSeeker) ([]string, error) {
for _, kind := range []string{"moov", "udta", "meta"} {
next, found, err := findMP4Child(rs, cur.body, cur.limit, kind)
if err != nil {
return nil, errNoGenreFrame
return mp4Atom{}, false, errNoGenreFrame
}
if !found {
return nil, nil // no iTunes metadata at all
return mp4Atom{}, false, nil // no iTunes metadata at all
}
cur = next
}
@@ -95,54 +178,24 @@ func readMP4GenreValues(rs io.ReadSeeker) ([]string, error) {
// children in the ISO layout. QuickTime-style files omit them, so the
// first child (hdlr) starts straight away. Look before skipping.
if _, err := rs.Seek(cur.body, io.SeekStart); err != nil {
return nil, errNoGenreFrame
return mp4Atom{}, false, errNoGenreFrame
}
var peek [8]byte
if _, err := io.ReadFull(rs, peek[:]); err != nil {
return nil, errNoGenreFrame
return mp4Atom{}, false, errNoGenreFrame
}
if string(peek[4:8]) != "hdlr" {
cur.body += 4
}
ilst, found, err := findMP4Child(rs, cur.body, cur.limit, "ilst")
ilst, found, err = findMP4Child(rs, cur.body, cur.limit, "ilst")
if err != nil {
return nil, errNoGenreFrame
return mp4Atom{}, false, errNoGenreFrame
}
if !found {
return nil, nil
}
var out []string
for pos := ilst.body; pos+8 <= ilst.limit; {
a, err := readMP4Atom(rs, pos, ilst.limit)
if err != nil {
return nil, errNoGenreFrame
}
pos = a.limit
if a.kind != "\xa9gen" {
continue
}
n := a.limit - a.body
if n > maxMP4GenreAtomSize {
return nil, errNoGenreFrame
}
if _, err := rs.Seek(a.body, io.SeekStart); err != nil {
return nil, errNoGenreFrame
}
body := make([]byte, n)
if _, err := io.ReadFull(rs, body); err != nil {
return nil, errNoGenreFrame
}
values, ok := mp4DataValues(body)
if !ok {
return nil, errNoGenreFrame
}
out = append(out, values...)
}
return out, nil
return ilst, found, nil
}
// mp4DataValues reads the "data" atoms in a ©gen body. Each is: size, "data",
// mp4DataValues reads the "data" atoms in a ©gen or freeform item's body;
// a freeform item's "mean" and "name" atoms are skipped. Each is: size, "data",
// a 4-byte type indicator (1 = UTF-8 text), a 4-byte locale, then the value.
// Atoms of other types carry no text and are skipped.
func mp4DataValues(b []byte) ([]string, bool) {