diff --git a/src/NzbDrone.Core.Test/OrganizerTests/GetNewFilenameFixture.cs b/src/NzbDrone.Core.Test/OrganizerTests/GetNewFilenameFixture.cs index 338e3059c..45043235a 100644 --- a/src/NzbDrone.Core.Test/OrganizerTests/GetNewFilenameFixture.cs +++ b/src/NzbDrone.Core.Test/OrganizerTests/GetNewFilenameFixture.cs @@ -371,5 +371,22 @@ namespace NzbDrone.Core.Test.OrganizerTests Subject.BuildFilename(new List { _episode1 }, _series, _episodeFile) .Should().Be("30 Rock - 30.Rock.S01E01.xvid-LOL"); } + + [Test] + public void should_trim_periods_from_end_of_episode_title() + { + _namingConfig.StandardEpisodeFormat = "{Series Title} - S{season:00}E{episode:00} - {Episode Title}"; + _namingConfig.MultiEpisodeStyle = 3; + + var episode = Builder.CreateNew() + .With(e => e.Title = "Part 1.") + .With(e => e.SeasonNumber = 6) + .With(e => e.EpisodeNumber = 6) + .Build(); + + + Subject.BuildFilename(new List { episode }, new Series { Title = "30 Rock" }, _episodeFile) + .Should().Be("30 Rock - S06E06 - Part 1"); + } } } \ No newline at end of file diff --git a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs index 2997be7d5..c158cb514 100644 --- a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs +++ b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs @@ -44,6 +44,8 @@ namespace NzbDrone.Core.Organizer public static readonly Regex SeriesTitleRegex = new Regex(@"(?\{(?:Series)(?\s|\.|-|_)Title\})", RegexOptions.Compiled | RegexOptions.IgnoreCase); + private static readonly char[] EpisodeTitleTrimCharaters = new[] { ' ', '.' }; + public FileNameBuilder(INamingConfigService namingConfigService, IQualityDefinitionService qualityDefinitionService, ICacheManger cacheManger, @@ -88,7 +90,7 @@ namespace NzbDrone.Core.Organizer var pattern = namingConfig.StandardEpisodeFormat; var episodeTitles = new List { - sortedEpisodes.First().Title + sortedEpisodes.First().Title.TrimEnd(EpisodeTitleTrimCharaters) }; var tokenValues = new Dictionary(FilenameBuilderTokenEqualityComparer.Instance); @@ -140,7 +142,7 @@ namespace NzbDrone.Core.Organizer break; } - episodeTitles.Add(episode.Title); + episodeTitles.Add(episode.Title.TrimEnd(EpisodeTitleTrimCharaters)); } seasonEpisodePattern = ReplaceNumberTokens(seasonEpisodePattern, sortedEpisodes);