feat(scanner): add ArtistSplitExceptions to protect artist names from splitting (#5701)

* refactor(scanner): make tag value splitting position-based

Replaces the ZWSP substitution trick with index-based cutting, in
preparation for artist split exceptions, which need match positions.

* feat(scanner): protect whitelisted names in tag value splitting

Separator matches inside word-bounded exception matches no longer split.
Matching is case-insensitive and longest-first; boundaries are rune-aware.

* feat(scanner): add Scanner.ArtistSplitExceptions config option

* feat(scanner): honor artist split exceptions for participant tags

Applies Scanner.ArtistSplitExceptions to artist, albumartist and role tag
splitting. Generic tags (genre, mood, ...) are unaffected.

* fix(scanner): apply split exceptions when per-tag Split overrides participant tags

Per-tag Tags.<name>.Split makes the generic ingestion path split the tag
before participant mapping runs, bypassing the whitelist. Attach the
exceptions to participant tag mappings (including sort variants) in clean().

* feat(scanner): split performer names and honor split exceptions

Performer pair values were never split; multiple names in one PERFORMER
value stayed a single artist. Split them with the roles separators, using
the same whitelist protection as other participant tags.

* test(scanner): lock MBID ordering for split performer values

* refactor(scanner): consolidate split-exception wiring and drop hot-path lock

ArtistSplitExceptionsRx is called per tag mapping per scanned file across
concurrent goroutines; replace the mutex+joined-key cache with an atomic
pointer compared via slices.Equal. Route all participant call sites through
WithParticipantExceptions and a shared splitParticipantValues helper.

* refactor(scanner): unexport artistSplitExceptionsRx

All external callers go through WithParticipantExceptions, so the accessor
does not need to be part of the model package API.
This commit is contained in:
Deluan Quintão 2026-07-02 08:29:44 -04:00 • committed by GitHub
commit 4cbba2ae49
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 395 additions and 43 deletions

View file

@ -94,18 +94,20 @@ func (md Metadata) processPerformers(participants model.Participants, rolesMbzId
roleIdx[role] = 0
}
conf := model.TagRolesConf().WithParticipantExceptions(model.TagPerformer)
titleCaser := cases.Title(language.Und)
for _, performer := range md.Pairs(model.TagPerformer) {
name := performer.Value()
subRole := titleCaser.String(performer.Key())
artist := model.Artist{
ID: md.artistID(name),
Name: name,
OrderArtistName: str.SanitizeFieldForSortingNoArticle(name),
MbzArtistID: md.getPerformerMbid(subRole, rolesMbzIdMap, roleIdx),
names := splitParticipantValues(conf, []string{performer.Value()})
for _, name := range names {
artist := model.Artist{
ID: md.artistID(name),
Name: name,
OrderArtistName: str.SanitizeFieldForSortingNoArticle(name),
MbzArtistID: md.getPerformerMbid(subRole, rolesMbzIdMap, roleIdx),
}
participants.AddWithSubRole(model.RolePerformer, subRole, artist)
}
participants.AddWithSubRole(model.RolePerformer, subRole, artist)
}
}
@ -171,6 +173,16 @@ func (md Metadata) buildArtists(names, sorts, mbids []string) []model.Artist {
return artists
}
// splitParticipantValues splits values by the conf separators, dropping
// duplicated or empty entries. Values are returned unchanged when the conf
// has no separators.
func splitParticipantValues(conf model.TagConf, values []string) []string {
if len(conf.Split) == 0 {
return values
}
return filterDuplicatedOrEmptyValues(conf.SplitTagValue(values))
}
// getRoleValues returns the values of a role tag, splitting them if necessary
func (md Metadata) getRoleValues(role model.TagName) []string {
values := md.Strings(role)
@ -181,11 +193,8 @@ func (md Metadata) getRoleValues(role model.TagName) []string {
if conf.Split == nil {
conf = model.TagRolesConf()
}
if len(conf.Split) > 0 {
values = conf.SplitTagValue(values)
return filterDuplicatedOrEmptyValues(values)
}
return values
conf = conf.WithParticipantExceptions(role)
return splitParticipantValues(conf, values)
}
// getArtistValues returns the values of a single or multi artist tag, splitting them if necessary
@ -202,11 +211,8 @@ func (md Metadata) getArtistValues(single, multi model.TagName) []string {
if conf.Split == nil {
conf = model.TagArtistsConf()
}
if len(conf.Split) > 0 {
vSingle = conf.SplitTagValue(vSingle)
return filterDuplicatedOrEmptyValues(vSingle)
}
return vSingle
conf = conf.WithParticipantExceptions(single)
return splitParticipantValues(conf, vSingle)
}
func (md Metadata) mapDisplayName(singularTagName, pluralTagName model.TagName) string {

View file

@ -4,6 +4,8 @@ import (
"os"
"github.com/google/uuid"
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/conf/configtest"
"github.com/navidrome/navidrome/consts"
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/model/metadata"
@ -563,6 +565,37 @@ var _ = Describe("Participants", func() {
matchPerformer("Tim Carmon", "tim carmon", "Hammond Organ"),
))
})
It("should split multiple names in a single value", func() {
mf = toMediaFile(model.RawTags{
"PERFORMER:GUITAR": {"Eric Clapton/B.B. King"},
"PERFORMER:BASS": {"Nathan East"},
})
participants := mf.Participants
Expect(participants).To(HaveKeyWithValue(model.RolePerformer, HaveLen(3)))
p := participants[model.RolePerformer]
Expect(p).To(ContainElements(
matchPerformer("Eric Clapton", "eric clapton", "Guitar"),
matchPerformer("B.B. King", "b.b. king", "Guitar"),
matchPerformer("Nathan East", "nathan east", "Bass"),
))
})
It("should assign MBIDs in order to names split from a single value", func() {
mf = toMediaFile(model.RawTags{
"PERFORMER:GUITAR": {"Eric Clapton/B.B. King"},
"MUSICBRAINZ_PERFORMERID:GUITAR": {mbid1, mbid2},
})
p := mf.Participants[model.RolePerformer]
Expect(p).To(HaveLen(2))
Expect(p[0].Name).To(Equal("Eric Clapton"))
Expect(p[0].MbzArtistID).To(Equal(mbid1))
Expect(p[1].Name).To(Equal("B.B. King"))
Expect(p[1].MbzArtistID).To(Equal(mbid2))
})
})
When("MUSICBRAINZ_PERFORMERID tag is set", func() {
@ -802,4 +835,60 @@ var _ = Describe("Participants", func() {
}
})
})
Describe("Artist split exceptions", func() {
BeforeEach(func() {
DeferCleanup(configtest.SetupConfig())
})
It("does not split a whitelisted artist name on the default separators", func() {
// " feat. " is a default artists separator (mappings.yaml)
conf.Server.Scanner.ArtistSplitExceptions = []string{"Someone feat. Else"}
mf = toMediaFile(model.RawTags{
"ARTIST": {"Artist Name feat. Someone feat. Else"},
})
artists := mf.Participants[model.RoleArtist]
Expect(artists).To(HaveLen(2))
Expect(artists[0].Name).To(Equal("Artist Name"))
Expect(artists[1].Name).To(Equal("Someone feat. Else"))
})
It("does not split a whitelisted name in role tags", func() {
// "/" is a default roles separator (mappings.yaml)
conf.Server.Scanner.ArtistSplitExceptions = []string{"AC/DC"}
mf = toMediaFile(model.RawTags{
"COMPOSER": {"AC/DC/John Doe"},
})
composers := mf.Participants[model.RoleComposer]
Expect(composers).To(HaveLen(2))
Expect(composers[0].Name).To(Equal("AC/DC"))
Expect(composers[1].Name).To(Equal("John Doe"))
})
It("splits normally when the exception does not match", func() {
conf.Server.Scanner.ArtistSplitExceptions = []string{"Iron and Wine"}
mf = toMediaFile(model.RawTags{
"ARTIST": {"Artist Name feat. Someone Else"},
})
artists := mf.Participants[model.RoleArtist]
Expect(artists).To(HaveLen(2))
Expect(artists[0].Name).To(Equal("Artist Name"))
Expect(artists[1].Name).To(Equal("Someone Else"))
})
It("does not split a whitelisted name in performer tags", func() {
conf.Server.Scanner.ArtistSplitExceptions = []string{"AC/DC"}
mf = toMediaFile(model.RawTags{
"PERFORMER:GUITAR": {"AC/DC/Brian Johnson"},
})
performers := mf.Participants[model.RolePerformer]
Expect(performers).To(HaveLen(2))
Expect(performers[0].Name).To(Equal("AC/DC"))
Expect(performers[1].Name).To(Equal("Brian Johnson"))
})
})
})

View file

@ -205,6 +205,7 @@ func clean(filePath string, tags model.RawTags) model.Tags {
cleaned := make(model.Tags, len(mappings))
for name, mapping := range mappings {
mapping = mapping.WithParticipantExceptions(name)
var values []string
switch mapping.Type {
case model.TagTypePair: