Fixed: TitleThe Naming Token Handling (and tests)

This commit is contained in:
Qstick
2020-05-25 01:01:23 -04:00
parent 2a3d22038f
commit de2ebba363
2 changed files with 82 additions and 18 deletions

View File

@@ -64,6 +64,8 @@ namespace NzbDrone.Core.Organizer
private static readonly char[] EpisodeTitleTrimCharacters = new[] { ' ', '.', '?' };
private static readonly Regex TitlePrefixRegex = new Regex(@"^(The|An|A) (.*?)((?: *\([^)]+\))*)$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public FileNameBuilder(INamingConfigService namingConfigService,
IQualityDefinitionService qualityDefinitionService,
IUpdateMediaInfo mediaInfoUpdater,
@@ -167,24 +169,7 @@ namespace NzbDrone.Core.Organizer
public static string TitleThe(string title)
{
string[] prefixes = { "The ", "An ", "A " };
if (title.Length < 5)
{
return title;
}
foreach (string prefix in prefixes)
{
int prefix_length = prefix.Length;
if (prefix.ToLower() == title.Substring(0, prefix_length).ToLower())
{
title = title.Substring(prefix_length) + ", " + prefix.Trim();
break;
}
}
return title.Trim();
return TitlePrefixRegex.Replace(title, "$2, $1$3");
}
public static string CleanFileName(string name, bool replace = true, ColonReplacementFormat colonReplacement = ColonReplacementFormat.Delete)