diff --git a/src/NzbDrone.Core/Organizer/FileNameValidation.cs b/src/NzbDrone.Core/Organizer/FileNameValidation.cs index c7c9c6cb8..8e97ebffa 100644 --- a/src/NzbDrone.Core/Organizer/FileNameValidation.cs +++ b/src/NzbDrone.Core/Organizer/FileNameValidation.cs @@ -23,6 +23,7 @@ public static IRuleBuilderOptions ValidMovieFolderFormat(this IRul { ruleBuilder.SetValidator(new NotEmptyValidator(null)); ruleBuilder.SetValidator(new IllegalCharactersValidator()); + ruleBuilder.SetValidator(new IllegalMovieFolderTokensValidator()); return ruleBuilder.SetValidator(new RegularExpressionValidator(FileNameBuilder.MovieTitleRegex)).WithMessage("Must contain movie title"); } @@ -44,6 +45,30 @@ protected override bool IsValid(PropertyValidatorContext context) } } + public class IllegalMovieFolderTokensValidator : PropertyValidator + { + protected override string GetDefaultMessageTemplate() => "Must not contain deprecated tokens derived from file properties: {tokens}"; + + protected override bool IsValid(PropertyValidatorContext context) + { + if (context.PropertyValue is not string value) + { + return false; + } + + var match = FileNameBuilder.DeprecatedMovieFolderTokensRegex.Matches(value); + + if (match.Any()) + { + context.MessageFormatter.AppendArgument("tokens", string.Join(", ", match.Select(c => c.Value).ToArray())); + + return false; + } + + return true; + } + } + public class IllegalCharactersValidator : PropertyValidator { private static readonly char[] InvalidPathChars = Path.GetInvalidPathChars();