From 4933a75d15f355b11e1c9a9e9383aead986c6e68 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 17 Apr 2019 22:25:41 -0700 Subject: [PATCH] Fixed: Don't include year 0 in series folder name Fixes #3057 --- .../FileNameBuilderTests/CleanTitleYearFixture.cs | 11 +++++++++++ .../FileNameBuilderTests/TitleTheYearFixture.cs | 11 +++++++++++ .../FileNameBuilderTests/TitleYearFixture.cs | 11 +++++++++++ src/NzbDrone.Core/Organizer/FileNameBuilder.cs | 6 ++++++ 4 files changed, 39 insertions(+) diff --git a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/CleanTitleYearFixture.cs b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/CleanTitleYearFixture.cs index 7a4bc5a2d..16ec3d650 100644 --- a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/CleanTitleYearFixture.cs +++ b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/CleanTitleYearFixture.cs @@ -58,5 +58,16 @@ public void should_get_expected_title_back(string title, int year, string expect Subject.BuildFileName(new List { _episode }, _series, _episodeFile) .Should().Be(expected); } + + [Test] + public void should_not_include_0_for_year() + { + _series.Title = "The Alienist"; + _series.Year = 0; + _namingConfig.StandardEpisodeFormat = "{Series CleanTitleYear}"; + + Subject.BuildFileName(new List { _episode }, _series, _episodeFile) + .Should().Be("The Alienist"); + } } } diff --git a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/TitleTheYearFixture.cs b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/TitleTheYearFixture.cs index d79401f1b..0e11f2f56 100644 --- a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/TitleTheYearFixture.cs +++ b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/TitleTheYearFixture.cs @@ -59,5 +59,16 @@ public void should_get_expected_title_back(string title, int year, string expect Subject.BuildFileName(new List { _episode }, _series, _episodeFile) .Should().Be(expected); } + + [Test] + public void should_not_include_0_for_year() + { + _series.Title = "The Alienist"; + _series.Year = 0; + _namingConfig.StandardEpisodeFormat = "{Series TitleTheYear}"; + + Subject.BuildFileName(new List { _episode }, _series, _episodeFile) + .Should().Be("Alienist, The"); + } } } diff --git a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/TitleYearFixture.cs b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/TitleYearFixture.cs index bb8c7fa7a..55530632a 100644 --- a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/TitleYearFixture.cs +++ b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/TitleYearFixture.cs @@ -58,5 +58,16 @@ public void should_get_expected_title_back(string title, int year, string expect Subject.BuildFileName(new List { _episode }, _series, _episodeFile) .Should().Be(expected); } + + [Test] + public void should_not_include_0_for_year() + { + _series.Title = "The Alienist"; + _series.Year = 0; + _namingConfig.StandardEpisodeFormat = "{Series TitleYear}"; + + Subject.BuildFileName(new List { _episode }, _series, _episodeFile) + .Should().Be("The Alienist"); + } } } diff --git a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs index e9235cfc6..b17a7f291 100644 --- a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs +++ b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs @@ -286,6 +286,12 @@ public static string TitleThe(string title) public static string TitleYear(string title, int year) { + // Don't use 0 for the year. + if (year == 0) + { + return title; + } + // Regex match incase the year in the title doesn't match the year, for whatever reason. if (YearRegex.IsMatch(title)) {