From e07492532725b2e5b512ed0ed4f741a9230ce1bd Mon Sep 17 00:00:00 2001 From: Silo Server Developer Date: Wed, 27 May 2026 18:36:58 +0200 Subject: [PATCH] fix(naming): strip unsubstituted Sonarr tokens ({TvdbId}/{imdb-}) from titles These tokens survived the provider-tag regex ([\w]+ doesn't match braces), polluting parsed titles (e.g. 'A Girl & Her Guard Dog [tvdb-{TvdbId}]') so they could not score-match. Broaden the regex to drop {...} and empty tokens. --- internal/naming/provider_token_test.go | 25 +++++++++++++++++++++++++ internal/naming/root_inference.go | 5 ++++- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 internal/naming/provider_token_test.go diff --git a/internal/naming/provider_token_test.go b/internal/naming/provider_token_test.go new file mode 100644 index 00000000..9dde9de8 --- /dev/null +++ b/internal/naming/provider_token_test.go @@ -0,0 +1,25 @@ +package naming + +import "testing" + +func TestStripInferProviderTags_HandlesBrokenSonarrTokens(t *testing.T) { + cases := []struct { + in string + want string + }{ + {"A Girl & Her Guard Dog [tvdb-{TvdbId}]", "A Girl & Her Guard Dog"}, + {"A Raven in the Harem [tvdb-{TvdbId}]", "A Raven in the Harem"}, + {"A Salad Bowl of Eccentrics {imdb-}", "A Salad Bowl of Eccentrics"}, + {"Coronation Street {imdb-}", "Coronation Street"}, + // well-formed tags must still be stripped: + {"Some Show [tvdb-81189]", "Some Show"}, + {"Some Show {tmdb-27205}", "Some Show"}, + // no tag: unchanged: + {"Cowboy Bebop", "Cowboy Bebop"}, + } + for _, c := range cases { + if got := stripInferProviderTags(c.in); got != c.want { + t.Errorf("stripInferProviderTags(%q) = %q, want %q", c.in, got, c.want) + } + } +} diff --git a/internal/naming/root_inference.go b/internal/naming/root_inference.go index e0095cdc..f383d725 100644 --- a/internal/naming/root_inference.go +++ b/internal/naming/root_inference.go @@ -18,7 +18,10 @@ var ( inferSeasonDirRe = regexp.MustCompile(`(?i)^Season\s+(\d{1,4})(?:\s.*)?$`) inferNumericSeasonRe = regexp.MustCompile(`^\d{1,4}$`) inferSpecialsDirRe = regexp.MustCompile(`(?i)^(?:specials?|extras?)$`) - inferProviderTagRe = regexp.MustCompile(`\s*[{\[](?:tmdb|tmdbid|imdb|imdbid|tvdb|tvdbid)-[\w]+[}\]]`) + // Matches a well-formed tag ([tvdb-81189]), an unsubstituted Sonarr token + // ([tvdb-{TvdbId}]), or an empty token ({imdb-}). The id part is either a + // {...} placeholder or zero-or-more word chars. + inferProviderTagRe = regexp.MustCompile(`\s*[{\[](?:tmdb|tmdbid|imdb|imdbid|tvdb|tvdbid)-(?:\{[^}]*\}|[\w]*)[}\]]`) ) type RootAssignment struct {