From f21358fce5eaae4b51d372e45db707da1b4533a6 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Wed, 6 Mar 2013 13:35:39 -0800 Subject: [PATCH] file name builder cleanup. --- .../OrganizerTests/GetNewFilenameFixture.cs | 402 +++++++++--------- .../CleanUpDropFolderFixture.cs | 6 +- .../MoveEpisodeFileFixture.cs | 12 +- .../ProviderTests/MisnamedProviderTest.cs | 20 +- NzbDrone.Core/Organizer/FileNameBuilder.cs | 60 ++- NzbDrone.Core/Providers/DiskScanProvider.cs | 6 +- NzbDrone.Core/Providers/MisnamedProvider.cs | 9 +- 7 files changed, 252 insertions(+), 263 deletions(-) diff --git a/NzbDrone.Core.Test/OrganizerTests/GetNewFilenameFixture.cs b/NzbDrone.Core.Test/OrganizerTests/GetNewFilenameFixture.cs index 55b59dfca..52e9975f9 100644 --- a/NzbDrone.Core.Test/OrganizerTests/GetNewFilenameFixture.cs +++ b/NzbDrone.Core.Test/OrganizerTests/GetNewFilenameFixture.cs @@ -48,12 +48,12 @@ public void GetNewFilename_Series_Episode_Quality_S01E05_Dash() - nameSpecification.SortingIncludeSeriesName = true; - nameSpecification.SortingIncludeEpisodeTitle = true; - nameSpecification.SortingAppendQuality = true; - nameSpecification.SortingSeparatorStyle = 0; - nameSpecification.SortingNumberStyle = 2; - nameSpecification.SortingReplaceSpaces = false; + nameSpecification.IncludeSeriesName = true; + nameSpecification.IncludeEpisodeTitle = true; + nameSpecification.AppendQuality = true; + nameSpecification.SeparatorStyle = 0; + nameSpecification.NumberStyle = 2; + nameSpecification.ReplaceSpaces = false; var episode = Builder.CreateNew() .With(e => e.Title = "City Sushi") @@ -62,7 +62,7 @@ public void GetNewFilename_Series_Episode_Quality_S01E05_Dash() .Build(); //Act - string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.BuildFilename(new List { episode }, _series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false }); //Assert Assert.AreEqual("South Park - S15E06 - City Sushi [HDTV-720p]", result); @@ -75,12 +75,12 @@ public void GetNewFilename_Episode_Quality_1x05_Dash() - nameSpecification.SortingIncludeSeriesName = false; - nameSpecification.SortingIncludeEpisodeTitle = true; - nameSpecification.SortingAppendQuality = true; - nameSpecification.SortingSeparatorStyle = 0; - nameSpecification.SortingNumberStyle = 0; - nameSpecification.SortingReplaceSpaces = false; + nameSpecification.IncludeSeriesName = false; + nameSpecification.IncludeEpisodeTitle = true; + nameSpecification.AppendQuality = true; + nameSpecification.SeparatorStyle = 0; + nameSpecification.NumberStyle = 0; + nameSpecification.ReplaceSpaces = false; var episode = Builder.CreateNew() .With(e => e.Title = "City Sushi") @@ -89,7 +89,7 @@ public void GetNewFilename_Episode_Quality_1x05_Dash() .Build(); //Act - string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.BuildFilename(new List { episode }, _series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false }); //Assert Assert.AreEqual("15x06 - City Sushi [HDTV-720p]", result); @@ -102,12 +102,12 @@ public void GetNewFilename_Series_Quality_01x05_Space() - nameSpecification.SortingIncludeSeriesName = true; - nameSpecification.SortingIncludeEpisodeTitle = false; - nameSpecification.SortingAppendQuality = true; - nameSpecification.SortingSeparatorStyle = 1; - nameSpecification.SortingNumberStyle = 1; - nameSpecification.SortingReplaceSpaces = false; + nameSpecification.IncludeSeriesName = true; + nameSpecification.IncludeEpisodeTitle = false; + nameSpecification.AppendQuality = true; + nameSpecification.SeparatorStyle = 1; + nameSpecification.NumberStyle = 1; + nameSpecification.ReplaceSpaces = false; var episode = Builder.CreateNew() .With(e => e.Title = "City Sushi") @@ -116,7 +116,7 @@ public void GetNewFilename_Series_Quality_01x05_Space() .Build(); //Act - string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.BuildFilename(new List { episode }, _series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false }); //Assert Assert.AreEqual("South Park 05x06 [HDTV-720p]", result); @@ -129,12 +129,12 @@ public void GetNewFilename_Series_s01e05_Space() - nameSpecification.SortingIncludeSeriesName = true; - nameSpecification.SortingIncludeEpisodeTitle = false; - nameSpecification.SortingAppendQuality = false; - nameSpecification.SortingSeparatorStyle = 1; - nameSpecification.SortingNumberStyle = 3; - nameSpecification.SortingReplaceSpaces = false; + nameSpecification.IncludeSeriesName = true; + nameSpecification.IncludeEpisodeTitle = false; + nameSpecification.AppendQuality = false; + nameSpecification.SeparatorStyle = 1; + nameSpecification.NumberStyle = 3; + nameSpecification.ReplaceSpaces = false; var episode = Builder.CreateNew() @@ -144,7 +144,7 @@ public void GetNewFilename_Series_s01e05_Space() .Build(); //Act - string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.BuildFilename(new List { episode }, _series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false }); //Assert Assert.AreEqual("South Park s05e06", result); @@ -157,12 +157,12 @@ public void GetNewFilename_Series_Episode_s01e05_Periods() - nameSpecification.SortingIncludeSeriesName = true; - nameSpecification.SortingIncludeEpisodeTitle = true; - nameSpecification.SortingAppendQuality = false; - nameSpecification.SortingSeparatorStyle = 1; - nameSpecification.SortingNumberStyle = 3; - nameSpecification.SortingReplaceSpaces = true; + nameSpecification.IncludeSeriesName = true; + nameSpecification.IncludeEpisodeTitle = true; + nameSpecification.AppendQuality = false; + nameSpecification.SeparatorStyle = 1; + nameSpecification.NumberStyle = 3; + nameSpecification.ReplaceSpaces = true; var episode = Builder.CreateNew() .With(e => e.Title = "City Sushi") @@ -171,7 +171,7 @@ public void GetNewFilename_Series_Episode_s01e05_Periods() .Build(); //Act - string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.BuildFilename(new List { episode }, _series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false }); //Assert Assert.AreEqual("South.Park.s05e06.City.Sushi", result); @@ -184,12 +184,12 @@ public void GetNewFilename_Series_Episode_s01e05_Dash_Periods_Quality() - nameSpecification.SortingIncludeSeriesName = true; - nameSpecification.SortingIncludeEpisodeTitle = true; - nameSpecification.SortingAppendQuality = true; - nameSpecification.SortingSeparatorStyle = 0; - nameSpecification.SortingNumberStyle = 3; - nameSpecification.SortingReplaceSpaces = true; + nameSpecification.IncludeSeriesName = true; + nameSpecification.IncludeEpisodeTitle = true; + nameSpecification.AppendQuality = true; + nameSpecification.SeparatorStyle = 0; + nameSpecification.NumberStyle = 3; + nameSpecification.ReplaceSpaces = true; var episode = Builder.CreateNew() .With(e => e.Title = "City Sushi") @@ -198,7 +198,7 @@ public void GetNewFilename_Series_Episode_s01e05_Dash_Periods_Quality() .Build(); //Act - string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.BuildFilename(new List { episode }, _series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false }); //Assert Assert.AreEqual("South.Park.-.s05e06.-.City.Sushi.[HDTV-720p]", result); @@ -211,12 +211,12 @@ public void GetNewFilename_S01E05_Dash() - nameSpecification.SortingIncludeSeriesName = false; - nameSpecification.SortingIncludeEpisodeTitle = false; - nameSpecification.SortingAppendQuality = false; - nameSpecification.SortingSeparatorStyle = 0; - nameSpecification.SortingNumberStyle = 2; - nameSpecification.SortingReplaceSpaces = false; + nameSpecification.IncludeSeriesName = false; + nameSpecification.IncludeEpisodeTitle = false; + nameSpecification.AppendQuality = false; + nameSpecification.SeparatorStyle = 0; + nameSpecification.NumberStyle = 2; + nameSpecification.ReplaceSpaces = false; var episode = Builder.CreateNew() @@ -226,7 +226,7 @@ public void GetNewFilename_S01E05_Dash() .Build(); //Act - string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.BuildFilename(new List { episode }, _series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false }); //Assert Assert.AreEqual("S15E06", result); @@ -239,13 +239,13 @@ public void GetNewFilename_multi_Series_Episode_Quality_S01E05_Scene_Dash() - nameSpecification.SortingIncludeSeriesName = true; - nameSpecification.SortingIncludeEpisodeTitle = true; - nameSpecification.SortingAppendQuality = true; - nameSpecification.SortingSeparatorStyle = 0; - nameSpecification.SortingNumberStyle = 2; - nameSpecification.SortingReplaceSpaces = false; - nameSpecification.SortingMultiEpisodeStyle = 3; + nameSpecification.IncludeSeriesName = true; + nameSpecification.IncludeEpisodeTitle = true; + nameSpecification.AppendQuality = true; + nameSpecification.SeparatorStyle = 0; + nameSpecification.NumberStyle = 2; + nameSpecification.ReplaceSpaces = false; + nameSpecification.MultiEpisodeStyle = 3; var episodeOne = Builder.CreateNew() .With(e => e.Title = "Strawberries and Cream (1)") @@ -260,7 +260,7 @@ public void GetNewFilename_multi_Series_Episode_Quality_S01E05_Scene_Dash() .Build(); //Act - string result = Subject.GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.BuildFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false }); //Assert Assert.AreEqual("The Mentalist - S03E23-E24 - Strawberries and Cream [HDTV-720p]", result); @@ -273,13 +273,13 @@ public void GetNewFilename_multi_Episode_Quality_1x05_Repeat_Dash() - nameSpecification.SortingIncludeSeriesName = false; - nameSpecification.SortingIncludeEpisodeTitle = true; - nameSpecification.SortingAppendQuality = true; - nameSpecification.SortingSeparatorStyle = 0; - nameSpecification.SortingNumberStyle = 0; - nameSpecification.SortingReplaceSpaces = false; - nameSpecification.SortingMultiEpisodeStyle = 2; + nameSpecification.IncludeSeriesName = false; + nameSpecification.IncludeEpisodeTitle = true; + nameSpecification.AppendQuality = true; + nameSpecification.SeparatorStyle = 0; + nameSpecification.NumberStyle = 0; + nameSpecification.ReplaceSpaces = false; + nameSpecification.MultiEpisodeStyle = 2; var episodeOne = Builder.CreateNew() .With(e => e.Title = "Strawberries and Cream (1)") @@ -294,7 +294,7 @@ public void GetNewFilename_multi_Episode_Quality_1x05_Repeat_Dash() .Build(); //Act - string result = Subject.GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.BuildFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false }); //Assert Assert.AreEqual("3x23x24 - Strawberries and Cream [HDTV-720p]", result); @@ -307,13 +307,13 @@ public void GetNewFilename_multi_Episode_Quality_01x05_Repeat_Space() - nameSpecification.SortingIncludeSeriesName = false; - nameSpecification.SortingIncludeEpisodeTitle = true; - nameSpecification.SortingAppendQuality = true; - nameSpecification.SortingSeparatorStyle = 1; - nameSpecification.SortingNumberStyle = 0; - nameSpecification.SortingReplaceSpaces = false; - nameSpecification.SortingMultiEpisodeStyle = 2; + nameSpecification.IncludeSeriesName = false; + nameSpecification.IncludeEpisodeTitle = true; + nameSpecification.AppendQuality = true; + nameSpecification.SeparatorStyle = 1; + nameSpecification.NumberStyle = 0; + nameSpecification.ReplaceSpaces = false; + nameSpecification.MultiEpisodeStyle = 2; var episodeOne = Builder.CreateNew() .With(e => e.Title = "Strawberries and Cream (1)") @@ -328,7 +328,7 @@ public void GetNewFilename_multi_Episode_Quality_01x05_Repeat_Space() .Build(); //Act - string result = Subject.GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.BuildFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false }); //Assert Assert.AreEqual("3x23x24 Strawberries and Cream [HDTV-720p]", result); @@ -341,13 +341,13 @@ public void GetNewFilename_multi_Series_Episode_s01e05_Duplicate_Period() - nameSpecification.SortingIncludeSeriesName = true; - nameSpecification.SortingIncludeEpisodeTitle = true; - nameSpecification.SortingAppendQuality = false; - nameSpecification.SortingSeparatorStyle = 1; - nameSpecification.SortingNumberStyle = 3; - nameSpecification.SortingReplaceSpaces = true; - nameSpecification.SortingMultiEpisodeStyle = 1; + nameSpecification.IncludeSeriesName = true; + nameSpecification.IncludeEpisodeTitle = true; + nameSpecification.AppendQuality = false; + nameSpecification.SeparatorStyle = 1; + nameSpecification.NumberStyle = 3; + nameSpecification.ReplaceSpaces = true; + nameSpecification.MultiEpisodeStyle = 1; var episodeOne = Builder.CreateNew() .With(e => e.Title = "Strawberries and Cream (1)") @@ -362,7 +362,7 @@ public void GetNewFilename_multi_Series_Episode_s01e05_Duplicate_Period() .Build(); //Act - string result = Subject.GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.BuildFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false }); //Assert Assert.AreEqual("The.Mentalist.s03e23.s03e24.Strawberries.and.Cream", result); @@ -375,13 +375,13 @@ public void GetNewFilename_multi_Series_S01E05_Extend_Dash_Period() - nameSpecification.SortingIncludeSeriesName = true; - nameSpecification.SortingIncludeEpisodeTitle = false; - nameSpecification.SortingAppendQuality = false; - nameSpecification.SortingSeparatorStyle = 0; - nameSpecification.SortingNumberStyle = 2; - nameSpecification.SortingReplaceSpaces = true; - nameSpecification.SortingMultiEpisodeStyle = 0; + nameSpecification.IncludeSeriesName = true; + nameSpecification.IncludeEpisodeTitle = false; + nameSpecification.AppendQuality = false; + nameSpecification.SeparatorStyle = 0; + nameSpecification.NumberStyle = 2; + nameSpecification.ReplaceSpaces = true; + nameSpecification.MultiEpisodeStyle = 0; var episodeOne = Builder.CreateNew() .With(e => e.Title = "Strawberries and Cream (1)") @@ -396,7 +396,7 @@ public void GetNewFilename_multi_Series_S01E05_Extend_Dash_Period() .Build(); //Act - string result = Subject.GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.BuildFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false }); //Assert Assert.AreEqual("The.Mentalist.-.S03E23-24", result); @@ -409,13 +409,13 @@ public void GetNewFilename_multi_1x05_Repeat_Dash_Period() - nameSpecification.SortingIncludeSeriesName = false; - nameSpecification.SortingIncludeEpisodeTitle = false; - nameSpecification.SortingAppendQuality = false; - nameSpecification.SortingSeparatorStyle = 0; - nameSpecification.SortingNumberStyle = 0; - nameSpecification.SortingReplaceSpaces = true; - nameSpecification.SortingMultiEpisodeStyle = 2; + nameSpecification.IncludeSeriesName = false; + nameSpecification.IncludeEpisodeTitle = false; + nameSpecification.AppendQuality = false; + nameSpecification.SeparatorStyle = 0; + nameSpecification.NumberStyle = 0; + nameSpecification.ReplaceSpaces = true; + nameSpecification.MultiEpisodeStyle = 2; var episodeOne = Builder.CreateNew() .With(e => e.Title = "Strawberries and Cream (1)") @@ -430,7 +430,7 @@ public void GetNewFilename_multi_1x05_Repeat_Dash_Period() .Build(); //Act - string result = Subject.GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.BuildFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false }); //Assert Assert.AreEqual("3x23x24", result); @@ -441,12 +441,12 @@ public void GetNewFilename_should_append_proper_when_proper_and_append_quality_i { //Setup - nameSpecification.SortingIncludeSeriesName = true; - nameSpecification.SortingIncludeEpisodeTitle = true; - nameSpecification.SortingAppendQuality = true; - nameSpecification.SortingSeparatorStyle = 0; - nameSpecification.SortingNumberStyle = 2; - nameSpecification.SortingReplaceSpaces = false; + nameSpecification.IncludeSeriesName = true; + nameSpecification.IncludeEpisodeTitle = true; + nameSpecification.AppendQuality = true; + nameSpecification.SeparatorStyle = 0; + nameSpecification.NumberStyle = 2; + nameSpecification.ReplaceSpaces = false; var episode = Builder.CreateNew() .With(e => e.Title = "City Sushi") @@ -455,7 +455,7 @@ public void GetNewFilename_should_append_proper_when_proper_and_append_quality_i .Build(); //Act - string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, true, new EpisodeFile()); + string result = Subject.BuildFilename(new List { episode }, _series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = true }); //Assert result.Should().Be("South Park - S15E06 - City Sushi [HDTV-720p] [Proper]"); @@ -466,12 +466,12 @@ public void GetNewFilename_should_not_append_proper_when_not_proper_and_append_q { //Setup - nameSpecification.SortingIncludeSeriesName = true; - nameSpecification.SortingIncludeEpisodeTitle = true; - nameSpecification.SortingAppendQuality = true; - nameSpecification.SortingSeparatorStyle = 0; - nameSpecification.SortingNumberStyle = 2; - nameSpecification.SortingReplaceSpaces = false; + nameSpecification.IncludeSeriesName = true; + nameSpecification.IncludeEpisodeTitle = true; + nameSpecification.AppendQuality = true; + nameSpecification.SeparatorStyle = 0; + nameSpecification.NumberStyle = 2; + nameSpecification.ReplaceSpaces = false; var episode = Builder.CreateNew() .With(e => e.Title = "City Sushi") @@ -480,7 +480,7 @@ public void GetNewFilename_should_not_append_proper_when_not_proper_and_append_q .Build(); //Act - string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.BuildFilename(new List { episode }, _series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false }); //Assert result.Should().Be("South Park - S15E06 - City Sushi [HDTV-720p]"); @@ -491,12 +491,12 @@ public void GetNewFilename_should_not_append_proper_when_proper_and_append_quali { //Setup - nameSpecification.SortingIncludeSeriesName = true; - nameSpecification.SortingIncludeEpisodeTitle = true; - nameSpecification.SortingAppendQuality = false; - nameSpecification.SortingSeparatorStyle = 0; - nameSpecification.SortingNumberStyle = 2; - nameSpecification.SortingReplaceSpaces = false; + nameSpecification.IncludeSeriesName = true; + nameSpecification.IncludeEpisodeTitle = true; + nameSpecification.AppendQuality = false; + nameSpecification.SeparatorStyle = 0; + nameSpecification.NumberStyle = 2; + nameSpecification.ReplaceSpaces = false; var episode = Builder.CreateNew() .With(e => e.Title = "City Sushi") @@ -505,7 +505,7 @@ public void GetNewFilename_should_not_append_proper_when_proper_and_append_quali .Build(); //Act - string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, true, new EpisodeFile()); + string result = Subject.BuildFilename(new List { episode }, _series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = true }); //Assert result.Should().Be("South Park - S15E06 - City Sushi"); @@ -516,13 +516,13 @@ public void GetNewFilename_should_order_multiple_episode_files_in_numerical_orde { //Setup - nameSpecification.SortingIncludeSeriesName = true; - nameSpecification.SortingIncludeEpisodeTitle = true; - nameSpecification.SortingAppendQuality = false; - nameSpecification.SortingSeparatorStyle = 0; - nameSpecification.SortingNumberStyle = 2; - nameSpecification.SortingReplaceSpaces = false; - nameSpecification.SortingMultiEpisodeStyle = 3; + nameSpecification.IncludeSeriesName = true; + nameSpecification.IncludeEpisodeTitle = true; + nameSpecification.AppendQuality = false; + nameSpecification.SeparatorStyle = 0; + nameSpecification.NumberStyle = 2; + nameSpecification.ReplaceSpaces = false; + nameSpecification.MultiEpisodeStyle = 3; var episode = Builder.CreateNew() .With(e => e.Title = "Hey, Baby, What's Wrong? (1)") @@ -537,7 +537,7 @@ public void GetNewFilename_should_order_multiple_episode_files_in_numerical_orde .Build(); //Act - string result = Subject.GetNewFilename(new List { episode2, episode }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.BuildFilename(new List { episode2, episode }, new Series { Title = "30 Rock" }, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false }); //Assert result.Should().Be("30 Rock - S06E06-E07 - Hey, Baby, What's Wrong!"); @@ -550,12 +550,12 @@ public void GetNewFilename_Series_Episode_Quality_S01E05_Period() - nameSpecification.SortingIncludeSeriesName = true; - nameSpecification.SortingIncludeEpisodeTitle = true; - nameSpecification.SortingAppendQuality = true; - nameSpecification.SortingSeparatorStyle = 2; - nameSpecification.SortingNumberStyle = 2; - nameSpecification.SortingReplaceSpaces = false; + nameSpecification.IncludeSeriesName = true; + nameSpecification.IncludeEpisodeTitle = true; + nameSpecification.AppendQuality = true; + nameSpecification.SeparatorStyle = 2; + nameSpecification.NumberStyle = 2; + nameSpecification.ReplaceSpaces = false; var episode = Builder.CreateNew() .With(e => e.Title = "City Sushi") @@ -564,7 +564,7 @@ public void GetNewFilename_Series_Episode_Quality_S01E05_Period() .Build(); //Act - string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.BuildFilename(new List { episode }, _series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false }); //Assert Assert.AreEqual("South Park.S15E06.City Sushi [HDTV-720p]", result); @@ -577,12 +577,12 @@ public void GetNewFilename_Episode_Quality_1x05_Period() - nameSpecification.SortingIncludeSeriesName = false; - nameSpecification.SortingIncludeEpisodeTitle = true; - nameSpecification.SortingAppendQuality = true; - nameSpecification.SortingSeparatorStyle = 2; - nameSpecification.SortingNumberStyle = 0; - nameSpecification.SortingReplaceSpaces = false; + nameSpecification.IncludeSeriesName = false; + nameSpecification.IncludeEpisodeTitle = true; + nameSpecification.AppendQuality = true; + nameSpecification.SeparatorStyle = 2; + nameSpecification.NumberStyle = 0; + nameSpecification.ReplaceSpaces = false; var episode = Builder.CreateNew() .With(e => e.Title = "City Sushi") @@ -591,7 +591,7 @@ public void GetNewFilename_Episode_Quality_1x05_Period() .Build(); //Act - string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.BuildFilename(new List { episode }, _series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false }); //Assert Assert.AreEqual("15x06.City Sushi [HDTV-720p]", result); @@ -602,13 +602,13 @@ public void GetNewFilename_UseSceneName_when_sceneName_isNull() { //Setup - nameSpecification.SortingIncludeSeriesName = false; - nameSpecification.SortingIncludeEpisodeTitle = true; - nameSpecification.SortingAppendQuality = true; - nameSpecification.SortingSeparatorStyle = 2; - nameSpecification.SortingNumberStyle = 0; - nameSpecification.SortingReplaceSpaces = false; - nameSpecification.SortingUseSceneName = true; + nameSpecification.IncludeSeriesName = false; + nameSpecification.IncludeEpisodeTitle = true; + nameSpecification.AppendQuality = true; + nameSpecification.SeparatorStyle = 2; + nameSpecification.NumberStyle = 0; + nameSpecification.ReplaceSpaces = false; + nameSpecification.UseSceneName = true; var episode = Builder.CreateNew() .With(e => e.Title = "City Sushi") @@ -622,7 +622,7 @@ public void GetNewFilename_UseSceneName_when_sceneName_isNull() .Build(); //Act - string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, episodeFile); + string result = Subject.BuildFilename(new List { episode }, _series, episodeFile); //Assert result.Should().Be(Path.GetFileNameWithoutExtension(episodeFile.Path)); @@ -633,13 +633,13 @@ public void GetNewFilename_UseSceneName_when_sceneName_isNotNull() { //Setup - nameSpecification.SortingIncludeSeriesName = false; - nameSpecification.SortingIncludeEpisodeTitle = true; - nameSpecification.SortingAppendQuality = true; - nameSpecification.SortingSeparatorStyle = 2; - nameSpecification.SortingNumberStyle = 0; - nameSpecification.SortingReplaceSpaces = false; - nameSpecification.SortingUseSceneName = true; + nameSpecification.IncludeSeriesName = false; + nameSpecification.IncludeEpisodeTitle = true; + nameSpecification.AppendQuality = true; + nameSpecification.SeparatorStyle = 2; + nameSpecification.NumberStyle = 0; + nameSpecification.ReplaceSpaces = false; + nameSpecification.UseSceneName = true; var episode = Builder.CreateNew() .With(e => e.Title = "City Sushi") @@ -653,7 +653,7 @@ public void GetNewFilename_UseSceneName_when_sceneName_isNotNull() .Build(); //Act - string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, episodeFile); + string result = Subject.BuildFilename(new List { episode }, _series, episodeFile); //Assert result.Should().Be(episodeFile.SceneName); @@ -664,13 +664,13 @@ public void should_only_have_one_episodeTitle_when_episode_titles_are_the_same() { //Setup - nameSpecification.SortingIncludeSeriesName = true; - nameSpecification.SortingIncludeEpisodeTitle = true; - nameSpecification.SortingAppendQuality = false; - nameSpecification.SortingSeparatorStyle = 0; - nameSpecification.SortingNumberStyle = 2; - nameSpecification.SortingReplaceSpaces = false; - nameSpecification.SortingMultiEpisodeStyle = 3; + nameSpecification.IncludeSeriesName = true; + nameSpecification.IncludeEpisodeTitle = true; + nameSpecification.AppendQuality = false; + nameSpecification.SeparatorStyle = 0; + nameSpecification.NumberStyle = 2; + nameSpecification.ReplaceSpaces = false; + nameSpecification.MultiEpisodeStyle = 3; var episode = Builder.CreateNew() .With(e => e.Title = "Hey, Baby, What's Wrong? (1)") @@ -685,7 +685,7 @@ public void should_only_have_one_episodeTitle_when_episode_titles_are_the_same() .Build(); //Act - string result = Subject.GetNewFilename(new List { episode2, episode }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.BuildFilename(new List { episode2, episode }, new Series { Title = "30 Rock" }, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false }); //Assert result.Should().Be("30 Rock - S06E06-E07 - Hey, Baby, What's Wrong!"); @@ -696,13 +696,13 @@ public void should_have_two_episodeTitles_when_episode_titles_are_not_the_same() { //Setup - nameSpecification.SortingIncludeSeriesName = true; - nameSpecification.SortingIncludeEpisodeTitle = true; - nameSpecification.SortingAppendQuality = false; - nameSpecification.SortingSeparatorStyle = 0; - nameSpecification.SortingNumberStyle = 2; - nameSpecification.SortingReplaceSpaces = false; - nameSpecification.SortingMultiEpisodeStyle = 3; + nameSpecification.IncludeSeriesName = true; + nameSpecification.IncludeEpisodeTitle = true; + nameSpecification.AppendQuality = false; + nameSpecification.SeparatorStyle = 0; + nameSpecification.NumberStyle = 2; + nameSpecification.ReplaceSpaces = false; + nameSpecification.MultiEpisodeStyle = 3; var episode = Builder.CreateNew() .With(e => e.Title = "Hello") @@ -717,7 +717,7 @@ public void should_have_two_episodeTitles_when_episode_titles_are_not_the_same() .Build(); //Act - string result = Subject.GetNewFilename(new List { episode2, episode }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.BuildFilename(new List { episode2, episode }, new Series { Title = "30 Rock" }, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false }); //Assert result.Should().Be("30 Rock - S06E06-E07 - Hello + World"); @@ -728,13 +728,13 @@ public void should_have_two_episodeTitles_when_distinct_count_is_two() { //Setup - nameSpecification.SortingIncludeSeriesName = true; - nameSpecification.SortingIncludeEpisodeTitle = true; - nameSpecification.SortingAppendQuality = false; - nameSpecification.SortingSeparatorStyle = 0; - nameSpecification.SortingNumberStyle = 2; - nameSpecification.SortingReplaceSpaces = false; - nameSpecification.SortingMultiEpisodeStyle = 3; + nameSpecification.IncludeSeriesName = true; + nameSpecification.IncludeEpisodeTitle = true; + nameSpecification.AppendQuality = false; + nameSpecification.SeparatorStyle = 0; + nameSpecification.NumberStyle = 2; + nameSpecification.ReplaceSpaces = false; + nameSpecification.MultiEpisodeStyle = 3; var episode = Builder.CreateNew() .With(e => e.Title = "Hello (3)") @@ -755,7 +755,7 @@ public void should_have_two_episodeTitles_when_distinct_count_is_two() .Build(); //Act - string result = Subject.GetNewFilename(new List { episode, episode2, episode3 }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.BuildFilename(new List { episode, episode2, episode3 }, new Series { Title = "30 Rock" }, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false }); //Assert result.Should().Be("30 Rock - S06E06-E07-E08 - Hello + World"); @@ -765,12 +765,12 @@ public void should_have_two_episodeTitles_when_distinct_count_is_two() public void should_use_airDate_if_series_isDaily() { - nameSpecification.SortingIncludeSeriesName = true; - nameSpecification.SortingIncludeEpisodeTitle = true; - nameSpecification.SortingAppendQuality = true; - nameSpecification.SortingSeparatorStyle = 0; - nameSpecification.SortingNumberStyle = 2; - nameSpecification.SortingReplaceSpaces = false; + nameSpecification.IncludeSeriesName = true; + nameSpecification.IncludeEpisodeTitle = true; + nameSpecification.AppendQuality = true; + nameSpecification.SeparatorStyle = 0; + nameSpecification.NumberStyle = 2; + nameSpecification.ReplaceSpaces = false; var series = Builder .CreateNew() @@ -786,7 +786,7 @@ public void should_use_airDate_if_series_isDaily() .Build(); var result = Subject - .GetNewFilename(episodes, series, Quality.HDTV720p, false, new EpisodeFile()); + .BuildFilename(episodes, series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false }); result.Should().Be("The Daily Show with Jon Stewart - 2012-12-13 - Kristen Stewart [HDTV-720p]"); } @@ -794,12 +794,12 @@ public void should_use_airDate_if_series_isDaily() public void should_use_airDate_if_series_isDaily_no_episode_title() { - nameSpecification.SortingIncludeSeriesName = true; - nameSpecification.SortingIncludeEpisodeTitle = false; - nameSpecification.SortingAppendQuality = false; - nameSpecification.SortingSeparatorStyle = 0; - nameSpecification.SortingNumberStyle = 2; - nameSpecification.SortingReplaceSpaces = false; + nameSpecification.IncludeSeriesName = true; + nameSpecification.IncludeEpisodeTitle = false; + nameSpecification.AppendQuality = false; + nameSpecification.SeparatorStyle = 0; + nameSpecification.NumberStyle = 2; + nameSpecification.ReplaceSpaces = false; var series = Builder .CreateNew() @@ -815,7 +815,7 @@ public void should_use_airDate_if_series_isDaily_no_episode_title() .Build(); var result = Subject - .GetNewFilename(episodes, series, Quality.HDTV720p, false, new EpisodeFile()); + .BuildFilename(episodes, series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false }); result.Should().Be("The Daily Show with Jon Stewart - 2012-12-13"); } @@ -823,12 +823,12 @@ public void should_use_airDate_if_series_isDaily_no_episode_title() public void should_set_airdate_to_unknown_if_not_available() { - nameSpecification.SortingIncludeSeriesName = true; - nameSpecification.SortingIncludeEpisodeTitle = true; - nameSpecification.SortingAppendQuality = false; - nameSpecification.SortingSeparatorStyle = 0; - nameSpecification.SortingNumberStyle = 2; - nameSpecification.SortingReplaceSpaces = false; + nameSpecification.IncludeSeriesName = true; + nameSpecification.IncludeEpisodeTitle = true; + nameSpecification.AppendQuality = false; + nameSpecification.SeparatorStyle = 0; + nameSpecification.NumberStyle = 2; + nameSpecification.ReplaceSpaces = false; var series = Builder .CreateNew() @@ -844,7 +844,7 @@ public void should_set_airdate_to_unknown_if_not_available() .Build(); var result = Subject - .GetNewFilename(episodes, series, Quality.HDTV720p, false, new EpisodeFile()); + .BuildFilename(episodes, series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false }); result.Should().Be("The Daily Show with Jon Stewart - Unknown - Kristen Stewart"); } } diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpDropFolderFixture.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpDropFolderFixture.cs index 00b6db828..d4fa3ddce 100644 --- a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpDropFolderFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpDropFolderFixture.cs @@ -29,7 +29,7 @@ public void should_do_nothing_if_no_files_are_found() { //Setup var folder = @"C:\Test\DropDir\The Office"; - + Mocker.GetMock().Setup(s => s.GetFiles(folder, SearchOption.AllDirectories)) .Returns(new string[0]); @@ -107,10 +107,10 @@ public void should_move_file_if_a_conflict_is_found() Mocker.GetMock().Setup(s => s.GetEpisodesByFileId(episodeFile.Id)) .Returns(episode); - Mocker.GetMock().Setup(s => s.GetNewFilename(It.IsAny>(), series, Quality.Unknown, false, It.IsAny())) + Mocker.GetMock().Setup(s => s.BuildFilename(It.IsAny>(), series, It.IsAny())) .Returns(newFilename); - Mocker.GetMock().Setup(s => s.CalculateFilePath(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + Mocker.GetMock().Setup(s => s.BuildFilePath(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Returns(new FileInfo(newFilePath)); Mocker.GetMock() diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/MoveEpisodeFileFixture.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/MoveEpisodeFileFixture.cs index 13abeaa5e..7d4ad806e 100644 --- a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/MoveEpisodeFileFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/MoveEpisodeFileFixture.cs @@ -58,11 +58,11 @@ public void should_not_move_file_if_source_and_destination_are_the_same_path() .Returns(fakeEpisode); Mocker.GetMock() - .Setup(e => e.GetNewFilename(fakeEpisode, fakeSeries, It.IsAny(), It.IsAny(), It.IsAny())) + .Setup(e => e.BuildFilename(fakeEpisode, fakeSeries, It.IsAny())) .Returns(filename); Mocker.GetMock() - .Setup(e => e.CalculateFilePath(It.IsAny(), fakeEpisode.First().SeasonNumber, filename, ".avi")) + .Setup(e => e.BuildFilePath(It.IsAny(), fakeEpisode.First().SeasonNumber, filename, ".avi")) .Returns(fi); //Act @@ -108,11 +108,11 @@ public void should_use_EpisodeFiles_quality() .Returns(fakeEpisode); Mocker.GetMock() - .Setup(e => e.GetNewFilename(fakeEpisode, fakeSeries, It.IsAny(), It.IsAny(), It.IsAny())) + .Setup(e => e.BuildFilename(fakeEpisode, fakeSeries, It.IsAny())) .Returns(filename); Mocker.GetMock() - .Setup(e => e.CalculateFilePath(It.IsAny(), fakeEpisode.First().SeasonNumber, filename, ".mkv")) + .Setup(e => e.BuildFilePath(It.IsAny(), fakeEpisode.First().SeasonNumber, filename, ".mkv")) .Returns(fi); Mocker.GetMock() @@ -160,11 +160,11 @@ public void should_log_error_and_return_null_when_source_file_does_not_exists() .Returns(fakeEpisode); Mocker.GetMock() - .Setup(e => e.GetNewFilename(fakeEpisode, fakeSeries, It.IsAny(), It.IsAny(), It.IsAny())) + .Setup(e => e.BuildFilename(fakeEpisode, fakeSeries, It.IsAny())) .Returns(filename); Mocker.GetMock() - .Setup(e => e.CalculateFilePath(It.IsAny(), fakeEpisode.First().SeasonNumber, filename, ".mkv")) + .Setup(e => e.BuildFilePath(It.IsAny(), fakeEpisode.First().SeasonNumber, filename, ".mkv")) .Returns(fi); var result = Mocker.Resolve().MoveEpisodeFile(file, true); diff --git a/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs index d7aceb666..47de8f176 100644 --- a/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs @@ -50,11 +50,11 @@ public void no_misnamed_files() .Setup(c => c.EpisodesWithFiles()).Returns(episodes); Mocker.GetMock() - .Setup(c => c.GetNewFilename(new List { episodes[0] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[0])) + .Setup(c => c.BuildFilename(new List { episodes[0] }, It.IsAny(), episodeFiles[0])) .Returns("Title1"); Mocker.GetMock() - .Setup(c => c.GetNewFilename(new List { episodes[1] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[1])) + .Setup(c => c.BuildFilename(new List { episodes[1] }, It.IsAny(), episodeFiles[1])) .Returns("Title2"); //Act @@ -97,11 +97,11 @@ public void all_misnamed_files() .Setup(c => c.EpisodesWithFiles()).Returns(episodes); Mocker.GetMock() - .Setup(c => c.GetNewFilename(new List { episodes[0] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[0])) + .Setup(c => c.BuildFilename(new List { episodes[0] }, It.IsAny(), episodeFiles[0])) .Returns("New Title 1"); Mocker.GetMock() - .Setup(c => c.GetNewFilename(new List { episodes[1] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[1])) + .Setup(c => c.BuildFilename(new List { episodes[1] }, It.IsAny(), episodeFiles[1])) .Returns("New Title 2"); //Act @@ -144,11 +144,11 @@ public void one_misnamed_file() .Setup(c => c.EpisodesWithFiles()).Returns(episodes); Mocker.GetMock() - .Setup(c => c.GetNewFilename(new List { episodes[0] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[0])) + .Setup(c => c.BuildFilename(new List { episodes[0] }, It.IsAny(), episodeFiles[0])) .Returns("New Title 1"); Mocker.GetMock() - .Setup(c => c.GetNewFilename(new List { episodes[1] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[1])) + .Setup(c => c.BuildFilename(new List { episodes[1] }, It.IsAny(), episodeFiles[1])) .Returns("Title2"); //Act @@ -193,11 +193,11 @@ public void misnamed_multi_episode_file() .Setup(c => c.EpisodesWithFiles()).Returns(episodes); Mocker.GetMock() - .Setup(c => c.GetNewFilename(new List { episodes[0], episodes[1] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[0])) + .Setup(c => c.BuildFilename(new List { episodes[0], episodes[1] }, It.IsAny(), episodeFiles[0])) .Returns("New Title 1"); Mocker.GetMock() - .Setup(c => c.GetNewFilename(new List { episodes[2] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[1])) + .Setup(c => c.BuildFilename(new List { episodes[2] }, It.IsAny(), episodeFiles[1])) .Returns("Title2"); //Act @@ -242,11 +242,11 @@ public void no_misnamed_multi_episode_file() .Setup(c => c.EpisodesWithFiles()).Returns(episodes); Mocker.GetMock() - .Setup(c => c.GetNewFilename(new List { episodes[0], episodes[1] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[0])) + .Setup(c => c.BuildFilename(new List { episodes[0], episodes[1] }, It.IsAny(), episodeFiles[0])) .Returns("Title1"); Mocker.GetMock() - .Setup(c => c.GetNewFilename(new List { episodes[2] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[1])) + .Setup(c => c.BuildFilename(new List { episodes[2] }, It.IsAny(), episodeFiles[1])) .Returns("Title2"); //Act diff --git a/NzbDrone.Core/Organizer/FileNameBuilder.cs b/NzbDrone.Core/Organizer/FileNameBuilder.cs index 6de2d3374..f7c9c5128 100644 --- a/NzbDrone.Core/Organizer/FileNameBuilder.cs +++ b/NzbDrone.Core/Organizer/FileNameBuilder.cs @@ -19,30 +19,30 @@ public static NameSpecification Default get { return new NameSpecification(); } } - public bool SortingUseSceneName { get; set; } + public bool UseSceneName { get; set; } - public int SortingSeparatorStyle { get; set; } + public int SeparatorStyle { get; set; } - public int SortingNumberStyle { get; set; } + public int NumberStyle { get; set; } - public bool SortingIncludeSeriesName { get; set; } + public bool IncludeSeriesName { get; set; } - public int SortingMultiEpisodeStyle { get; set; } + public int MultiEpisodeStyle { get; set; } - public bool SortingIncludeEpisodeTitle { get; set; } + public bool IncludeEpisodeTitle { get; set; } - public bool SortingAppendQuality { get; set; } + public bool AppendQuality { get; set; } - public bool SortingReplaceSpaces { get; set; } + public bool ReplaceSpaces { get; set; } - public string SortingSeasonFolderFormat { get; set; } + public string SeasonFolderFormat { get; set; } } public interface IBuildFileNames { - string GetNewFilename(IList episodes, Series series, Quality quality, bool proper, EpisodeFile episodeFile); - FileInfo CalculateFilePath(Series series, int seasonNumber, string fileName, string extension); + string BuildFilename(IList episodes, Series series, EpisodeFile episodeFile); + FileInfo BuildFilePath(Series series, int seasonNumber, string fileName, string extension); } public class FileNameBuilder : IBuildFileNames @@ -59,23 +59,15 @@ public FileNameBuilder(IBasicRepository nameSpecificationRepo public NameSpecification GetSpecification() { - var spec = _nameSpecificationRepository.SingleOrDefault(); - - if (spec == null) - { - spec = NameSpecification.Default; - } - - return spec; - + return _nameSpecificationRepository.SingleOrDefault() ?? NameSpecification.Default; } - public string GetNewFilename(IList episodes, Series series, Quality quality, bool proper, EpisodeFile episodeFile) + + public string BuildFilename(IList episodes, Series series, EpisodeFile episodeFile) { var nameSpec = GetSpecification(); - - if (nameSpec.SortingUseSceneName) + if (nameSpec.UseSceneName) { _logger.Trace("Attempting to use scene name"); if (String.IsNullOrWhiteSpace(episodeFile.SceneName)) @@ -91,8 +83,8 @@ public string GetNewFilename(IList episodes, Series series, Quality qua var sortedEpisodes = episodes.OrderBy(e => e.EpisodeNumber); - var separatorStyle = EpisodeSortingHelper.GetSeparatorStyle(nameSpec.SortingSeparatorStyle); - var numberStyle = EpisodeSortingHelper.GetNumberStyle(nameSpec.SortingNumberStyle); + var separatorStyle = EpisodeSortingHelper.GetSeparatorStyle(nameSpec.SeparatorStyle); + var numberStyle = EpisodeSortingHelper.GetNumberStyle(nameSpec.NumberStyle); var episodeNames = new List(); @@ -100,7 +92,7 @@ public string GetNewFilename(IList episodes, Series series, Quality qua string result = String.Empty; - if (nameSpec.SortingIncludeSeriesName) + if (nameSpec.IncludeSeriesName) { result += series.Title + separatorStyle.Pattern; } @@ -113,7 +105,7 @@ public string GetNewFilename(IList episodes, Series series, Quality qua if (episodes.Count > 1) { var multiEpisodeStyle = - EpisodeSortingHelper.GetMultiEpisodeStyle(nameSpec.SortingMultiEpisodeStyle); + EpisodeSortingHelper.GetMultiEpisodeStyle(nameSpec.MultiEpisodeStyle); foreach (var episode in sortedEpisodes.Skip(1)) { @@ -147,7 +139,7 @@ public string GetNewFilename(IList episodes, Series series, Quality qua result += "Unknown"; } - if (nameSpec.SortingIncludeEpisodeTitle) + if (nameSpec.IncludeEpisodeTitle) { if (episodeNames.Distinct().Count() == 1) result += separatorStyle.Pattern + episodeNames.First(); @@ -156,22 +148,22 @@ public string GetNewFilename(IList episodes, Series series, Quality qua result += separatorStyle.Pattern + String.Join(" + ", episodeNames.Distinct()); } - if (nameSpec.SortingAppendQuality) + if (nameSpec.AppendQuality) { - result += String.Format(" [{0}]", quality); + result += String.Format(" [{0}]", episodeFile.Quality); - if (proper) + if (episodeFile.Proper) result += " [Proper]"; } - if (nameSpec.SortingReplaceSpaces) + if (nameSpec.ReplaceSpaces) result = result.Replace(' ', '.'); _logger.Trace("New File Name is: [{0}]", result.Trim()); return CleanFilename(result.Trim()); } - public FileInfo CalculateFilePath(Series series, int seasonNumber, string fileName, string extension) + public FileInfo BuildFilePath(Series series, int seasonNumber, string fileName, string extension) { var nameSpec = GetSpecification(); @@ -179,7 +171,7 @@ public FileInfo CalculateFilePath(Series series, int seasonNumber, string fileNa string path = series.Path; if (series.SeasonFolder) { - var seasonFolder = nameSpec.SortingSeasonFolderFormat + var seasonFolder = nameSpec.SeasonFolderFormat .Replace("%0s", seasonNumber.ToString("00")) .Replace("%s", seasonNumber.ToString()); diff --git a/NzbDrone.Core/Providers/DiskScanProvider.cs b/NzbDrone.Core/Providers/DiskScanProvider.cs index 523d82c4f..d8c232087 100644 --- a/NzbDrone.Core/Providers/DiskScanProvider.cs +++ b/NzbDrone.Core/Providers/DiskScanProvider.cs @@ -28,7 +28,7 @@ public class DiskScanProvider private readonly ISeriesRepository _seriesRepository; private readonly IEventAggregator _eventAggregator; - public DiskScanProvider(DiskProvider diskProvider, IEpisodeService episodeService, IMediaFileService mediaFileService, IConfigService configService,IBuildFileNames buildFileNames, + public DiskScanProvider(DiskProvider diskProvider, IEpisodeService episodeService, IMediaFileService mediaFileService, IConfigService configService, IBuildFileNames buildFileNames, RecycleBinProvider recycleBinProvider, MediaInfoProvider mediaInfoProvider, ISeriesRepository seriesRepository, IEventAggregator eventAggregator) { _diskProvider = diskProvider; @@ -188,8 +188,8 @@ public virtual EpisodeFile MoveEpisodeFile(EpisodeFile episodeFile, bool newDown var series = _seriesRepository.Get(episodeFile.SeriesId); var episodes = _episodeService.GetEpisodesByFileId(episodeFile.Id); - string newFileName = _buildFileNames.GetNewFilename(episodes, series, episodeFile.Quality, episodeFile.Proper, episodeFile); - var newFile = _buildFileNames.CalculateFilePath(series, episodes.First().SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path)); + string newFileName = _buildFileNames.BuildFilename(episodes, series, episodeFile); + var newFile = _buildFileNames.BuildFilePath(series, episodes.First().SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path)); //Only rename if existing and new filenames don't match if (DiskProvider.PathEquals(episodeFile.Path, newFile.FullName)) diff --git a/NzbDrone.Core/Providers/MisnamedProvider.cs b/NzbDrone.Core/Providers/MisnamedProvider.cs index 71033bf2d..cba9378c1 100644 --- a/NzbDrone.Core/Providers/MisnamedProvider.cs +++ b/NzbDrone.Core/Providers/MisnamedProvider.cs @@ -26,7 +26,7 @@ public MisnamedProvider(IEpisodeService episodeService, IBuildFileNames buildFil } public virtual List MisnamedFiles(int pageNumber, int pageSize, out int totalItems) - { + { var misnamedFiles = new List(); var episodesWithFiles = _episodeService.EpisodesWithFiles().GroupBy(e => e.EpisodeFileId).ToList(); @@ -37,17 +37,14 @@ public virtual List MisnamedFiles(int pageNumber, int page var misnamedFilesSelect = episodesWithFiles.AsParallel().Where( w => w.First().EpisodeFile.Path != - _buildFileNames.GetNewFilename(w.Select(e => e).ToList(), w.First().Series, - w.First().EpisodeFile.Quality, w.First().EpisodeFile.Proper, w.First().EpisodeFile)).Skip(Math.Max(pageSize * (pageNumber - 1), 0)).Take(pageSize); + _buildFileNames.BuildFilename(w.Select(e => e).ToList(), w.First().Series, w.First().EpisodeFile)).Skip(Math.Max(pageSize * (pageNumber - 1), 0)).Take(pageSize); //Process the episodes misnamedFilesSelect.AsParallel().ForAll(f => { var episodes = f.Select(e => e).ToList(); var firstEpisode = episodes[0]; - var properName = _buildFileNames.GetNewFilename(episodes, - firstEpisode.Series, - firstEpisode.EpisodeFile.Quality, firstEpisode.EpisodeFile.Proper, firstEpisode.EpisodeFile); + var properName = _buildFileNames.BuildFilename(episodes, firstEpisode.Series, firstEpisode.EpisodeFile); var currentName = Path.GetFileNameWithoutExtension(firstEpisode.EpisodeFile.Path);