mirror of
https://github.com/navidrome/navidrome.git
synced 2026-05-03 06:51:16 +00:00
fix: split tag values from multiple sources individually
When a file has multiple tag frames mapping to the same logical tag (e.g. both TXXX:MOOD and TMOO), TagLib merges them into one key with multiple values. SplitTagValue had a len(values) != 1 guard that skipped splitting entirely in this case, leaving comma-separated values unsplit. Change SplitTagValue to split each value individually regardless of input count. Empty values are filtered during splitting. Fixes #5065
This commit is contained in:
parent
6b8fcc37c6
commit
ea4fe334e6
@ -34,23 +34,25 @@ type TagConf struct {
|
|||||||
SplitRx *regexp.Regexp `yaml:"-"`
|
SplitRx *regexp.Regexp `yaml:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SplitTagValue splits a tag value by the split separators, but only if it has a single value.
|
// SplitTagValue splits tag values by the configured split separators.
|
||||||
|
// Each value in the input slice is individually split and trimmed.
|
||||||
func (c TagConf) SplitTagValue(values []string) []string {
|
func (c TagConf) SplitTagValue(values []string) []string {
|
||||||
// If there's not exactly one value or no separators, return early.
|
if c.SplitRx == nil || len(values) == 0 {
|
||||||
if len(values) != 1 || c.SplitRx == nil {
|
|
||||||
return values
|
return values
|
||||||
}
|
}
|
||||||
tag := values[0]
|
|
||||||
|
|
||||||
// Replace all occurrences of any separator with the zero-width space.
|
var result []string
|
||||||
tag = c.SplitRx.ReplaceAllString(tag, consts.Zwsp)
|
for _, tag := range values {
|
||||||
|
// Replace all occurrences of any separator with the zero-width space.
|
||||||
|
tag = c.SplitRx.ReplaceAllString(tag, consts.Zwsp)
|
||||||
|
|
||||||
// Split by the zero-width space and trim each substring.
|
// Split by the zero-width space and trim each substring.
|
||||||
parts := strings.Split(tag, consts.Zwsp)
|
parts := strings.Split(tag, consts.Zwsp)
|
||||||
for i, part := range parts {
|
for _, part := range parts {
|
||||||
parts[i] = strings.TrimSpace(part)
|
result = append(result, strings.TrimSpace(part))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return parts
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
type TagType string
|
type TagType string
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user