Added: Setting for Colon Replacement Format (#2711)

Fixes #2140
Fixes #2657
This commit is contained in:
Qstick
2018-04-16 18:22:54 -04:00
committed by Leonardo Galli
parent 38932d82db
commit 210902ecb6
30 changed files with 218 additions and 291 deletions

View File

@@ -248,8 +248,9 @@ namespace NzbDrone.Core.Organizer
{
AddMovieFileTokens(tokenHandlers, new MovieFile { SceneName = $"{movie.Title} {movie.Year}", RelativePath = $"{movie.Title} {movie.Year}"});
}
return CleanFolderName(ReplaceTokens(namingConfig.MovieFolderFormat, tokenHandlers, namingConfig));
string name = ReplaceTokens(namingConfig.MovieFolderFormat, tokenHandlers, namingConfig);
return CleanFolderName(name, namingConfig);
}
public static string CleanTitle(string title)
@@ -283,11 +284,14 @@ namespace NzbDrone.Core.Organizer
return title.Trim();
}
public static string CleanFileName(string name, bool replace = true)
public static string CleanFileName(string name, NamingConfig namingConfig)
{
bool replace = namingConfig.ReplaceIllegalCharacters;
var colonReplacementFormat = namingConfig.ColonReplacementFormat.GetFormatString();
string result = name;
string[] badCharacters = { "\\", "/", "<", ">", "?", "*", ":", "|", "\"" };
string[] goodCharacters = { "+", "+", "", "", "!", "-", "", "", "" };
string[] goodCharacters = { "+", "+", "", "", "!", "-", colonReplacementFormat, "", "" };
for (int i = 0; i < badCharacters.Length; i++)
{
@@ -297,12 +301,12 @@ namespace NzbDrone.Core.Organizer
return result.Trim();
}
public static string CleanFolderName(string name)
public static string CleanFolderName(string name, NamingConfig namingConfig)
{
name = FileNameCleanupRegex.Replace(name, match => match.Captures[0].Value[0].ToString());
name = name.Trim(' ', '.');
return CleanFileName(name);
return CleanFileName(name, namingConfig);
}
private void AddMovieTokens(Dictionary<string, Func<TokenMatch, string>> tokenHandlers, Movie movie)
@@ -557,7 +561,7 @@ namespace NzbDrone.Core.Organizer
replacementText = replacementText.Replace(" ", tokenMatch.Separator);
}
replacementText = CleanFileName(replacementText, namingConfig.ReplaceIllegalCharacters);
replacementText = CleanFileName(replacementText, namingConfig);
if (!replacementText.IsNullOrWhiteSpace())
{