diff --git a/src/NzbDrone.Core.Test/OrganizerTests/GetNewFilenameFixture.cs b/src/NzbDrone.Core.Test/OrganizerTests/GetNewFilenameFixture.cs index 373a4aa3c..cfad01e1d 100644 --- a/src/NzbDrone.Core.Test/OrganizerTests/GetNewFilenameFixture.cs +++ b/src/NzbDrone.Core.Test/OrganizerTests/GetNewFilenameFixture.cs @@ -332,5 +332,17 @@ public void should_format_scene_multi_episode_properly() Subject.BuildFilename(new List { _episode1, _episode2 }, _series, _episodeFile) .Should().Be("South Park - S15E06-E07 - City Sushi"); } + + [Test] + public void should_not_clean_episode_title_if_there_is_only_one() + { + var title = "City Sushi (1)"; + _episode1.Title = title; + + _namingConfig.StandardEpisodeFormat = "{Episode Title}"; + + Subject.BuildFilename(new List { _episode1 }, _series, _episodeFile) + .Should().Be(title); + } } } \ No newline at end of file diff --git a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs index 776f138df..9032a2196 100644 --- a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs +++ b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs @@ -21,7 +21,6 @@ public interface IBuildFileNames public class FileNameBuilder : IBuildFileNames { - private readonly IConfigService _configService; private readonly INamingConfigService _namingConfigService; private readonly ICached _patternCache; private readonly Logger _logger; @@ -41,12 +40,10 @@ public class FileNameBuilder : IBuildFileNames public static readonly Regex AirDateRegex = new Regex(@"\{Air(\s|\W|_)Date\}", RegexOptions.Compiled | RegexOptions.IgnoreCase); public FileNameBuilder(INamingConfigService namingConfigService, - IConfigService configService, ICacheManger cacheManger, Logger logger) { _namingConfigService = namingConfigService; - _configService = configService; _patternCache = cacheManger.GetCache(GetType()); _logger = logger; } @@ -84,7 +81,7 @@ public string BuildFilename(IList episodes, Series series, EpisodeFile var pattern = namingConfig.StandardEpisodeFormat; var episodeTitles = new List { - Parser.Parser.CleanupEpisodeTitle(sortedEpisodes.First().Title) + sortedEpisodes.First().Title }; var tokenValues = new Dictionary(FilenameBuilderTokenEqualityComparer.Instance) @@ -135,14 +132,14 @@ public string BuildFilename(IList episodes, Series series, EpisodeFile break; } - episodeTitles.Add(Parser.Parser.CleanupEpisodeTitle(episode.Title)); + episodeTitles.Add(episode.Title); } seasonEpisodePattern = ReplaceNumberTokens(seasonEpisodePattern, sortedEpisodes); tokenValues.Add("{Season Episode}", seasonEpisodePattern); - } - - tokenValues.Add("{Episode Title}", String.Join(" + ", episodeTitles.Distinct())); + } + + tokenValues.Add("{Episode Title}", GetEpisodeTitle(episodeTitles)); tokenValues.Add("{Quality Title}", episodeFile.Quality.ToString()); @@ -314,6 +311,16 @@ private EpisodeFormat GetEpisodeFormat(string pattern) return null; }); } + + private string GetEpisodeTitle(List episodeTitles) + { + if (episodeTitles.Count == 1) + { + return episodeTitles.First(); + } + + return String.Join(" + ", episodeTitles.Select(Parser.Parser.CleanupEpisodeTitle).Distinct()); + } } public enum MultiEpisodeStyle