From 2838ac36df72fefbe796e0fa88316ea6d7f106f9 Mon Sep 17 00:00:00 2001 From: Deluan Date: Thu, 13 Mar 2025 19:47:34 -0400 Subject: [PATCH] feat(scanner): allow disabling tags with `Tags..Ignore=true` Signed-off-by: Deluan --- conf/configuration.go | 1 + model/tag_mappings.go | 29 +++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/conf/configuration.go b/conf/configuration.go index b4e38add2..e1e6b2f67 100644 --- a/conf/configuration.go +++ b/conf/configuration.go @@ -140,6 +140,7 @@ type subsonicOptions struct { } type TagConf struct { + Ignore bool `yaml:"ignore"` Aliases []string `yaml:"aliases"` Type string `yaml:"type"` MaxLength int `yaml:"maxLength"` diff --git a/model/tag_mappings.go b/model/tag_mappings.go index 14edd3b0e..d8caa0c5d 100644 --- a/model/tag_mappings.go +++ b/model/tag_mappings.go @@ -1,6 +1,7 @@ package model import ( + "cmp" "maps" "regexp" "slices" @@ -186,19 +187,31 @@ func loadTagMappings() { // Overwrite the default mappings with the ones from the config for tag, cfg := range conf.Server.Tags { - if len(cfg.Aliases) == 0 { + if cfg.Ignore { delete(_mappings.Main, TagName(tag)) delete(_mappings.Additional, TagName(tag)) continue } - c := TagConf{ - Aliases: cfg.Aliases, - Type: TagType(cfg.Type), - MaxLength: cfg.MaxLength, - Split: cfg.Split, - Album: cfg.Album, - SplitRx: compileSplitRegex(TagName(tag), cfg.Split), + oldValue, ok := _mappings.Main[TagName(tag)] + if !ok { + oldValue = _mappings.Additional[TagName(tag)] } + aliases := cfg.Aliases + if len(aliases) == 0 { + aliases = oldValue.Aliases + } + split := cfg.Split + if len(split) == 0 { + split = oldValue.Split + } + c := TagConf{ + Aliases: aliases, + Split: split, + Type: cmp.Or(TagType(cfg.Type), oldValue.Type), + MaxLength: cmp.Or(cfg.MaxLength, oldValue.MaxLength), + Album: cmp.Or(cfg.Album, oldValue.Album), + } + c.SplitRx = compileSplitRegex(TagName(tag), c.Split) if _, ok := _mappings.Main[TagName(tag)]; ok { _mappings.Main[TagName(tag)] = c } else {