1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

New: Episode CleanTitle renaming token

This commit is contained in:
Mark McDowall 2014-12-20 23:30:53 -08:00
parent ac16c49ab8
commit 3cfbca5358
3 changed files with 45 additions and 12 deletions

View File

@ -874,5 +874,37 @@ public void should_use_Sonarr_as_release_group_when_not_available()
Subject.BuildFileName(new List<Episode> { _episode1 }, _series, _episodeFile)
.Should().Be("Sonarr");
}
[Test]
public void should_scenify_series_title_when_using_period_separator()
{
_series.Title = "Girlfriends' Guide to Divorce";
_namingConfig.StandardEpisodeFormat = "{Series.CleanTitle}";
Subject.BuildFileName(new List<Episode> { _episode1 }, _series, _episodeFile)
.Should().Be("Girlfriends.Guide.to.Divorce");
}
[Test]
public void should_scenify_episode_title_when_using_period_separator()
{
_episode1.Title = "Rule #23: Never Lie to the Kids";
_namingConfig.StandardEpisodeFormat = "{Episode.CleanTitle}";
Subject.BuildFileName(new List<Episode> { _episode1 }, _series, _episodeFile)
.Should().Be("Rule.23.Never.Lie.to.the.Kids");
}
[Test]
public void should_replace_forward_slash_sign_when_scenifying_episode_title()
{
_episode1.Title = "Anne Hathaway/Florence + The Machine";
_namingConfig.StandardEpisodeFormat = "{Episode.CleanTitle}";
Subject.BuildFileName(new List<Episode> { _episode1 }, _series, _episodeFile)
.Should().Be("Anne.Hathaway.Florence.The.Machine");
}
}
}
}

View File

@ -56,6 +56,9 @@ public class FileNameBuilder : IBuildFileNames
private static readonly Regex FileNameCleanupRegex = new Regex(@"([- ._])(\1)+", RegexOptions.Compiled);
private static readonly Regex TrimSeparatorsRegex = new Regex(@"[- ._]$", RegexOptions.Compiled);
private static readonly Regex ScenifyRemoveChars = new Regex(@"[^a-z0-9+\/ ]", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex ScenifyReplaceChars = new Regex(@"[+\/]", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly char[] EpisodeTitleTrimCharacters = new[] { ' ', '.', '?' };
public FileNameBuilder(INamingConfigService namingConfigService,
@ -232,18 +235,12 @@ public string GetSeasonFolder(Series series, Int32 seasonNumber, NamingConfig na
return CleanFolderName(ReplaceTokens(namingConfig.SeasonFolderFormat, tokenHandlers));
}
public static string CleanTitle(string name)
public static string CleanTitle(string title)
{
string[] dropCharacters = { ":", ".", "(", ")" };
title = ScenifyReplaceChars.Replace(title, " ");
title = ScenifyRemoveChars.Replace(title, String.Empty);
string result = name;
for (int i = 0; i < dropCharacters.Length; i++)
{
result = result.Replace(dropCharacters[i], "");
}
return result;
return title;
}
public static string CleanFileName(string name)
@ -411,6 +408,7 @@ private void AddEpisodeTokens(Dictionary<String, Func<TokenMatch, String>> token
}
tokenHandlers["{Episode Title}"] = m => GetEpisodeTitle(episodes);
tokenHandlers["{Episode CleanTitle}"] = m => CleanTitle(GetEpisodeTitle(episodes));
}
private void AddEpisodeFileTokens(Dictionary<String, Func<TokenMatch, String>> tokenHandlers, Series series, EpisodeFile episodeFile)
@ -715,4 +713,4 @@ public enum MultiEpisodeStyle
Scene = 3,
Range = 4
}
}
}

View File

@ -4,5 +4,8 @@
<li><a href="#" data-token="Episode Title">Episode Title</a></li>
<li><a href="#" data-token="Episode.Title">Episode.Title</a></li>
<li><a href="#" data-token="Episode_Title">Episode_Title</a></li>
<li><a href="#" data-token="Episode Title">Episode CleanTitle</a></li>
<li><a href="#" data-token="Episode.Title">Episode.CleanTitle</a></li>
<li><a href="#" data-token="Episode_Title">Episode_CleanTitle</a></li>
</ul>
</li>