mirror of
https://github.com/Radarr/Radarr
synced 2025-02-22 14:21:14 +00:00
New: Deprecate use of movie file tokens in Movie Folder Format
This commit is contained in:
parent
6236bc9b4f
commit
9623377d39
4 changed files with 42 additions and 3 deletions
|
@ -248,6 +248,7 @@ function Naming() {
|
|||
translate('MovieFolderFormatHelpText'),
|
||||
...movieFolderFormatHelpTexts,
|
||||
]}
|
||||
helpTextWarning={translate('MovieFolderFormatHelpTextWarning')}
|
||||
errors={[
|
||||
...movieFolderFormatErrors,
|
||||
...settings.movieFolderFormat.errors,
|
||||
|
|
|
@ -1018,6 +1018,7 @@
|
|||
"MovieFilesTotaling": "Movie Files Totaling",
|
||||
"MovieFolderFormat": "Movie Folder Format",
|
||||
"MovieFolderFormatHelpText": "Used when adding a new movie or moving movies via the movie editor",
|
||||
"MovieFolderFormatHelpTextWarning": "Folder tokens associated with movie file properties have been deprecated and will no longer be supported in the next major version.",
|
||||
"MovieFolderImportedTooltip": "Movie imported from movie folder",
|
||||
"MovieFootNote": "Optionally control truncation to a maximum number of bytes including ellipsis (`...`). Truncating from the end (e.g. `{Movie Title:30}`) or the beginning (e.g. `{Movie Title:-30}`) are both supported.",
|
||||
"MovieGrabbedTooltip": "Movie grabbed from {indexer} and sent to {downloadClient}",
|
||||
|
|
|
@ -56,6 +56,9 @@ public class FileNameBuilder : IBuildFileNames
|
|||
|
||||
private static readonly Regex ReservedDeviceNamesRegex = new Regex(@"^(?:aux|com[1-9]|con|lpt[1-9]|nul|prn)\.", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
public static readonly Regex DeprecatedMovieFolderTokensRegex = new Regex(@"(\{(?:Original[- ._](?:Title|Filename)|Release[- ._]Group|Edition[- ._]Tags|Quality[- ._](?:Full|Title|Proper|Real)|MediaInfo[- ._](?:Video|VideoCodec|VideoBitDepth|Audio|AudioCodec|AudioChannels|AudioLanguages|AudioLanguagesAll|SubtitleLanguages|SubtitleLanguagesAll|3D|Simple|Full|VideoDynamicRange|VideoDynamicRangeType))\})",
|
||||
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
// generated from https://www.loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt
|
||||
public static readonly ImmutableDictionary<string, string> Iso639BTMap = new Dictionary<string, string>
|
||||
{
|
||||
|
@ -171,16 +174,25 @@ public string GetMovieFolder(Movie movie, NamingConfig namingConfig = null)
|
|||
namingConfig = _namingConfigService.GetConfig();
|
||||
}
|
||||
|
||||
var movieFile = movie.MovieFile;
|
||||
|
||||
var pattern = namingConfig.MovieFolderFormat;
|
||||
var tokenHandlers = new Dictionary<string, Func<TokenMatch, string>>(FileNameBuilderTokenEqualityComparer.Instance);
|
||||
|
||||
var deprecatedTokensMatch = DeprecatedMovieFolderTokensRegex.Matches(pattern);
|
||||
|
||||
if (deprecatedTokensMatch.Any())
|
||||
{
|
||||
_logger.Warn("DEPRECATED: The use of tokens associated with movie file properties ({0}) in Movie Folder Format is deprecated and will no longer be supported in the next major version. Please update your Movie Folder Format: '{1}'.", string.Join(", ", deprecatedTokensMatch.Select(c => c.Value).ToArray()), pattern);
|
||||
}
|
||||
|
||||
var multipleTokens = TitleRegex.Matches(pattern).Count > 1;
|
||||
|
||||
var tokenHandlers = new Dictionary<string, Func<TokenMatch, string>>(FileNameBuilderTokenEqualityComparer.Instance);
|
||||
|
||||
AddMovieTokens(tokenHandlers, movie);
|
||||
AddReleaseDateTokens(tokenHandlers, movie.Year);
|
||||
AddIdTokens(tokenHandlers, movie);
|
||||
|
||||
var movieFile = movie.MovieFile;
|
||||
|
||||
if (movie.MovieFile != null)
|
||||
{
|
||||
AddQualityTokens(tokenHandlers, movie, movieFile);
|
||||
|
|
|
@ -24,6 +24,7 @@ public static IRuleBuilderOptions<T, string> ValidMovieFolderFormat<T>(this IRul
|
|||
{
|
||||
ruleBuilder.SetValidator(new NotEmptyValidator(null));
|
||||
ruleBuilder.SetValidator(new IllegalCharactersValidator());
|
||||
ruleBuilder.SetValidator(new IllegalMovieFolderTokensValidator());
|
||||
|
||||
return ruleBuilder.SetValidator(new ValidMovieFolderFormatValidator());
|
||||
}
|
||||
|
@ -62,6 +63,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();
|
||||
|
|
Loading…
Reference in a new issue