From 9e00da4d2ab69634308a4c1c7b62b2adda597458 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sat, 30 Nov 2013 21:49:40 -0800 Subject: [PATCH] Don't strip episode count from title if only one episode --- .../OrganizerTests/GetNewFilenameFixture.cs | 12 ++++++++++ .../Organizer/FileNameBuilder.cs | 23 ++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) 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 @@ namespace NzbDrone.Core.Test.OrganizerTests 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 @@ namespace NzbDrone.Core.Organizer public class FileNameBuilder : IBuildFileNames { - private readonly IConfigService _configService; private readonly INamingConfigService _namingConfigService; private readonly ICached _patternCache; private readonly Logger _logger; @@ -41,12 +40,10 @@ namespace NzbDrone.Core.Organizer 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 @@ namespace NzbDrone.Core.Organizer 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 @@ namespace NzbDrone.Core.Organizer 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 @@ namespace NzbDrone.Core.Organizer 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