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

A couple more CleanTitle fixes

This commit is contained in:
Mark McDowall 2014-12-23 07:38:49 -08:00
parent 7ec34de3b7
commit 5f8af9f3a2
2 changed files with 25 additions and 6 deletions

View File

@ -60,7 +60,7 @@ public void Setup()
[TestCase("Tamara Ecclestone: Billion $$ Girl", "Tamara Ecclestone Billion $$ Girl")]
[TestCase("Marvel's Agents of S.H.I.E.L.D.", "Marvels Agents of S.H.I.E.L.D")]
[TestCase("Castle (2009)", "Castle 2009")]
// [TestCase("", "")]
[TestCase("Law & Order (UK)", "Law and Order UK")]
// [TestCase("", "")]
public void should_get_expected_title_back(string title, string expected)
{
@ -70,5 +70,22 @@ public void should_get_expected_title_back(string title, string expected)
Subject.BuildFileName(new List<Episode> { _episode }, _series, _episodeFile)
.Should().Be(expected);
}
[Test]
public void should_use_and_as_separator_for_multiple_episodes()
{
var episodes = Builder<Episode>.CreateListOfSize(2)
.TheFirst(1)
.With(e => e.Title = "Surrender Benson")
.TheNext(1)
.With(e => e.Title = "Imprisoned Lives")
.Build()
.ToList();
_namingConfig.StandardEpisodeFormat = "{Episode CleanTitle}";
Subject.BuildFileName(episodes, _series, _episodeFile)
.Should().Be(episodes.First().Title + " and " + episodes.Last().Title);
}
}
}

View File

@ -56,7 +56,6 @@ 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(@"(?<!$1)[^\w+#\/. ](?!$1)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex ScenifyRemoveChars = new Regex(@"(?<=\s)(,|<|>|\/|\\|;|:|'|""|\||`|~|!|@|$|%|^|&|\*|-|_|=){1}(?=\s)|('|:)(?=s|\s)|(\(|\)|\[|\]|\{|\})", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex ScenifyReplaceChars = new Regex(@"[\/]", RegexOptions.Compiled | RegexOptions.IgnoreCase);
@ -238,6 +237,7 @@ public string GetSeasonFolder(Series series, Int32 seasonNumber, NamingConfig na
public static string CleanTitle(string title)
{
title = title.Replace("&", "and");
title = ScenifyReplaceChars.Replace(title, " ");
title = ScenifyRemoveChars.Replace(title, String.Empty);
@ -408,8 +408,8 @@ private void AddEpisodeTokens(Dictionary<String, Func<TokenMatch, String>> token
tokenHandlers["{Air Date}"] = m => "Unknown";
}
tokenHandlers["{Episode Title}"] = m => GetEpisodeTitle(episodes);
tokenHandlers["{Episode CleanTitle}"] = m => CleanTitle(GetEpisodeTitle(episodes));
tokenHandlers["{Episode Title}"] = m => GetEpisodeTitle(episodes, "+");
tokenHandlers["{Episode CleanTitle}"] = m => CleanTitle(GetEpisodeTitle(episodes, "and"));
}
private void AddEpisodeFileTokens(Dictionary<String, Func<TokenMatch, String>> tokenHandlers, Series series, EpisodeFile episodeFile)
@ -645,8 +645,10 @@ private AbsoluteEpisodeFormat[] GetAbsoluteFormat(string pattern)
}).ToArray());
}
private string GetEpisodeTitle(List<Episode> episodes)
private string GetEpisodeTitle(List<Episode> episodes, string separator)
{
separator = String.Format(" {0} ", separator.Trim());
if (episodes.Count == 1)
{
return episodes.First().Title.TrimEnd(EpisodeTitleTrimCharacters);
@ -657,7 +659,7 @@ private string GetEpisodeTitle(List<Episode> episodes)
.Select(Parser.Parser.CleanupEpisodeTitle)
.Distinct();
return String.Join(" + ", titles);
return String.Join(separator, titles);
}
private string GetQualityProper(Series series, QualityModel quality)