Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand Down
26 changes: 26 additions & 0 deletions cmd/internal/wrtagflag/wrtagflag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{}
Expand All @@ -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)")

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions contrib/completions/wrtag.bash
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function _wrtag_completion() {
--notification-uri
--path-format
--research-link
--score-min
--tag-config
--version
)
Expand All @@ -55,6 +56,7 @@ function _wrtag_completion() {
-notification-uri
-path-format
-research-link
-score-min
-tag-config
-version
move
Expand Down
3 changes: 3 additions & 0 deletions contrib/completions/wrtag.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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 <tag>' 'drop <tag>'"
Expand Down
8 changes: 3 additions & 5 deletions wrtag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
Loading