From 91871dd31558f248eb54264e353b72c40186e699 Mon Sep 17 00:00:00 2001 From: Yamin Shihab Date: Thu, 13 Aug 2026 21:21:01 -0600 Subject: [PATCH] feat(wrtag): add score-min config option --- README.md | 1 + cmd/internal/wrtagflag/wrtagflag.go | 26 ++++++++++++++++++++++++++ contrib/completions/wrtag.bash | 2 ++ contrib/completions/wrtag.fish | 3 +++ wrtag.go | 8 +++----- 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c199502..603bd32 100644 --- a/README.md +++ b/README.md @@ -443,6 +443,7 @@ Global configuration is used by all tools. Any option can be provided with a CLI | -notification-uri | WRTAG_NOTIFICATION_URI | notification-uri | Add a shoutrrr notification URI for an event (see [Notifications](#notifications)) (stackable) | | -path-format | WRTAG_PATH_FORMAT | path-format | Path to root music directory including path format rules (see [Path format](#path-format)) | | -research-link | WRTAG_RESEARCH_LINK | research-link | Define a helper URL to help find information about an unmatched release (stackable) | +| -score-min | WRTAG_SCORE_MIN | score-min | The minimum score required for a MusicBrainz match to be considered valid (default 95.00%) | | -tag-config | WRTAG_TAG_CONFIG | tag-config | Specify tag keep and drop rules when writing new tag revisions (see [Tagging](#tagging)) (stackable) | | -version | WRTAG_VERSION | version | Print the version and exit | diff --git a/cmd/internal/wrtagflag/wrtagflag.go b/cmd/internal/wrtagflag/wrtagflag.go index fe76c88..42cfe5e 100644 --- a/cmd/internal/wrtagflag/wrtagflag.go +++ b/cmd/internal/wrtagflag/wrtagflag.go @@ -71,6 +71,7 @@ func Config() *wrtag.Config { var cfg wrtag.Config flag.Var(&pathFormatParser{&cfg.PathFormat}, "path-format", "Path to root music directory including path format rules (see [Path format](#path-format))") + flag.Var(&addonsParser{&cfg.Addons}, "addon", "Define an addon for extra metadata writing (see [Addons](#addons)) (stackable)") cfg.KeepFiles = map[string]struct{}{} @@ -79,6 +80,9 @@ func Config() *wrtag.Config { cfg.DiffWeights = wrtag.DiffWeights{} flag.Var(&diffWeightsParser{cfg.DiffWeights}, "diff-weight", "Adjust distance weighting for a tag (0 to ignore) (stackable)") + cfg.MinScore = 95 + flag.Var(&percentageParser{&cfg.MinScore}, "score-min", "The minimum score required for a MusicBrainz match to be considered valid") + cfg.TagConfig = wrtag.TagConfig{} flag.Var(&tagConfigParser{&cfg.TagConfig}, "tag-config", "Specify tag keep and drop rules when writing new tag revisions (see [Tagging](#tagging)) (stackable)") @@ -257,6 +261,28 @@ func (tw diffWeightsParser) String() string { return strings.Join(parts, ", ") } +type percentageParser struct{ *float64 } + +func (p percentageParser) Set(value string) error { + value = strings.TrimSpace(value) + before, found := strings.CutSuffix(value, "%") + if found { + n, err := strconv.ParseFloat(strings.TrimSpace(before), 64) + if err != nil || n < 0 || n > 100 { + return errors.New("must be a floating-point number between 0 and 100 (inclusive)") + } + *p.float64 = n + return nil + } + return errors.New("no valid percentage found") +} +func (p percentageParser) String() string { + if p.float64 == nil { + return "" + } + return fmt.Sprintf("%.2f%%", *p.float64) +} + type tagConfigParser struct{ *wrtag.TagConfig } func (tw tagConfigParser) Set(value string) error { diff --git a/contrib/completions/wrtag.bash b/contrib/completions/wrtag.bash index b03a711..ce3d078 100644 --- a/contrib/completions/wrtag.bash +++ b/contrib/completions/wrtag.bash @@ -32,6 +32,7 @@ function _wrtag_completion() { --notification-uri --path-format --research-link + --score-min --tag-config --version ) @@ -55,6 +56,7 @@ function _wrtag_completion() { -notification-uri -path-format -research-link + -score-min -tag-config -version move diff --git a/contrib/completions/wrtag.fish b/contrib/completions/wrtag.fish index 2c352e3..2e0b151 100644 --- a/contrib/completions/wrtag.fish +++ b/contrib/completions/wrtag.fish @@ -78,6 +78,9 @@ __complete_prefer_oldstyle -c wrtag -n "not __fish_seen_subcommand_from $command __complete_prefer_oldstyle -c wrtag -n "not __fish_seen_subcommand_from $commands" \ -o research-link -x -d "Define a helper URL to help find information about an unmatched release" +__complete_prefer_oldstyle -c wrtag -n "not __fish_seen_subcommand_from $commands" \ + -o score-min -x -d "The minimum score required for a MusicBrainz match to be considered valid (default 95.00%)" + __complete_prefer_oldstyle -c wrtag -n "not __fish_seen_subcommand_from $commands" \ -o tag-config -x -d "Specify tag keep and drop rules when writing new tag revisions" \ -a "'keep ' 'drop '" diff --git a/wrtag.go b/wrtag.go index ec352f4..2ba76be 100644 --- a/wrtag.go +++ b/wrtag.go @@ -50,9 +50,6 @@ func IsNonFatalError(err error) bool { return errors.Is(err, ErrScoreTooLow) || errors.Is(err, ErrTrackCountMismatch) } -// The minimum score required for a MusicBrainz match to be considered valid. -const minScore = 95 - const numTrackGenres = 6 const ( @@ -85,6 +82,7 @@ type Config struct { CoverArtArchiveClient musicbrainz.CAAClient PathFormat pathformat.Format DiffWeights DiffWeights + MinScore float64 TagConfig TagConfig KeepFiles map[string]struct{} Addons []addon.Addon @@ -181,9 +179,9 @@ func ProcessDir( var shouldImport bool switch cond { case HighScoreOrMBID: - shouldImport = score >= minScore || mbid != "" + shouldImport = score >= cfg.MinScore || mbid != "" case HighScore: - shouldImport = score >= minScore + shouldImport = score >= cfg.MinScore case Always: shouldImport = true }