From dce64a55305a7648724ea0eb089df8a400fdae61 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Wed, 6 Mar 2013 13:20:33 -0800 Subject: [PATCH] moved naming specification out of general config. --- .../NzbDrone.Common.Test.ncrunchproject | 4 + .../JobTests/ImportNewSeriesJobTest.cs | 6 +- .../JobTests/RenameSeasonJobFixture.cs | 2 +- .../MediaFileTests/MediaFileServiceTest.cs | 3 +- NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 2 +- .../GetNewFilenameFixture.cs | 475 +++++++++--------- .../CleanUpDropFolderFixture.cs | 5 +- .../MoveEpisodeFileFixture.cs | 13 +- .../ProviderTests/MisnamedProviderTest.cs | 21 +- NzbDrone.Core/Configuration/ConfigService.cs | 47 -- NzbDrone.Core/Configuration/IConfigService.cs | 8 - NzbDrone.Core/Datastore/BasicRepository.cs | 20 +- .../Download/Clients/BlackholeProvider.cs | 3 +- .../Download/Clients/PneumaticProvider.cs | 3 +- .../ExternalNotificationBase.cs | 2 +- NzbDrone.Core/Indexers/IndexerService.cs | 2 +- NzbDrone.Core/Jobs/JobRepository.cs | 2 +- NzbDrone.Core/MediaFiles/MediaFileService.cs | 143 +----- NzbDrone.Core/Model/EpisodeParseResult.cs | 3 +- NzbDrone.Core/NzbDrone.Core.csproj | 1 + NzbDrone.Core/Organizer/FileNameBuilder.cs | 207 ++++++++ NzbDrone.Core/Providers/DiskScanProvider.cs | 14 +- NzbDrone.Core/Providers/MisnamedProvider.cs | 12 +- 23 files changed, 535 insertions(+), 463 deletions(-) rename NzbDrone.Core.Test/{MediaFileTests => OrganizerTests}/GetNewFilenameFixture.cs (50%) create mode 100644 NzbDrone.Core/Organizer/FileNameBuilder.cs diff --git a/NzbDrone.Common.Test/NzbDrone.Common.Test.ncrunchproject b/NzbDrone.Common.Test/NzbDrone.Common.Test.ncrunchproject index c2e8bc20c..a11e9b3c3 100644 --- a/NzbDrone.Common.Test/NzbDrone.Common.Test.ncrunchproject +++ b/NzbDrone.Common.Test/NzbDrone.Common.Test.ncrunchproject @@ -14,6 +14,7 @@ true 60000 + AutoDetect @@ -32,5 +33,8 @@ NzbDrone.Common.Test.ServiceProviderTests.Should_be_able_to_start_and_stop_service + + .* + \ No newline at end of file diff --git a/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs b/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs index ee6c51bfe..b1844ff90 100644 --- a/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; - +using System.Linq; using FizzWare.NBuilder; using Moq; using NUnit.Framework; @@ -174,7 +174,7 @@ public void AutoIgnoreSeason_existing_should_not_ignore_currentseason() Mocker.GetMock() .Setup(p => p.GetFilesBySeries(seriesId)) - .Returns(episodesFiles); + .Returns(episodesFiles.ToList()); Mocker.GetMock() .Setup(p => p.GetSeasonNumbers(seriesId)) @@ -200,7 +200,7 @@ public void AutoIgnoreSeason_existing_should_ignore_seasons_with_no_file() Mocker.GetMock() .Setup(p => p.GetFilesBySeries(seriesId)) - .Returns(episodesFiles); + .Returns(episodesFiles.ToList()); Mocker.GetMock() .Setup(p => p.GetSeasonNumbers(seriesId)) diff --git a/NzbDrone.Core.Test/JobTests/RenameSeasonJobFixture.cs b/NzbDrone.Core.Test/JobTests/RenameSeasonJobFixture.cs index 3a6b30e71..7133d4705 100644 --- a/NzbDrone.Core.Test/JobTests/RenameSeasonJobFixture.cs +++ b/NzbDrone.Core.Test/JobTests/RenameSeasonJobFixture.cs @@ -44,7 +44,7 @@ public void Setup() Mocker.GetMock() .Setup(s => s.GetFilesBySeason(_series.Id, 5)) - .Returns(_episodeFiles); + .Returns(_episodeFiles.ToList()); } private void WithMovedFiles() diff --git a/NzbDrone.Core.Test/MediaFileTests/MediaFileServiceTest.cs b/NzbDrone.Core.Test/MediaFileTests/MediaFileServiceTest.cs index f73b08311..142a886a7 100644 --- a/NzbDrone.Core.Test/MediaFileTests/MediaFileServiceTest.cs +++ b/NzbDrone.Core.Test/MediaFileTests/MediaFileServiceTest.cs @@ -4,6 +4,7 @@ using NUnit.Framework; using NzbDrone.Core.Configuration; using NzbDrone.Core.MediaFiles; +using NzbDrone.Core.Organizer; using NzbDrone.Core.Tv; using NzbDrone.Core.Test.Framework; @@ -17,7 +18,7 @@ public class MediaFileServiceTest : CoreTest [TestCase("Law & Order: Criminal Intent - S10E07 - Icarus [HDTV-720p]", "Law & Order- Criminal Intent - S10E07 - Icarus [HDTV-720p]")] public void CleanFileName(string name, string expectedName) { - MediaFileService.CleanFilename(name).Should().Be(expectedName); + FileNameBuilder.CleanFilename(name).Should().Be(expectedName); } [Test] diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 8b3da67f1..3ec096119 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -222,7 +222,7 @@ - + diff --git a/NzbDrone.Core.Test/MediaFileTests/GetNewFilenameFixture.cs b/NzbDrone.Core.Test/OrganizerTests/GetNewFilenameFixture.cs similarity index 50% rename from NzbDrone.Core.Test/MediaFileTests/GetNewFilenameFixture.cs rename to NzbDrone.Core.Test/OrganizerTests/GetNewFilenameFixture.cs index 5b774a25b..55b59dfca 100644 --- a/NzbDrone.Core.Test/MediaFileTests/GetNewFilenameFixture.cs +++ b/NzbDrone.Core.Test/OrganizerTests/GetNewFilenameFixture.cs @@ -1,26 +1,28 @@ // ReSharper disable RedundantUsingDirective - using System; using System.Collections.Generic; using System.IO; -using System.Linq; using FizzWare.NBuilder; using FluentAssertions; using NUnit.Framework; using NzbDrone.Core.Configuration; +using NzbDrone.Core.Datastore; using NzbDrone.Core.MediaFiles; +using NzbDrone.Core.Organizer; using NzbDrone.Core.Qualities; using NzbDrone.Core.Tv; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test.MediaFileTests +namespace NzbDrone.Core.Test.OrganizerTests { [TestFixture] // ReSharper disable InconsistentNaming - public class MediaFileProvider_GetNewFilenameTest : CoreTest + public class MediaFileProvider_GetNewFilenameTest : CoreTest { private Series _series; + private NameSpecification nameSpecification; + [SetUp] public void Setup() { @@ -28,6 +30,15 @@ public void Setup() .CreateNew() .With(s => s.Title = "South Park") .Build(); + + + nameSpecification = new NameSpecification(); + + + Mocker.GetMock>() + .Setup(c => c.SingleOrDefault()).Returns(nameSpecification); + + } [Test] @@ -36,13 +47,13 @@ public void GetNewFilename_Series_Episode_Quality_S01E05_Dash() //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); + + nameSpecification.SortingIncludeSeriesName = true; + nameSpecification.SortingIncludeEpisodeTitle = true; + nameSpecification.SortingAppendQuality = true; + nameSpecification.SortingSeparatorStyle = 0; + nameSpecification.SortingNumberStyle = 2; + nameSpecification.SortingReplaceSpaces = false; var episode = Builder.CreateNew() .With(e => e.Title = "City Sushi") @@ -51,7 +62,7 @@ public void GetNewFilename_Series_Episode_Quality_S01E05_Dash() .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("South Park - S15E06 - City Sushi [HDTV-720p]", result); @@ -63,13 +74,13 @@ public void GetNewFilename_Episode_Quality_1x05_Dash() //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); + + nameSpecification.SortingIncludeSeriesName = false; + nameSpecification.SortingIncludeEpisodeTitle = true; + nameSpecification.SortingAppendQuality = true; + nameSpecification.SortingSeparatorStyle = 0; + nameSpecification.SortingNumberStyle = 0; + nameSpecification.SortingReplaceSpaces = false; var episode = Builder.CreateNew() .With(e => e.Title = "City Sushi") @@ -78,7 +89,7 @@ public void GetNewFilename_Episode_Quality_1x05_Dash() .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("15x06 - City Sushi [HDTV-720p]", result); @@ -90,13 +101,13 @@ public void GetNewFilename_Series_Quality_01x05_Space() //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(1); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(1); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); + + nameSpecification.SortingIncludeSeriesName = true; + nameSpecification.SortingIncludeEpisodeTitle = false; + nameSpecification.SortingAppendQuality = true; + nameSpecification.SortingSeparatorStyle = 1; + nameSpecification.SortingNumberStyle = 1; + nameSpecification.SortingReplaceSpaces = false; var episode = Builder.CreateNew() .With(e => e.Title = "City Sushi") @@ -105,7 +116,7 @@ public void GetNewFilename_Series_Quality_01x05_Space() .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("South Park 05x06 [HDTV-720p]", result); @@ -117,13 +128,13 @@ public void GetNewFilename_Series_s01e05_Space() //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(1); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(3); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); + + nameSpecification.SortingIncludeSeriesName = true; + nameSpecification.SortingIncludeEpisodeTitle = false; + nameSpecification.SortingAppendQuality = false; + nameSpecification.SortingSeparatorStyle = 1; + nameSpecification.SortingNumberStyle = 3; + nameSpecification.SortingReplaceSpaces = false; var episode = Builder.CreateNew() @@ -133,7 +144,7 @@ public void GetNewFilename_Series_s01e05_Space() .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("South Park s05e06", result); @@ -145,13 +156,13 @@ public void GetNewFilename_Series_Episode_s01e05_Periods() //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(1); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(3); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(true); + + nameSpecification.SortingIncludeSeriesName = true; + nameSpecification.SortingIncludeEpisodeTitle = true; + nameSpecification.SortingAppendQuality = false; + nameSpecification.SortingSeparatorStyle = 1; + nameSpecification.SortingNumberStyle = 3; + nameSpecification.SortingReplaceSpaces = true; var episode = Builder.CreateNew() .With(e => e.Title = "City Sushi") @@ -160,7 +171,7 @@ public void GetNewFilename_Series_Episode_s01e05_Periods() .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("South.Park.s05e06.City.Sushi", result); @@ -172,13 +183,13 @@ public void GetNewFilename_Series_Episode_s01e05_Dash_Periods_Quality() //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(3); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(true); + + nameSpecification.SortingIncludeSeriesName = true; + nameSpecification.SortingIncludeEpisodeTitle = true; + nameSpecification.SortingAppendQuality = true; + nameSpecification.SortingSeparatorStyle = 0; + nameSpecification.SortingNumberStyle = 3; + nameSpecification.SortingReplaceSpaces = true; var episode = Builder.CreateNew() .With(e => e.Title = "City Sushi") @@ -187,7 +198,7 @@ public void GetNewFilename_Series_Episode_s01e05_Dash_Periods_Quality() .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("South.Park.-.s05e06.-.City.Sushi.[HDTV-720p]", result); @@ -199,13 +210,13 @@ public void GetNewFilename_S01E05_Dash() //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); + + nameSpecification.SortingIncludeSeriesName = false; + nameSpecification.SortingIncludeEpisodeTitle = false; + nameSpecification.SortingAppendQuality = false; + nameSpecification.SortingSeparatorStyle = 0; + nameSpecification.SortingNumberStyle = 2; + nameSpecification.SortingReplaceSpaces = false; var episode = Builder.CreateNew() @@ -215,7 +226,7 @@ public void GetNewFilename_S01E05_Dash() .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("S15E06", result); @@ -227,14 +238,14 @@ public void GetNewFilename_multi_Series_Episode_Quality_S01E05_Scene_Dash() //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(3); + + nameSpecification.SortingIncludeSeriesName = true; + nameSpecification.SortingIncludeEpisodeTitle = true; + nameSpecification.SortingAppendQuality = true; + nameSpecification.SortingSeparatorStyle = 0; + nameSpecification.SortingNumberStyle = 2; + nameSpecification.SortingReplaceSpaces = false; + nameSpecification.SortingMultiEpisodeStyle = 3; var episodeOne = Builder.CreateNew() .With(e => e.Title = "Strawberries and Cream (1)") @@ -249,7 +260,7 @@ public void GetNewFilename_multi_Series_Episode_Quality_S01E05_Scene_Dash() .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("The Mentalist - S03E23-E24 - Strawberries and Cream [HDTV-720p]", result); @@ -261,14 +272,14 @@ public void GetNewFilename_multi_Episode_Quality_1x05_Repeat_Dash() //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(2); + + nameSpecification.SortingIncludeSeriesName = false; + nameSpecification.SortingIncludeEpisodeTitle = true; + nameSpecification.SortingAppendQuality = true; + nameSpecification.SortingSeparatorStyle = 0; + nameSpecification.SortingNumberStyle = 0; + nameSpecification.SortingReplaceSpaces = false; + nameSpecification.SortingMultiEpisodeStyle = 2; var episodeOne = Builder.CreateNew() .With(e => e.Title = "Strawberries and Cream (1)") @@ -283,7 +294,7 @@ public void GetNewFilename_multi_Episode_Quality_1x05_Repeat_Dash() .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("3x23x24 - Strawberries and Cream [HDTV-720p]", result); @@ -295,14 +306,14 @@ public void GetNewFilename_multi_Episode_Quality_01x05_Repeat_Space() //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(1); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(2); + + nameSpecification.SortingIncludeSeriesName = false; + nameSpecification.SortingIncludeEpisodeTitle = true; + nameSpecification.SortingAppendQuality = true; + nameSpecification.SortingSeparatorStyle = 1; + nameSpecification.SortingNumberStyle = 0; + nameSpecification.SortingReplaceSpaces = false; + nameSpecification.SortingMultiEpisodeStyle = 2; var episodeOne = Builder.CreateNew() .With(e => e.Title = "Strawberries and Cream (1)") @@ -317,7 +328,7 @@ public void GetNewFilename_multi_Episode_Quality_01x05_Repeat_Space() .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("3x23x24 Strawberries and Cream [HDTV-720p]", result); @@ -329,14 +340,14 @@ public void GetNewFilename_multi_Series_Episode_s01e05_Duplicate_Period() //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(1); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(3); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(true); - fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(1); + + nameSpecification.SortingIncludeSeriesName = true; + nameSpecification.SortingIncludeEpisodeTitle = true; + nameSpecification.SortingAppendQuality = false; + nameSpecification.SortingSeparatorStyle = 1; + nameSpecification.SortingNumberStyle = 3; + nameSpecification.SortingReplaceSpaces = true; + nameSpecification.SortingMultiEpisodeStyle = 1; var episodeOne = Builder.CreateNew() .With(e => e.Title = "Strawberries and Cream (1)") @@ -351,7 +362,7 @@ public void GetNewFilename_multi_Series_Episode_s01e05_Duplicate_Period() .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("The.Mentalist.s03e23.s03e24.Strawberries.and.Cream", result); @@ -363,14 +374,14 @@ public void GetNewFilename_multi_Series_S01E05_Extend_Dash_Period() //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(true); - fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(0); + + nameSpecification.SortingIncludeSeriesName = true; + nameSpecification.SortingIncludeEpisodeTitle = false; + nameSpecification.SortingAppendQuality = false; + nameSpecification.SortingSeparatorStyle = 0; + nameSpecification.SortingNumberStyle = 2; + nameSpecification.SortingReplaceSpaces = true; + nameSpecification.SortingMultiEpisodeStyle = 0; var episodeOne = Builder.CreateNew() .With(e => e.Title = "Strawberries and Cream (1)") @@ -385,7 +396,7 @@ public void GetNewFilename_multi_Series_S01E05_Extend_Dash_Period() .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("The.Mentalist.-.S03E23-24", result); @@ -397,14 +408,14 @@ public void GetNewFilename_multi_1x05_Repeat_Dash_Period() //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(true); - fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(2); + + nameSpecification.SortingIncludeSeriesName = false; + nameSpecification.SortingIncludeEpisodeTitle = false; + nameSpecification.SortingAppendQuality = false; + nameSpecification.SortingSeparatorStyle = 0; + nameSpecification.SortingNumberStyle = 0; + nameSpecification.SortingReplaceSpaces = true; + nameSpecification.SortingMultiEpisodeStyle = 2; var episodeOne = Builder.CreateNew() .With(e => e.Title = "Strawberries and Cream (1)") @@ -419,7 +430,7 @@ public void GetNewFilename_multi_1x05_Repeat_Dash_Period() .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("3x23x24", result); @@ -429,13 +440,13 @@ public void GetNewFilename_multi_1x05_Repeat_Dash_Period() public void GetNewFilename_should_append_proper_when_proper_and_append_quality_is_true() { //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); + + nameSpecification.SortingIncludeSeriesName = true; + nameSpecification.SortingIncludeEpisodeTitle = true; + nameSpecification.SortingAppendQuality = true; + nameSpecification.SortingSeparatorStyle = 0; + nameSpecification.SortingNumberStyle = 2; + nameSpecification.SortingReplaceSpaces = false; var episode = Builder.CreateNew() .With(e => e.Title = "City Sushi") @@ -444,7 +455,7 @@ public void GetNewFilename_should_append_proper_when_proper_and_append_quality_i .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, true, new EpisodeFile()); + string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, true, new EpisodeFile()); //Assert result.Should().Be("South Park - S15E06 - City Sushi [HDTV-720p] [Proper]"); @@ -454,13 +465,13 @@ public void GetNewFilename_should_append_proper_when_proper_and_append_quality_i public void GetNewFilename_should_not_append_proper_when_not_proper_and_append_quality_is_true() { //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); + + nameSpecification.SortingIncludeSeriesName = true; + nameSpecification.SortingIncludeEpisodeTitle = true; + nameSpecification.SortingAppendQuality = true; + nameSpecification.SortingSeparatorStyle = 0; + nameSpecification.SortingNumberStyle = 2; + nameSpecification.SortingReplaceSpaces = false; var episode = Builder.CreateNew() .With(e => e.Title = "City Sushi") @@ -469,7 +480,7 @@ public void GetNewFilename_should_not_append_proper_when_not_proper_and_append_q .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); //Assert result.Should().Be("South Park - S15E06 - City Sushi [HDTV-720p]"); @@ -479,13 +490,13 @@ public void GetNewFilename_should_not_append_proper_when_not_proper_and_append_q public void GetNewFilename_should_not_append_proper_when_proper_and_append_quality_is_false() { //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); + + nameSpecification.SortingIncludeSeriesName = true; + nameSpecification.SortingIncludeEpisodeTitle = true; + nameSpecification.SortingAppendQuality = false; + nameSpecification.SortingSeparatorStyle = 0; + nameSpecification.SortingNumberStyle = 2; + nameSpecification.SortingReplaceSpaces = false; var episode = Builder.CreateNew() .With(e => e.Title = "City Sushi") @@ -494,7 +505,7 @@ public void GetNewFilename_should_not_append_proper_when_proper_and_append_quali .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, true, new EpisodeFile()); + string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, true, new EpisodeFile()); //Assert result.Should().Be("South Park - S15E06 - City Sushi"); @@ -504,14 +515,14 @@ public void GetNewFilename_should_not_append_proper_when_proper_and_append_quali public void GetNewFilename_should_order_multiple_episode_files_in_numerical_order() { //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(3); + + nameSpecification.SortingIncludeSeriesName = true; + nameSpecification.SortingIncludeEpisodeTitle = true; + nameSpecification.SortingAppendQuality = false; + nameSpecification.SortingSeparatorStyle = 0; + nameSpecification.SortingNumberStyle = 2; + nameSpecification.SortingReplaceSpaces = false; + nameSpecification.SortingMultiEpisodeStyle = 3; var episode = Builder.CreateNew() .With(e => e.Title = "Hey, Baby, What's Wrong? (1)") @@ -526,7 +537,7 @@ public void GetNewFilename_should_order_multiple_episode_files_in_numerical_orde .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode2, episode }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.GetNewFilename(new List { episode2, episode }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile()); //Assert result.Should().Be("30 Rock - S06E06-E07 - Hey, Baby, What's Wrong!"); @@ -538,13 +549,13 @@ public void GetNewFilename_Series_Episode_Quality_S01E05_Period() //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); + + nameSpecification.SortingIncludeSeriesName = true; + nameSpecification.SortingIncludeEpisodeTitle = true; + nameSpecification.SortingAppendQuality = true; + nameSpecification.SortingSeparatorStyle = 2; + nameSpecification.SortingNumberStyle = 2; + nameSpecification.SortingReplaceSpaces = false; var episode = Builder.CreateNew() .With(e => e.Title = "City Sushi") @@ -553,7 +564,7 @@ public void GetNewFilename_Series_Episode_Quality_S01E05_Period() .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("South Park.S15E06.City Sushi [HDTV-720p]", result); @@ -565,13 +576,13 @@ public void GetNewFilename_Episode_Quality_1x05_Period() //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); + + nameSpecification.SortingIncludeSeriesName = false; + nameSpecification.SortingIncludeEpisodeTitle = true; + nameSpecification.SortingAppendQuality = true; + nameSpecification.SortingSeparatorStyle = 2; + nameSpecification.SortingNumberStyle = 0; + nameSpecification.SortingReplaceSpaces = false; var episode = Builder.CreateNew() .With(e => e.Title = "City Sushi") @@ -580,7 +591,7 @@ public void GetNewFilename_Episode_Quality_1x05_Period() .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("15x06.City Sushi [HDTV-720p]", result); @@ -590,14 +601,14 @@ public void GetNewFilename_Episode_Quality_1x05_Period() public void GetNewFilename_UseSceneName_when_sceneName_isNull() { //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - fakeConfig.SetupGet(c => c.SortingUseSceneName).Returns(true); + + nameSpecification.SortingIncludeSeriesName = false; + nameSpecification.SortingIncludeEpisodeTitle = true; + nameSpecification.SortingAppendQuality = true; + nameSpecification.SortingSeparatorStyle = 2; + nameSpecification.SortingNumberStyle = 0; + nameSpecification.SortingReplaceSpaces = false; + nameSpecification.SortingUseSceneName = true; var episode = Builder.CreateNew() .With(e => e.Title = "City Sushi") @@ -611,7 +622,7 @@ public void GetNewFilename_UseSceneName_when_sceneName_isNull() .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, episodeFile); + string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, episodeFile); //Assert result.Should().Be(Path.GetFileNameWithoutExtension(episodeFile.Path)); @@ -621,14 +632,14 @@ public void GetNewFilename_UseSceneName_when_sceneName_isNull() public void GetNewFilename_UseSceneName_when_sceneName_isNotNull() { //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - fakeConfig.SetupGet(c => c.SortingUseSceneName).Returns(true); + + nameSpecification.SortingIncludeSeriesName = false; + nameSpecification.SortingIncludeEpisodeTitle = true; + nameSpecification.SortingAppendQuality = true; + nameSpecification.SortingSeparatorStyle = 2; + nameSpecification.SortingNumberStyle = 0; + nameSpecification.SortingReplaceSpaces = false; + nameSpecification.SortingUseSceneName = true; var episode = Builder.CreateNew() .With(e => e.Title = "City Sushi") @@ -642,7 +653,7 @@ public void GetNewFilename_UseSceneName_when_sceneName_isNotNull() .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, episodeFile); + string result = Subject.GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, episodeFile); //Assert result.Should().Be(episodeFile.SceneName); @@ -652,14 +663,14 @@ public void GetNewFilename_UseSceneName_when_sceneName_isNotNull() public void should_only_have_one_episodeTitle_when_episode_titles_are_the_same() { //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(3); + + nameSpecification.SortingIncludeSeriesName = true; + nameSpecification.SortingIncludeEpisodeTitle = true; + nameSpecification.SortingAppendQuality = false; + nameSpecification.SortingSeparatorStyle = 0; + nameSpecification.SortingNumberStyle = 2; + nameSpecification.SortingReplaceSpaces = false; + nameSpecification.SortingMultiEpisodeStyle = 3; var episode = Builder.CreateNew() .With(e => e.Title = "Hey, Baby, What's Wrong? (1)") @@ -674,7 +685,7 @@ public void should_only_have_one_episodeTitle_when_episode_titles_are_the_same() .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode2, episode }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.GetNewFilename(new List { episode2, episode }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile()); //Assert result.Should().Be("30 Rock - S06E06-E07 - Hey, Baby, What's Wrong!"); @@ -684,14 +695,14 @@ public void should_only_have_one_episodeTitle_when_episode_titles_are_the_same() public void should_have_two_episodeTitles_when_episode_titles_are_not_the_same() { //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(3); + + nameSpecification.SortingIncludeSeriesName = true; + nameSpecification.SortingIncludeEpisodeTitle = true; + nameSpecification.SortingAppendQuality = false; + nameSpecification.SortingSeparatorStyle = 0; + nameSpecification.SortingNumberStyle = 2; + nameSpecification.SortingReplaceSpaces = false; + nameSpecification.SortingMultiEpisodeStyle = 3; var episode = Builder.CreateNew() .With(e => e.Title = "Hello") @@ -706,7 +717,7 @@ public void should_have_two_episodeTitles_when_episode_titles_are_not_the_same() .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode2, episode }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.GetNewFilename(new List { episode2, episode }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile()); //Assert result.Should().Be("30 Rock - S06E06-E07 - Hello + World"); @@ -716,14 +727,14 @@ public void should_have_two_episodeTitles_when_episode_titles_are_not_the_same() public void should_have_two_episodeTitles_when_distinct_count_is_two() { //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(3); + + nameSpecification.SortingIncludeSeriesName = true; + nameSpecification.SortingIncludeEpisodeTitle = true; + nameSpecification.SortingAppendQuality = false; + nameSpecification.SortingSeparatorStyle = 0; + nameSpecification.SortingNumberStyle = 2; + nameSpecification.SortingReplaceSpaces = false; + nameSpecification.SortingMultiEpisodeStyle = 3; var episode = Builder.CreateNew() .With(e => e.Title = "Hello (3)") @@ -744,7 +755,7 @@ public void should_have_two_episodeTitles_when_distinct_count_is_two() .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode, episode2, episode3 }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Subject.GetNewFilename(new List { episode, episode2, episode3 }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile()); //Assert result.Should().Be("30 Rock - S06E06-E07-E08 - Hello + World"); @@ -753,13 +764,13 @@ public void should_have_two_episodeTitles_when_distinct_count_is_two() [Test] public void should_use_airDate_if_series_isDaily() { - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); + + nameSpecification.SortingIncludeSeriesName = true; + nameSpecification.SortingIncludeEpisodeTitle = true; + nameSpecification.SortingAppendQuality = true; + nameSpecification.SortingSeparatorStyle = 0; + nameSpecification.SortingNumberStyle = 2; + nameSpecification.SortingReplaceSpaces = false; var series = Builder .CreateNew() @@ -774,7 +785,7 @@ public void should_use_airDate_if_series_isDaily() .With(e => e.Title = "Kristen Stewart") .Build(); - var result = Mocker.Resolve() + var result = Subject .GetNewFilename(episodes, series, Quality.HDTV720p, false, new EpisodeFile()); result.Should().Be("The Daily Show with Jon Stewart - 2012-12-13 - Kristen Stewart [HDTV-720p]"); } @@ -782,13 +793,13 @@ public void should_use_airDate_if_series_isDaily() [Test] public void should_use_airDate_if_series_isDaily_no_episode_title() { - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); + + nameSpecification.SortingIncludeSeriesName = true; + nameSpecification.SortingIncludeEpisodeTitle = false; + nameSpecification.SortingAppendQuality = false; + nameSpecification.SortingSeparatorStyle = 0; + nameSpecification.SortingNumberStyle = 2; + nameSpecification.SortingReplaceSpaces = false; var series = Builder .CreateNew() @@ -803,7 +814,7 @@ public void should_use_airDate_if_series_isDaily_no_episode_title() .With(e => e.Title = "Kristen Stewart") .Build(); - var result = Mocker.Resolve() + var result = Subject .GetNewFilename(episodes, series, Quality.HDTV720p, false, new EpisodeFile()); result.Should().Be("The Daily Show with Jon Stewart - 2012-12-13"); } @@ -811,13 +822,13 @@ public void should_use_airDate_if_series_isDaily_no_episode_title() [Test] public void should_set_airdate_to_unknown_if_not_available() { - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); + + nameSpecification.SortingIncludeSeriesName = true; + nameSpecification.SortingIncludeEpisodeTitle = true; + nameSpecification.SortingAppendQuality = false; + nameSpecification.SortingSeparatorStyle = 0; + nameSpecification.SortingNumberStyle = 2; + nameSpecification.SortingReplaceSpaces = false; var series = Builder .CreateNew() @@ -832,7 +843,7 @@ public void should_set_airdate_to_unknown_if_not_available() .With(e => e.Title = "Kristen Stewart") .Build(); - var result = Mocker.Resolve() + var result = Subject .GetNewFilename(episodes, series, Quality.HDTV720p, false, new EpisodeFile()); 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 65455ccb0..00b6db828 100644 --- a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpDropFolderFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpDropFolderFixture.cs @@ -9,6 +9,7 @@ using NUnit.Framework; using NzbDrone.Common; using NzbDrone.Core.MediaFiles; +using NzbDrone.Core.Organizer; using NzbDrone.Core.Qualities; using NzbDrone.Core.Tv; using NzbDrone.Core.Model; @@ -106,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.GetNewFilename(It.IsAny>(), series, Quality.Unknown, false, It.IsAny())) .Returns(newFilename); - Mocker.GetMock().Setup(s => s.CalculateFilePath(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + Mocker.GetMock().Setup(s => s.CalculateFilePath(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 0c8169e21..13abeaa5e 100644 --- a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/MoveEpisodeFileFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/MoveEpisodeFileFixture.cs @@ -11,6 +11,7 @@ using NzbDrone.Core.Download; using NzbDrone.Core.ExternalNotification; using NzbDrone.Core.MediaFiles; +using NzbDrone.Core.Organizer; using NzbDrone.Core.Qualities; using NzbDrone.Core.Tv; using NzbDrone.Core.Model; @@ -56,11 +57,11 @@ public void should_not_move_file_if_source_and_destination_are_the_same_path() .Setup(e => e.GetEpisodesByFileId(file.Id)) .Returns(fakeEpisode); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.GetNewFilename(fakeEpisode, fakeSeries, It.IsAny(), It.IsAny(), It.IsAny())) .Returns(filename); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.CalculateFilePath(It.IsAny(), fakeEpisode.First().SeasonNumber, filename, ".avi")) .Returns(fi); @@ -106,11 +107,11 @@ public void should_use_EpisodeFiles_quality() .Setup(e => e.GetEpisodesByFileId(file.Id)) .Returns(fakeEpisode); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.GetNewFilename(fakeEpisode, fakeSeries, It.IsAny(), It.IsAny(), It.IsAny())) .Returns(filename); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.CalculateFilePath(It.IsAny(), fakeEpisode.First().SeasonNumber, filename, ".mkv")) .Returns(fi); @@ -158,11 +159,11 @@ public void should_log_error_and_return_null_when_source_file_does_not_exists() .Setup(e => e.GetEpisodesByFileId(file.Id)) .Returns(fakeEpisode); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.GetNewFilename(fakeEpisode, fakeSeries, It.IsAny(), It.IsAny(), It.IsAny())) .Returns(filename); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.CalculateFilePath(It.IsAny(), fakeEpisode.First().SeasonNumber, filename, ".mkv")) .Returns(fi); diff --git a/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs index 24debc39b..d7aceb666 100644 --- a/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs @@ -5,6 +5,7 @@ using Moq; using NUnit.Framework; using NzbDrone.Core.MediaFiles; +using NzbDrone.Core.Organizer; using NzbDrone.Core.Qualities; using NzbDrone.Core.Tv; using NzbDrone.Core.Providers; @@ -48,11 +49,11 @@ public void no_misnamed_files() Mocker.GetMock() .Setup(c => c.EpisodesWithFiles()).Returns(episodes); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetNewFilename(new List { episodes[0] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[0])) .Returns("Title1"); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetNewFilename(new List { episodes[1] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[1])) .Returns("Title2"); @@ -95,11 +96,11 @@ public void all_misnamed_files() Mocker.GetMock() .Setup(c => c.EpisodesWithFiles()).Returns(episodes); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetNewFilename(new List { episodes[0] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[0])) .Returns("New Title 1"); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetNewFilename(new List { episodes[1] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[1])) .Returns("New Title 2"); @@ -142,11 +143,11 @@ public void one_misnamed_file() Mocker.GetMock() .Setup(c => c.EpisodesWithFiles()).Returns(episodes); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetNewFilename(new List { episodes[0] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[0])) .Returns("New Title 1"); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetNewFilename(new List { episodes[1] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[1])) .Returns("Title2"); @@ -191,11 +192,11 @@ public void misnamed_multi_episode_file() Mocker.GetMock() .Setup(c => c.EpisodesWithFiles()).Returns(episodes); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetNewFilename(new List { episodes[0], episodes[1] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[0])) .Returns("New Title 1"); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetNewFilename(new List { episodes[2] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[1])) .Returns("Title2"); @@ -240,11 +241,11 @@ public void no_misnamed_multi_episode_file() Mocker.GetMock() .Setup(c => c.EpisodesWithFiles()).Returns(episodes); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetNewFilename(new List { episodes[0], episodes[1] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[0])) .Returns("Title1"); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetNewFilename(new List { episodes[2] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[1])) .Returns("Title2"); diff --git a/NzbDrone.Core/Configuration/ConfigService.cs b/NzbDrone.Core/Configuration/ConfigService.cs index 1d1e578ef..e8470b657 100644 --- a/NzbDrone.Core/Configuration/ConfigService.cs +++ b/NzbDrone.Core/Configuration/ConfigService.cs @@ -149,29 +149,6 @@ public String DownloadClientTvDirectory set { SetValue("DownloadClientTvDirectory", value); } } - public bool SortingIncludeSeriesName - { - get { return GetValueBoolean("Sorting_SeriesName", true); } - set { SetValue("Sorting_SeriesName", value); } - } - - public bool SortingIncludeEpisodeTitle - { - get { return GetValueBoolean("Sorting_EpisodeName", true); } - set { SetValue("Sorting_EpisodeName", value); } - } - - public bool SortingReplaceSpaces - { - get { return GetValueBoolean("Sorting_ReplaceSpaces"); } - set { SetValue("Sorting_ReplaceSpaces", value); } - } - - public bool SortingAppendQuality - { - get { return GetValueBoolean("Sorting_AppendQaulity", true); } - set { SetValue("Sorting_AppendQaulity", value); } - } public bool UseSeasonFolder { @@ -186,30 +163,6 @@ public string SortingSeasonFolderFormat set { SetValue("Sorting_SeasonFolderFormat", value); } } - public int SortingSeparatorStyle - { - get { return GetValueInt("Sorting_SeparatorStyle"); } - set { SetValue("Sorting_SeparatorStyle", value); } - } - - public int SortingNumberStyle - { - get { return GetValueInt("Sorting_NumberStyle", 2); } - set { SetValue("Sorting_NumberStyle", value); } - } - - public int SortingMultiEpisodeStyle - { - get { return GetValueInt("Sorting_MultiEpisodeStyle"); } - set { SetValue("Sorting_MultiEpisodeStyle", value); } - } - - public bool SortingUseSceneName - { - get { return GetValueBoolean("Sorting_UseSceneName", false); } - set { SetValue("Sorting_UseSceneName", value); } - } - public int DefaultQualityProfile { get { return GetValueInt("DefaultQualityProfile", 1); } diff --git a/NzbDrone.Core/Configuration/IConfigService.cs b/NzbDrone.Core/Configuration/IConfigService.cs index f8b3b8fc8..fb644569c 100644 --- a/NzbDrone.Core/Configuration/IConfigService.cs +++ b/NzbDrone.Core/Configuration/IConfigService.cs @@ -25,16 +25,8 @@ public interface IConfigService SabPriorityType SabBacklogTvPriority { get; set; } SabPriorityType SabRecentTvPriority { get; set; } String DownloadClientTvDirectory { get; set; } - bool SortingIncludeSeriesName { get; set; } - bool SortingIncludeEpisodeTitle { get; set; } - bool SortingReplaceSpaces { get; set; } - bool SortingAppendQuality { get; set; } bool UseSeasonFolder { get; set; } string SortingSeasonFolderFormat { get; set; } - int SortingSeparatorStyle { get; set; } - int SortingNumberStyle { get; set; } - int SortingMultiEpisodeStyle { get; set; } - bool SortingUseSceneName { get; set; } int DefaultQualityProfile { get; set; } Boolean XbmcUpdateLibrary { get; set; } Boolean XbmcCleanLibrary { get; set; } diff --git a/NzbDrone.Core/Datastore/BasicRepository.cs b/NzbDrone.Core/Datastore/BasicRepository.cs index 4042e98c3..57bfd60c8 100644 --- a/NzbDrone.Core/Datastore/BasicRepository.cs +++ b/NzbDrone.Core/Datastore/BasicRepository.cs @@ -8,13 +8,15 @@ namespace NzbDrone.Core.Datastore IEnumerable All(); int Count(); TModel Get(int id); + TModel Single(); + TModel SingleOrDefault(); TModel Insert(TModel model); TModel Update(TModel model); - TModel Upsert(TModel model); + TModel UpSert(TModel model); void Delete(int id); IList InsertMany(IList model); IList UpdateMany(IList model); - void DeleteMany(IList model); + void DeleteMany(List model); void Purge(); bool HasItems(); } @@ -45,6 +47,16 @@ public TModel Get(int id) return Queryable.Single(c => c.Id == id); } + public TModel Single() + { + return Queryable.Single(); + } + + public TModel SingleOrDefault() + { + return Queryable.SingleOrDefault(); + } + public TModel Insert(TModel model) { return ObjectDatabase.Insert(model); @@ -65,12 +77,12 @@ public IList UpdateMany(IList model) return ObjectDatabase.UpdateMany(model); } - public void DeleteMany(IList model) + public void DeleteMany(List model) { ObjectDatabase.DeleteMany(model); } - public TModel Upsert(TModel model) + public TModel UpSert(TModel model) { if (model.Id == 0) { diff --git a/NzbDrone.Core/Download/Clients/BlackholeProvider.cs b/NzbDrone.Core/Download/Clients/BlackholeProvider.cs index 4bae2b3a0..8594df2f9 100644 --- a/NzbDrone.Core/Download/Clients/BlackholeProvider.cs +++ b/NzbDrone.Core/Download/Clients/BlackholeProvider.cs @@ -8,6 +8,7 @@ using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Model; using NzbDrone.Core.DecisionEngine; +using NzbDrone.Core.Organizer; namespace NzbDrone.Core.Download.Clients { @@ -37,7 +38,7 @@ public virtual bool DownloadNzb(string url, string title, bool recentlyAired) { try { - title = MediaFileService.CleanFilename(title); + title = FileNameBuilder.CleanFilename(title); var filename = Path.Combine(_configService.BlackholeDirectory, title + ".nzb"); diff --git a/NzbDrone.Core/Download/Clients/PneumaticProvider.cs b/NzbDrone.Core/Download/Clients/PneumaticProvider.cs index 1b9314f89..48eaf9ddb 100644 --- a/NzbDrone.Core/Download/Clients/PneumaticProvider.cs +++ b/NzbDrone.Core/Download/Clients/PneumaticProvider.cs @@ -7,6 +7,7 @@ using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Model; using NzbDrone.Core.DecisionEngine; +using NzbDrone.Core.Organizer; namespace NzbDrone.Core.Download.Clients { @@ -43,7 +44,7 @@ public virtual bool DownloadNzb(string url, string title, bool recentlyAired) return false; } - title = MediaFileService.CleanFilename(title); + title = FileNameBuilder.CleanFilename(title); //Save to the Pneumatic directory (The user will need to ensure its accessible by XBMC) var filename = Path.Combine(_configService.PneumaticDirectory, title + ".nzb"); diff --git a/NzbDrone.Core/ExternalNotification/ExternalNotificationBase.cs b/NzbDrone.Core/ExternalNotification/ExternalNotificationBase.cs index 7b2f852dd..aab88548f 100644 --- a/NzbDrone.Core/ExternalNotification/ExternalNotificationBase.cs +++ b/NzbDrone.Core/ExternalNotification/ExternalNotificationBase.cs @@ -65,7 +65,7 @@ private void SetEnableStatus(Action updateAction new ExternalNotificationDefinition { Name = Name }; updateAction(def); - _externalNotificationRepository.Upsert(def); + _externalNotificationRepository.UpSert(def); } private bool GetEnableStatus(Func readFunction) diff --git a/NzbDrone.Core/Indexers/IndexerService.cs b/NzbDrone.Core/Indexers/IndexerService.cs index 3c0a1c352..83a42dab4 100644 --- a/NzbDrone.Core/Indexers/IndexerService.cs +++ b/NzbDrone.Core/Indexers/IndexerService.cs @@ -67,7 +67,7 @@ public void SaveSettings(Indexer indexer) { //Todo: This will be used in the API _logger.Debug("Upserting Indexer definitions for {0}", indexer.Name); - _indexerRepository.Upsert(indexer); + _indexerRepository.UpSert(indexer); } public Indexer GetSettings(Type type) diff --git a/NzbDrone.Core/Jobs/JobRepository.cs b/NzbDrone.Core/Jobs/JobRepository.cs index 1286454fa..fd00e9617 100644 --- a/NzbDrone.Core/Jobs/JobRepository.cs +++ b/NzbDrone.Core/Jobs/JobRepository.cs @@ -68,7 +68,7 @@ public void Init() jobDefinition.Interval = Convert.ToInt32(job.DefaultInterval.TotalMinutes); - Upsert(jobDefinition); + UpSert(jobDefinition); } } } diff --git a/NzbDrone.Core/MediaFiles/MediaFileService.cs b/NzbDrone.Core/MediaFiles/MediaFileService.cs index 74a1f4ecd..e5810efe6 100644 --- a/NzbDrone.Core/MediaFiles/MediaFileService.cs +++ b/NzbDrone.Core/MediaFiles/MediaFileService.cs @@ -1,13 +1,9 @@ -using System; using System.Collections.Generic; using System.IO; -using System.Linq; using NLog; using NzbDrone.Common.Eventing; using NzbDrone.Core.Configuration; -using NzbDrone.Core.Qualities; using NzbDrone.Core.Tv; -using NzbDrone.Core.Helpers; using NzbDrone.Core.Tv.Events; namespace NzbDrone.Core.MediaFiles @@ -19,10 +15,8 @@ public interface IMediaFileService void Delete(int episodeFileId); bool Exists(string path); EpisodeFile GetFileByPath(string path); - IList GetFilesBySeries(int seriesId); - IList GetFilesBySeason(int seriesId, int seasonNumber); - FileInfo CalculateFilePath(Series series, int seasonNumber, string fileName, string extention); - string GetNewFilename(IList episodes, Series series, Quality quality, bool proper, EpisodeFile episodeFile); + List GetFilesBySeries(int seriesId); + List GetFilesBySeason(int seriesId, int seasonNumber); } public class MediaFileService : IMediaFileService, IHandleAsync @@ -73,25 +67,32 @@ public EpisodeFile GetFileByPath(string path) return _mediaFileRepository.GetFileByPath(path.Normalize()); } - public IList GetFilesBySeries(int seriesId) + public List GetFilesBySeries(int seriesId) { return _mediaFileRepository.GetFilesBySeries(seriesId); } - public IList GetFilesBySeason(int seriesId, int seasonNumber) + public List GetFilesBySeason(int seriesId, int seasonNumber) { return _mediaFileRepository.GetFilesBySeason(seriesId, seasonNumber); } + + public void HandleAsync(SeriesDeletedEvent message) + { + var files = GetFilesBySeries(message.Series.Id); + _mediaFileRepository.DeleteMany(files); + } + public FileInfo CalculateFilePath(Series series, int seasonNumber, string fileName, string extention) { string path = series.Path; if (series.SeasonFolder) { var seasonFolder = _configService.SortingSeasonFolderFormat - .Replace("%0s", seasonNumber.ToString("00")) - .Replace("%s", seasonNumber.ToString()); + .Replace("%0s", seasonNumber.ToString("00")) + .Replace("%s", seasonNumber.ToString()); path = Path.Combine(path, seasonFolder); } @@ -100,123 +101,5 @@ public FileInfo CalculateFilePath(Series series, int seasonNumber, string fileNa return new FileInfo(path); } - - - public string GetNewFilename(IList episodes, Series series, Quality quality, bool proper, EpisodeFile episodeFile) - { - if (_configService.SortingUseSceneName) - { - _logger.Trace("Attempting to use scene name"); - if (String.IsNullOrWhiteSpace(episodeFile.SceneName)) - { - var name = Path.GetFileNameWithoutExtension(episodeFile.Path); - _logger.Trace("Unable to use scene name, because it is null, sticking with current name: {0}", name); - - return name; - } - - return episodeFile.SceneName; - } - - var sortedEpisodes = episodes.OrderBy(e => e.EpisodeNumber); - - var separatorStyle = EpisodeSortingHelper.GetSeparatorStyle(_configService.SortingSeparatorStyle); - var numberStyle = EpisodeSortingHelper.GetNumberStyle(_configService.SortingNumberStyle); - - var episodeNames = new List(); - - episodeNames.Add(Parser.CleanupEpisodeTitle(sortedEpisodes.First().Title)); - - string result = String.Empty; - - if (_configService.SortingIncludeSeriesName) - { - result += series.Title + separatorStyle.Pattern; - } - - if (series.SeriesTypes == SeriesTypes.Standard) - { - result += numberStyle.Pattern.Replace("%0e", - String.Format("{0:00}", sortedEpisodes.First().EpisodeNumber)); - - if (episodes.Count > 1) - { - var multiEpisodeStyle = - EpisodeSortingHelper.GetMultiEpisodeStyle(_configService.SortingMultiEpisodeStyle); - - foreach (var episode in sortedEpisodes.Skip(1)) - { - if (multiEpisodeStyle.Name == "Duplicate") - { - result += separatorStyle.Pattern + numberStyle.Pattern; - } - else - { - result += multiEpisodeStyle.Pattern; - } - - result = result.Replace("%0e", String.Format("{0:00}", episode.EpisodeNumber)); - episodeNames.Add(Parser.CleanupEpisodeTitle(episode.Title)); - } - } - - result = result - .Replace("%s", String.Format("{0}", episodes.First().SeasonNumber)) - .Replace("%0s", String.Format("{0:00}", episodes.First().SeasonNumber)) - .Replace("%x", numberStyle.EpisodeSeparator) - .Replace("%p", separatorStyle.Pattern); - } - - else - { - if (episodes.First().AirDate.HasValue) - result += episodes.First().AirDate.Value.ToString("yyyy-MM-dd"); - - else - result += "Unknown"; - } - - if (_configService.SortingIncludeEpisodeTitle) - { - if (episodeNames.Distinct().Count() == 1) - result += separatorStyle.Pattern + episodeNames.First(); - - else - result += separatorStyle.Pattern + String.Join(" + ", episodeNames.Distinct()); - } - - if (_configService.SortingAppendQuality) - { - result += String.Format(" [{0}]", quality); - - if (proper) - result += " [Proper]"; - } - - if (_configService.SortingReplaceSpaces) - result = result.Replace(' ', '.'); - - _logger.Trace("New File Name is: [{0}]", result.Trim()); - return CleanFilename(result.Trim()); - } - - - public static string CleanFilename(string name) - { - string result = name; - string[] badCharacters = { "\\", "/", "<", ">", "?", "*", ":", "|", "\"" }; - string[] goodCharacters = { "+", "+", "{", "}", "!", "@", "-", "#", "`" }; - - for (int i = 0; i < badCharacters.Length; i++) - result = result.Replace(badCharacters[i], goodCharacters[i]); - - return result.Trim(); - } - - public void HandleAsync(SeriesDeletedEvent message) - { - var files = GetFilesBySeries(message.Series.Id); - _mediaFileRepository.DeleteMany(files); - } } } \ No newline at end of file diff --git a/NzbDrone.Core/Model/EpisodeParseResult.cs b/NzbDrone.Core/Model/EpisodeParseResult.cs index c5ef82160..827be127c 100644 --- a/NzbDrone.Core/Model/EpisodeParseResult.cs +++ b/NzbDrone.Core/Model/EpisodeParseResult.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Collections.Generic; using NzbDrone.Core.MediaFiles; +using NzbDrone.Core.Organizer; using NzbDrone.Core.Providers; using NzbDrone.Core.Tv; using NzbDrone.Core.Repository; @@ -77,7 +78,7 @@ public override string ToString() public string GetDownloadTitle() { - var seriesTitle = MediaFileService.CleanFilename(Series.Title); + var seriesTitle = FileNameBuilder.CleanFilename(Series.Title); //Handle Full Naming if (FullSeason) diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 37f23dff4..1bddb48eb 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -234,6 +234,7 @@ + diff --git a/NzbDrone.Core/Organizer/FileNameBuilder.cs b/NzbDrone.Core/Organizer/FileNameBuilder.cs new file mode 100644 index 000000000..6de2d3374 --- /dev/null +++ b/NzbDrone.Core/Organizer/FileNameBuilder.cs @@ -0,0 +1,207 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using NLog; +using NzbDrone.Core.Datastore; +using NzbDrone.Core.Helpers; +using NzbDrone.Core.MediaFiles; +using NzbDrone.Core.Qualities; +using NzbDrone.Core.Tv; + +namespace NzbDrone.Core.Organizer +{ + + public class NameSpecification : ModelBase + { + public static NameSpecification Default + { + get { return new NameSpecification(); } + } + + public bool SortingUseSceneName { get; set; } + + public int SortingSeparatorStyle { get; set; } + + public int SortingNumberStyle { get; set; } + + public bool SortingIncludeSeriesName { get; set; } + + public int SortingMultiEpisodeStyle { get; set; } + + public bool SortingIncludeEpisodeTitle { get; set; } + + public bool SortingAppendQuality { get; set; } + + public bool SortingReplaceSpaces { get; set; } + + public string SortingSeasonFolderFormat { 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); + } + + public class FileNameBuilder : IBuildFileNames + { + private readonly IBasicRepository _nameSpecificationRepository; + private readonly Logger _logger; + + public FileNameBuilder(IBasicRepository nameSpecificationRepository, Logger logger) + { + _nameSpecificationRepository = nameSpecificationRepository; + _logger = logger; + } + + + public NameSpecification GetSpecification() + { + var spec = _nameSpecificationRepository.SingleOrDefault(); + + if (spec == null) + { + spec = NameSpecification.Default; + } + + return spec; + + } + + public string GetNewFilename(IList episodes, Series series, Quality quality, bool proper, EpisodeFile episodeFile) + { + var nameSpec = GetSpecification(); + + + if (nameSpec.SortingUseSceneName) + { + _logger.Trace("Attempting to use scene name"); + if (String.IsNullOrWhiteSpace(episodeFile.SceneName)) + { + var name = Path.GetFileNameWithoutExtension(episodeFile.Path); + _logger.Trace("Unable to use scene name, because it is null, sticking with current name: {0}", name); + + return name; + } + + return episodeFile.SceneName; + } + + var sortedEpisodes = episodes.OrderBy(e => e.EpisodeNumber); + + var separatorStyle = EpisodeSortingHelper.GetSeparatorStyle(nameSpec.SortingSeparatorStyle); + var numberStyle = EpisodeSortingHelper.GetNumberStyle(nameSpec.SortingNumberStyle); + + var episodeNames = new List(); + + episodeNames.Add(Parser.CleanupEpisodeTitle(sortedEpisodes.First().Title)); + + string result = String.Empty; + + if (nameSpec.SortingIncludeSeriesName) + { + result += series.Title + separatorStyle.Pattern; + } + + if (series.SeriesTypes == SeriesTypes.Standard) + { + result += numberStyle.Pattern.Replace("%0e", + String.Format("{0:00}", sortedEpisodes.First().EpisodeNumber)); + + if (episodes.Count > 1) + { + var multiEpisodeStyle = + EpisodeSortingHelper.GetMultiEpisodeStyle(nameSpec.SortingMultiEpisodeStyle); + + foreach (var episode in sortedEpisodes.Skip(1)) + { + if (multiEpisodeStyle.Name == "Duplicate") + { + result += separatorStyle.Pattern + numberStyle.Pattern; + } + else + { + result += multiEpisodeStyle.Pattern; + } + + result = result.Replace("%0e", String.Format("{0:00}", episode.EpisodeNumber)); + episodeNames.Add(Parser.CleanupEpisodeTitle(episode.Title)); + } + } + + result = result + .Replace("%s", String.Format("{0}", episodes.First().SeasonNumber)) + .Replace("%0s", String.Format("{0:00}", episodes.First().SeasonNumber)) + .Replace("%x", numberStyle.EpisodeSeparator) + .Replace("%p", separatorStyle.Pattern); + } + + else + { + if (episodes.First().AirDate.HasValue) + result += episodes.First().AirDate.Value.ToString("yyyy-MM-dd"); + + else + result += "Unknown"; + } + + if (nameSpec.SortingIncludeEpisodeTitle) + { + if (episodeNames.Distinct().Count() == 1) + result += separatorStyle.Pattern + episodeNames.First(); + + else + result += separatorStyle.Pattern + String.Join(" + ", episodeNames.Distinct()); + } + + if (nameSpec.SortingAppendQuality) + { + result += String.Format(" [{0}]", quality); + + if (proper) + result += " [Proper]"; + } + + if (nameSpec.SortingReplaceSpaces) + 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) + { + + var nameSpec = GetSpecification(); + + string path = series.Path; + if (series.SeasonFolder) + { + var seasonFolder = nameSpec.SortingSeasonFolderFormat + .Replace("%0s", seasonNumber.ToString("00")) + .Replace("%s", seasonNumber.ToString()); + + path = Path.Combine(path, seasonFolder); + } + + path = Path.Combine(path, fileName + extension); + + return new FileInfo(path); + } + + + public static string CleanFilename(string name) + { + string result = name; + string[] badCharacters = { "\\", "/", "<", ">", "?", "*", ":", "|", "\"" }; + string[] goodCharacters = { "+", "+", "{", "}", "!", "@", "-", "#", "`" }; + + for (int i = 0; i < badCharacters.Length; i++) + result = result.Replace(badCharacters[i], goodCharacters[i]); + + return result.Trim(); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Providers/DiskScanProvider.cs b/NzbDrone.Core/Providers/DiskScanProvider.cs index 5508e56b7..523d82c4f 100644 --- a/NzbDrone.Core/Providers/DiskScanProvider.cs +++ b/NzbDrone.Core/Providers/DiskScanProvider.cs @@ -7,8 +7,8 @@ using NzbDrone.Common.Eventing; using NzbDrone.Core.Configuration; using NzbDrone.Core.Download; -using NzbDrone.Core.ExternalNotification; using NzbDrone.Core.MediaFiles; +using NzbDrone.Core.Organizer; using NzbDrone.Core.Tv; using NzbDrone.Core.Model; @@ -17,23 +17,25 @@ namespace NzbDrone.Core.Providers public class DiskScanProvider { private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - private static readonly string[] mediaExtentions = new[] { ".mkv", ".avi", ".wmv", ".mp4", ".mpg", ".mpeg", ".xvid", ".flv", ".mov", ".rm", ".rmvb", ".divx", ".dvr-ms", ".ts", ".ogm", ".m4v", ".strm" }; + private static readonly string[] MediaExtensions = new[] { ".mkv", ".avi", ".wmv", ".mp4", ".mpg", ".mpeg", ".xvid", ".flv", ".mov", ".rm", ".rmvb", ".divx", ".dvr-ms", ".ts", ".ogm", ".m4v", ".strm" }; private readonly DiskProvider _diskProvider; private readonly IEpisodeService _episodeService; private readonly IMediaFileService _mediaFileService; private readonly IConfigService _configService; + private readonly IBuildFileNames _buildFileNames; private readonly RecycleBinProvider _recycleBinProvider; private readonly MediaInfoProvider _mediaInfoProvider; private readonly ISeriesRepository _seriesRepository; private readonly IEventAggregator _eventAggregator; - public DiskScanProvider(DiskProvider diskProvider, IEpisodeService episodeService, IMediaFileService mediaFileService, IConfigService configService, + public DiskScanProvider(DiskProvider diskProvider, IEpisodeService episodeService, IMediaFileService mediaFileService, IConfigService configService,IBuildFileNames buildFileNames, RecycleBinProvider recycleBinProvider, MediaInfoProvider mediaInfoProvider, ISeriesRepository seriesRepository, IEventAggregator eventAggregator) { _diskProvider = diskProvider; _episodeService = episodeService; _mediaFileService = mediaFileService; _configService = configService; + _buildFileNames = buildFileNames; _recycleBinProvider = recycleBinProvider; _mediaInfoProvider = mediaInfoProvider; _seriesRepository = seriesRepository; @@ -186,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 = _mediaFileService.GetNewFilename(episodes, series, episodeFile.Quality, episodeFile.Proper, episodeFile); - var newFile = _mediaFileService.CalculateFilePath(series, episodes.First().SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path)); + string newFileName = _buildFileNames.GetNewFilename(episodes, series, episodeFile.Quality, episodeFile.Proper, episodeFile); + var newFile = _buildFileNames.CalculateFilePath(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)) @@ -308,7 +310,7 @@ public virtual List GetVideoFiles(string path, bool allDirectories = tru var searchOption = allDirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; var filesOnDisk = _diskProvider.GetFiles(path, searchOption); - var mediaFileList = filesOnDisk.Where(c => mediaExtentions.Contains(Path.GetExtension(c).ToLower())).ToList(); + var mediaFileList = filesOnDisk.Where(c => MediaExtensions.Contains(Path.GetExtension(c).ToLower())).ToList(); Logger.Trace("{0} video files were found in {1}", mediaFileList.Count, path); return mediaFileList; diff --git a/NzbDrone.Core/Providers/MisnamedProvider.cs b/NzbDrone.Core/Providers/MisnamedProvider.cs index d9dd17b7a..71033bf2d 100644 --- a/NzbDrone.Core/Providers/MisnamedProvider.cs +++ b/NzbDrone.Core/Providers/MisnamedProvider.cs @@ -5,7 +5,7 @@ using System.Text; using System.Diagnostics; using NLog; -using NzbDrone.Core.MediaFiles; +using NzbDrone.Core.Organizer; using NzbDrone.Core.Tv; using NzbDrone.Core.Model; using NzbDrone.Core.Repository; @@ -14,15 +14,15 @@ namespace NzbDrone.Core.Providers { public class MisnamedProvider { - private readonly IMediaFileService _mediaFileService; private readonly IEpisodeService _episodeService; + private readonly IBuildFileNames _buildFileNames; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public MisnamedProvider(IMediaFileService mediaFileService, IEpisodeService episodeService) + public MisnamedProvider(IEpisodeService episodeService, IBuildFileNames buildFileNames) { - _mediaFileService = mediaFileService; _episodeService = episodeService; + _buildFileNames = buildFileNames; } public virtual List MisnamedFiles(int pageNumber, int pageSize, out int totalItems) @@ -37,7 +37,7 @@ public virtual List MisnamedFiles(int pageNumber, int page var misnamedFilesSelect = episodesWithFiles.AsParallel().Where( w => w.First().EpisodeFile.Path != - _mediaFileService.GetNewFilename(w.Select(e => e).ToList(), w.First().Series, + _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); //Process the episodes @@ -45,7 +45,7 @@ public virtual List MisnamedFiles(int pageNumber, int page { var episodes = f.Select(e => e).ToList(); var firstEpisode = episodes[0]; - var properName = _mediaFileService.GetNewFilename(episodes, + var properName = _buildFileNames.GetNewFilename(episodes, firstEpisode.Series, firstEpisode.EpisodeFile.Quality, firstEpisode.EpisodeFile.Proper, firstEpisode.EpisodeFile);