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
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:
@@ -0,0 +1,140 @@
|
||||
package library
|
||||
|
||||
import (
|
||||
"io"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/dhowden/tag"
|
||||
)
|
||||
|
||||
// artistCredit is who a track is filed under, and the credit shown beside it.
|
||||
//
|
||||
// A track's ARTIST tag is a credit, not always one artist: "Low Tide Choir
|
||||
// feat. Ruby Calloway" names a guest, and a collaboration names two artists
|
||||
// equally. Filed under the whole string, each such credit became an artist of
|
||||
// its own, with its own page, its own place in the artist list and its own
|
||||
// "Songs like" mix, holding one or two tracks. The track is filed under its
|
||||
// first artist instead, and the full credit is kept to show with it.
|
||||
type artistCredit struct {
|
||||
// Name is the artist the track is filed under.
|
||||
Name string
|
||||
// MBID is Name's MusicBrainz id, or "".
|
||||
MBID string
|
||||
// Credit is the full credit when it names more than Name, else "".
|
||||
Credit string
|
||||
}
|
||||
|
||||
// featuring finds where a guest credit starts: "X feat. Y", "X ft. Y",
|
||||
// "X featuring Y", "X (feat. Y)". Outside brackets the abbreviations need
|
||||
// their full stop, so a band called "Little Feat" is not cut short; inside
|
||||
// brackets the stop is optional.
|
||||
var featuring = regexp.MustCompile(`(?i)\s+(?:[(\[]\s*(?:feat\.?|ft\.?|featuring)|feat\.|ft\.|featuring)\s`)
|
||||
|
||||
// readArtistCredit works out a track's artist credit from its tags.
|
||||
//
|
||||
// - A file that lists its artists one by one (Picard's ARTISTS tag, two or
|
||||
// more values) is filed under the first. This is the only way a
|
||||
// collaboration is split: "A & B" may be two artists or one band
|
||||
// ("Simon & Garfunkel", "St. Paul & The Broken Bones"), and only the
|
||||
// list says which.
|
||||
// - Otherwise a featured guest is cut from the credit: "X feat. Y" is filed
|
||||
// under X.
|
||||
// - Otherwise the credit is the artist.
|
||||
//
|
||||
// The MusicBrainz id is the first of the file's artist ids, which Picard
|
||||
// writes in credit order, so it belongs to the first artist.
|
||||
func readArtistCredit(meta tag.Metadata, rs io.ReadSeeker, ids TagMBIDs) artistCredit {
|
||||
credit := strings.TrimSpace(meta.Artist())
|
||||
listed := readTagList(meta, rs, "ARTISTS", "ARTISTS")
|
||||
mbid := ids.Artist
|
||||
if isVorbis(meta) {
|
||||
// dhowden/tag keeps the last of a repeated Vorbis field, which on a
|
||||
// credit of two artists is the second artist's id.
|
||||
if all := readTagList(meta, rs, "MUSICBRAINZ_ARTISTID", ""); len(all) > 0 {
|
||||
mbid = cleanMBID(all[0])
|
||||
}
|
||||
}
|
||||
|
||||
name := credit
|
||||
switch {
|
||||
case len(listed) >= 2:
|
||||
name = listed[0]
|
||||
if credit == "" {
|
||||
credit = strings.Join(listed, ", ")
|
||||
}
|
||||
case credit != "":
|
||||
name = withoutGuests(credit)
|
||||
}
|
||||
if name == "" {
|
||||
return artistCredit{Name: "Unknown Artist"}
|
||||
}
|
||||
out := artistCredit{Name: name, MBID: mbid}
|
||||
if credit != name {
|
||||
out.Credit = credit
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// withoutGuests cuts a featured guest from a credit: "X feat. Y" gives X.
|
||||
// Album artists go through it too, as a single's release credit often names
|
||||
// its guest.
|
||||
func withoutGuests(credit string) string {
|
||||
if loc := featuring.FindStringIndex(credit); loc != nil && loc[0] > 0 {
|
||||
return strings.TrimSpace(credit[:loc[0]])
|
||||
}
|
||||
return credit
|
||||
}
|
||||
|
||||
func isVorbis(meta tag.Metadata) bool { return meta.Format() == tag.VORBIS }
|
||||
|
||||
// readTagList returns every value of a field that can repeat, in file order:
|
||||
// the Vorbis comment vorbisKey (FLAC, Ogg Vorbis, Opus), or the user-defined
|
||||
// text field called textName (ID3v2 TXXX, MP4 freeform). An empty textName
|
||||
// reads Vorbis only. A file that cannot be read for it gives nil.
|
||||
func readTagList(meta tag.Metadata, rs io.ReadSeeker, vorbisKey, textName string) []string {
|
||||
var values []string
|
||||
switch meta.Format() {
|
||||
case tag.VORBIS:
|
||||
if meta.FileType() == tag.OGG {
|
||||
values, _ = readOggValues(rs, vorbisKey)
|
||||
} else {
|
||||
values, _ = readFLACValues(rs, vorbisKey)
|
||||
}
|
||||
case tag.MP4:
|
||||
if textName != "" {
|
||||
values, _ = readMP4FreeformValues(rs, textName)
|
||||
}
|
||||
case tag.ID3v2_2, tag.ID3v2_3, tag.ID3v2_4:
|
||||
if textName != "" {
|
||||
values = id3TextList(meta, textName)
|
||||
}
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
// id3TextList reads the TXXX field called name. dhowden/tag files each TXXX
|
||||
// frame under "TXXX", "TXXX_0", … as a *tag.Comm. ID3v2.4 separates the
|
||||
// values of one frame with NUL. ID3v2.3 has no separator, and a "/" there
|
||||
// may be part of a name (AC/DC), so a v2.3 frame is one value.
|
||||
func id3TextList(meta tag.Metadata, name string) []string {
|
||||
var out []string
|
||||
for key, v := range meta.Raw() {
|
||||
if !strings.HasPrefix(key, "TXXX") {
|
||||
continue
|
||||
}
|
||||
c, ok := v.(*tag.Comm)
|
||||
if !ok || !strings.EqualFold(c.Description, name) {
|
||||
continue
|
||||
}
|
||||
for _, part := range strings.Split(c.Text, "\x00") {
|
||||
if p := strings.TrimSpace(part); p != "" {
|
||||
out = append(out, p)
|
||||
}
|
||||
}
|
||||
// One frame per field name: a tagger that wrote two would leave the
|
||||
// order between them to map iteration.
|
||||
break
|
||||
}
|
||||
return out
|
||||
}
|
||||
Reference in New Issue
Block a user