From cbaa2f7ef42ced921675da14b55ebca8fa9afff5 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 5 Jun 2011 21:03:08 -0700 Subject: [PATCH] RenameProvider will return string for Multi-Episode files. --- NzbDrone.Core.Test/RenameProviderTest.cs | 385 ++++++++++++++++-- NzbDrone.Core/Helpers/EpisodeSortingHelper.cs | 21 +- NzbDrone.Core/Model/EpisodeSortingType.cs | 1 + NzbDrone.Core/Providers/RenameProvider.cs | 71 +++- 4 files changed, 434 insertions(+), 44 deletions(-) diff --git a/NzbDrone.Core.Test/RenameProviderTest.cs b/NzbDrone.Core.Test/RenameProviderTest.cs index 807e24a25..f82e09876 100644 --- a/NzbDrone.Core.Test/RenameProviderTest.cs +++ b/NzbDrone.Core.Test/RenameProviderTest.cs @@ -50,9 +50,6 @@ namespace NzbDrone.Core.Test .With(e => e.SeriesId = series.SeriesId) .Build(); - var fakeMediaFileProvider = mocker.GetMock(); - fakeMediaFileProvider.Setup(m => m.GetEpisodeFile(12345)).Returns(episodeFile); - var fakeEpisodeProvider = mocker.GetMock(); fakeEpisodeProvider.Setup(m => m.EpisodesByFileId(12345)).Returns(new List {episode}); @@ -60,7 +57,7 @@ namespace NzbDrone.Core.Test fakeSeriesProvider.Setup(m => m.GetSeries(series.SeriesId)).Returns(series); //Act - string result = mocker.Resolve().GetNewFilename(12345); + string result = mocker.Resolve().GetNewFilename(episodeFile); //Assert Assert.AreEqual("South Park - S15E06 - City Sushi [HDTV]", result); @@ -96,9 +93,6 @@ namespace NzbDrone.Core.Test .With(e => e.SeriesId = series.SeriesId) .Build(); - var fakeMediaFileProvider = mocker.GetMock(); - fakeMediaFileProvider.Setup(m => m.GetEpisodeFile(12345)).Returns(episodeFile); - var fakeEpisodeProvider = mocker.GetMock(); fakeEpisodeProvider.Setup(m => m.EpisodesByFileId(12345)).Returns(new List { episode }); @@ -106,7 +100,7 @@ namespace NzbDrone.Core.Test fakeSeriesProvider.Setup(m => m.GetSeries(series.SeriesId)).Returns(series); //Act - string result = mocker.Resolve().GetNewFilename(12345); + string result = mocker.Resolve().GetNewFilename(episodeFile); //Assert Assert.AreEqual("15x06 - City Sushi [HDTV]", result); @@ -142,9 +136,6 @@ namespace NzbDrone.Core.Test .With(e => e.SeriesId = series.SeriesId) .Build(); - var fakeMediaFileProvider = mocker.GetMock(); - fakeMediaFileProvider.Setup(m => m.GetEpisodeFile(12345)).Returns(episodeFile); - var fakeEpisodeProvider = mocker.GetMock(); fakeEpisodeProvider.Setup(m => m.EpisodesByFileId(12345)).Returns(new List { episode }); @@ -152,7 +143,7 @@ namespace NzbDrone.Core.Test fakeSeriesProvider.Setup(m => m.GetSeries(series.SeriesId)).Returns(series); //Act - string result = mocker.Resolve().GetNewFilename(12345); + string result = mocker.Resolve().GetNewFilename(episodeFile); //Assert Assert.AreEqual("South Park 05x06 [HDTV]", result); @@ -188,9 +179,6 @@ namespace NzbDrone.Core.Test .With(e => e.SeriesId = series.SeriesId) .Build(); - var fakeMediaFileProvider = mocker.GetMock(); - fakeMediaFileProvider.Setup(m => m.GetEpisodeFile(12345)).Returns(episodeFile); - var fakeEpisodeProvider = mocker.GetMock(); fakeEpisodeProvider.Setup(m => m.EpisodesByFileId(12345)).Returns(new List { episode }); @@ -198,7 +186,7 @@ namespace NzbDrone.Core.Test fakeSeriesProvider.Setup(m => m.GetSeries(series.SeriesId)).Returns(series); //Act - string result = mocker.Resolve().GetNewFilename(12345); + string result = mocker.Resolve().GetNewFilename(episodeFile); //Assert Assert.AreEqual("South Park s05e06", result); @@ -234,9 +222,6 @@ namespace NzbDrone.Core.Test .With(e => e.SeriesId = series.SeriesId) .Build(); - var fakeMediaFileProvider = mocker.GetMock(); - fakeMediaFileProvider.Setup(m => m.GetEpisodeFile(12345)).Returns(episodeFile); - var fakeEpisodeProvider = mocker.GetMock(); fakeEpisodeProvider.Setup(m => m.EpisodesByFileId(12345)).Returns(new List { episode }); @@ -244,7 +229,7 @@ namespace NzbDrone.Core.Test fakeSeriesProvider.Setup(m => m.GetSeries(series.SeriesId)).Returns(series); //Act - string result = mocker.Resolve().GetNewFilename(12345); + string result = mocker.Resolve().GetNewFilename(episodeFile); //Assert Assert.AreEqual("South.Park.s05e06.City.Sushi", result); @@ -280,8 +265,48 @@ namespace NzbDrone.Core.Test .With(e => e.SeriesId = series.SeriesId) .Build(); - var fakeMediaFileProvider = mocker.GetMock(); - fakeMediaFileProvider.Setup(m => m.GetEpisodeFile(12345)).Returns(episodeFile); + var fakeEpisodeProvider = mocker.GetMock(); + fakeEpisodeProvider.Setup(m => m.EpisodesByFileId(12345)).Returns(new List { episode }); + + var fakeSeriesProvider = mocker.GetMock(); + fakeSeriesProvider.Setup(m => m.GetSeries(series.SeriesId)).Returns(series); + + //Act + string result = mocker.Resolve().GetNewFilename(episodeFile); + + //Assert + Assert.AreEqual("South.Park.-.s05e06.-.City.Sushi.[HDTV]", result); + } + + [Test] + public void GetNewFilename_S01E05_Dash() + { + //Setup + var mocker = new AutoMoqer(); + + var fakeConfig = mocker.GetMock(); + fakeConfig.SetupGet(c => c.SeriesName).Returns(false); + fakeConfig.SetupGet(c => c.EpisodeName).Returns(false); + fakeConfig.SetupGet(c => c.AppendQuality).Returns(false); + fakeConfig.SetupGet(c => c.SeparatorStyle).Returns(0); + fakeConfig.SetupGet(c => c.NumberStyle).Returns(2); + fakeConfig.SetupGet(c => c.ReplaceSpaces).Returns(false); + + var series = Builder.CreateNew().With(s => s.Title = "South Park").Build(); + + var episodeFile = Builder.CreateNew() + .With(e => e.EpisodeFileId = 12345) + .With(e => e.SeriesId = series.SeriesId) + .With(e => e.Quality = QualityTypes.HDTV) + .Build(); + + var episode = Builder.CreateNew() + .With(e => e.EpisodeFileId = episodeFile.EpisodeFileId) + .With(e => e.Title = "City Sushi") + .With(e => e.SeasonNumber = 15) + .With(e => e.EpisodeNumber = 6) + .With(e => e.SeriesId = series.SeriesId) + .Build(); var fakeEpisodeProvider = mocker.GetMock(); fakeEpisodeProvider.Setup(m => m.EpisodesByFileId(12345)).Returns(new List { episode }); @@ -290,10 +315,322 @@ namespace NzbDrone.Core.Test fakeSeriesProvider.Setup(m => m.GetSeries(series.SeriesId)).Returns(series); //Act - string result = mocker.Resolve().GetNewFilename(12345); + string result = mocker.Resolve().GetNewFilename(episodeFile); //Assert - Assert.AreEqual("South.Park.-.s05e06.-.City.Sushi.[HDTV]", result); + Assert.AreEqual("S15E06", result); + } + + [Test] + public void GetNewFilename_multi_Series_Episode_Quality_S01E05_Scene_Dash() + { + //Setup + var mocker = new AutoMoqer(); + + var fakeConfig = mocker.GetMock(); + fakeConfig.SetupGet(c => c.SeriesName).Returns(true); + fakeConfig.SetupGet(c => c.EpisodeName).Returns(true); + fakeConfig.SetupGet(c => c.AppendQuality).Returns(true); + fakeConfig.SetupGet(c => c.SeparatorStyle).Returns(0); + fakeConfig.SetupGet(c => c.NumberStyle).Returns(2); + fakeConfig.SetupGet(c => c.ReplaceSpaces).Returns(false); + fakeConfig.SetupGet(c => c.MultiEpisodeStyle).Returns(3); + + var series = Builder.CreateNew().With(s => s.Title = "The Mentalist").Build(); + + var episodeFile = Builder.CreateNew() + .With(e => e.EpisodeFileId = 12345) + .With(e => e.SeriesId = series.SeriesId) + .With(e => e.Quality = QualityTypes.HDTV) + .Build(); + + var episodeOne = Builder.CreateNew() + .With(e => e.EpisodeFileId = episodeFile.EpisodeFileId) + .With(e => e.Title = "Strawberries and Cream (1)") + .With(e => e.SeasonNumber = 3) + .With(e => e.EpisodeNumber = 23) + .With(e => e.SeriesId = series.SeriesId) + .Build(); + + var episodeTwo = Builder.CreateNew() + .With(e => e.EpisodeFileId = episodeFile.EpisodeFileId) + .With(e => e.Title = "Strawberries and Cream (2)") + .With(e => e.SeasonNumber = 3) + .With(e => e.EpisodeNumber = 24) + .With(e => e.SeriesId = series.SeriesId) + .Build(); + + var fakeEpisodeProvider = mocker.GetMock(); + fakeEpisodeProvider.Setup(m => m.EpisodesByFileId(12345)).Returns(new List { episodeOne, episodeTwo }); + + var fakeSeriesProvider = mocker.GetMock(); + fakeSeriesProvider.Setup(m => m.GetSeries(series.SeriesId)).Returns(series); + + //Act + string result = mocker.Resolve().GetNewFilename(episodeFile); + + //Assert + Assert.AreEqual("The Mentalist - S03E23-E24 - Strawberries and Cream (1) + Strawberries and Cream (2) [HDTV]", result); + } + + [Test] + public void GetNewFilename_multi_Episode_Quality_1x05_Repeat_Dash() + { + //Setup + var mocker = new AutoMoqer(); + + var fakeConfig = mocker.GetMock(); + fakeConfig.SetupGet(c => c.SeriesName).Returns(false); + fakeConfig.SetupGet(c => c.EpisodeName).Returns(true); + fakeConfig.SetupGet(c => c.AppendQuality).Returns(true); + fakeConfig.SetupGet(c => c.SeparatorStyle).Returns(0); + fakeConfig.SetupGet(c => c.NumberStyle).Returns(0); + fakeConfig.SetupGet(c => c.ReplaceSpaces).Returns(false); + fakeConfig.SetupGet(c => c.MultiEpisodeStyle).Returns(2); + + var series = Builder.CreateNew().With(s => s.Title = "The Mentalist").Build(); + + var episodeFile = Builder.CreateNew() + .With(e => e.EpisodeFileId = 12345) + .With(e => e.SeriesId = series.SeriesId) + .With(e => e.Quality = QualityTypes.HDTV) + .Build(); + + var episodeOne = Builder.CreateNew() + .With(e => e.EpisodeFileId = episodeFile.EpisodeFileId) + .With(e => e.Title = "Strawberries and Cream (1)") + .With(e => e.SeasonNumber = 3) + .With(e => e.EpisodeNumber = 23) + .With(e => e.SeriesId = series.SeriesId) + .Build(); + + var episodeTwo = Builder.CreateNew() + .With(e => e.EpisodeFileId = episodeFile.EpisodeFileId) + .With(e => e.Title = "Strawberries and Cream (2)") + .With(e => e.SeasonNumber = 3) + .With(e => e.EpisodeNumber = 24) + .With(e => e.SeriesId = series.SeriesId) + .Build(); + + var fakeEpisodeProvider = mocker.GetMock(); + fakeEpisodeProvider.Setup(m => m.EpisodesByFileId(12345)).Returns(new List { episodeOne, episodeTwo }); + + var fakeSeriesProvider = mocker.GetMock(); + fakeSeriesProvider.Setup(m => m.GetSeries(series.SeriesId)).Returns(series); + + //Act + string result = mocker.Resolve().GetNewFilename(episodeFile); + + //Assert + Assert.AreEqual("3x23x24 - Strawberries and Cream (1) + Strawberries and Cream (2) [HDTV]", result); + } + + [Test] + public void GetNewFilename_multi_Episode_Quality_01x05_Repeat_Space() + { + //Setup + var mocker = new AutoMoqer(); + + var fakeConfig = mocker.GetMock(); + fakeConfig.SetupGet(c => c.SeriesName).Returns(false); + fakeConfig.SetupGet(c => c.EpisodeName).Returns(true); + fakeConfig.SetupGet(c => c.AppendQuality).Returns(true); + fakeConfig.SetupGet(c => c.SeparatorStyle).Returns(1); + fakeConfig.SetupGet(c => c.NumberStyle).Returns(0); + fakeConfig.SetupGet(c => c.ReplaceSpaces).Returns(false); + fakeConfig.SetupGet(c => c.MultiEpisodeStyle).Returns(2); + + var series = Builder.CreateNew().With(s => s.Title = "The Mentalist").Build(); + + var episodeFile = Builder.CreateNew() + .With(e => e.EpisodeFileId = 12345) + .With(e => e.SeriesId = series.SeriesId) + .With(e => e.Quality = QualityTypes.HDTV) + .Build(); + + var episodeOne = Builder.CreateNew() + .With(e => e.EpisodeFileId = episodeFile.EpisodeFileId) + .With(e => e.Title = "Strawberries and Cream (1)") + .With(e => e.SeasonNumber = 3) + .With(e => e.EpisodeNumber = 23) + .With(e => e.SeriesId = series.SeriesId) + .Build(); + + var episodeTwo = Builder.CreateNew() + .With(e => e.EpisodeFileId = episodeFile.EpisodeFileId) + .With(e => e.Title = "Strawberries and Cream (2)") + .With(e => e.SeasonNumber = 3) + .With(e => e.EpisodeNumber = 24) + .With(e => e.SeriesId = series.SeriesId) + .Build(); + + var fakeEpisodeProvider = mocker.GetMock(); + fakeEpisodeProvider.Setup(m => m.EpisodesByFileId(12345)).Returns(new List { episodeOne, episodeTwo }); + + var fakeSeriesProvider = mocker.GetMock(); + fakeSeriesProvider.Setup(m => m.GetSeries(series.SeriesId)).Returns(series); + + //Act + string result = mocker.Resolve().GetNewFilename(episodeFile); + + //Assert + Assert.AreEqual("3x23x24 Strawberries and Cream (1) + Strawberries and Cream (2) [HDTV]", result); + } + + [Test] + public void GetNewFilename_multi_Series_Episode_s01e05_Duplicate_Period() + { + //Setup + var mocker = new AutoMoqer(); + + var fakeConfig = mocker.GetMock(); + fakeConfig.SetupGet(c => c.SeriesName).Returns(true); + fakeConfig.SetupGet(c => c.EpisodeName).Returns(true); + fakeConfig.SetupGet(c => c.AppendQuality).Returns(false); + fakeConfig.SetupGet(c => c.SeparatorStyle).Returns(1); + fakeConfig.SetupGet(c => c.NumberStyle).Returns(3); + fakeConfig.SetupGet(c => c.ReplaceSpaces).Returns(true); + fakeConfig.SetupGet(c => c.MultiEpisodeStyle).Returns(1); + + var series = Builder.CreateNew().With(s => s.Title = "The Mentalist").Build(); + + var episodeFile = Builder.CreateNew() + .With(e => e.EpisodeFileId = 12345) + .With(e => e.SeriesId = series.SeriesId) + .With(e => e.Quality = QualityTypes.HDTV) + .Build(); + + var episodeOne = Builder.CreateNew() + .With(e => e.EpisodeFileId = episodeFile.EpisodeFileId) + .With(e => e.Title = "Strawberries and Cream (1)") + .With(e => e.SeasonNumber = 3) + .With(e => e.EpisodeNumber = 23) + .With(e => e.SeriesId = series.SeriesId) + .Build(); + + var episodeTwo = Builder.CreateNew() + .With(e => e.EpisodeFileId = episodeFile.EpisodeFileId) + .With(e => e.Title = "Strawberries and Cream (2)") + .With(e => e.SeasonNumber = 3) + .With(e => e.EpisodeNumber = 24) + .With(e => e.SeriesId = series.SeriesId) + .Build(); + + var fakeEpisodeProvider = mocker.GetMock(); + fakeEpisodeProvider.Setup(m => m.EpisodesByFileId(12345)).Returns(new List { episodeOne, episodeTwo }); + + var fakeSeriesProvider = mocker.GetMock(); + fakeSeriesProvider.Setup(m => m.GetSeries(series.SeriesId)).Returns(series); + + //Act + string result = mocker.Resolve().GetNewFilename(episodeFile); + + //Assert + Assert.AreEqual("The.Mentalist.s03e23.s03e24.Strawberries.and.Cream.(1).+.Strawberries.and.Cream.(2)", result); + } + + [Test] + public void GetNewFilename_multi_Series_S01E05_Extend_Dash_Period() + { + //Setup + var mocker = new AutoMoqer(); + + var fakeConfig = mocker.GetMock(); + fakeConfig.SetupGet(c => c.SeriesName).Returns(true); + fakeConfig.SetupGet(c => c.EpisodeName).Returns(false); + fakeConfig.SetupGet(c => c.AppendQuality).Returns(false); + fakeConfig.SetupGet(c => c.SeparatorStyle).Returns(0); + fakeConfig.SetupGet(c => c.NumberStyle).Returns(2); + fakeConfig.SetupGet(c => c.ReplaceSpaces).Returns(true); + fakeConfig.SetupGet(c => c.MultiEpisodeStyle).Returns(0); + + var series = Builder.CreateNew().With(s => s.Title = "The Mentalist").Build(); + + var episodeFile = Builder.CreateNew() + .With(e => e.EpisodeFileId = 12345) + .With(e => e.SeriesId = series.SeriesId) + .With(e => e.Quality = QualityTypes.HDTV) + .Build(); + + var episodeOne = Builder.CreateNew() + .With(e => e.EpisodeFileId = episodeFile.EpisodeFileId) + .With(e => e.Title = "Strawberries and Cream (1)") + .With(e => e.SeasonNumber = 3) + .With(e => e.EpisodeNumber = 23) + .With(e => e.SeriesId = series.SeriesId) + .Build(); + + var episodeTwo = Builder.CreateNew() + .With(e => e.EpisodeFileId = episodeFile.EpisodeFileId) + .With(e => e.Title = "Strawberries and Cream (2)") + .With(e => e.SeasonNumber = 3) + .With(e => e.EpisodeNumber = 24) + .With(e => e.SeriesId = series.SeriesId) + .Build(); + + var fakeEpisodeProvider = mocker.GetMock(); + fakeEpisodeProvider.Setup(m => m.EpisodesByFileId(12345)).Returns(new List { episodeOne, episodeTwo }); + + var fakeSeriesProvider = mocker.GetMock(); + fakeSeriesProvider.Setup(m => m.GetSeries(series.SeriesId)).Returns(series); + + //Act + string result = mocker.Resolve().GetNewFilename(episodeFile); + + //Assert + Assert.AreEqual("The.Mentalist.-.S03E23-24", result); + } + + [Test] + public void GetNewFilename_multi_1x05_Repeat_Dash_Period() + { + //Setup + var mocker = new AutoMoqer(); + + var fakeConfig = mocker.GetMock(); + fakeConfig.SetupGet(c => c.SeriesName).Returns(false); + fakeConfig.SetupGet(c => c.EpisodeName).Returns(false); + fakeConfig.SetupGet(c => c.AppendQuality).Returns(false); + fakeConfig.SetupGet(c => c.SeparatorStyle).Returns(0); + fakeConfig.SetupGet(c => c.NumberStyle).Returns(0); + fakeConfig.SetupGet(c => c.ReplaceSpaces).Returns(true); + fakeConfig.SetupGet(c => c.MultiEpisodeStyle).Returns(2); + + var series = Builder.CreateNew().With(s => s.Title = "The Mentalist").Build(); + + var episodeFile = Builder.CreateNew() + .With(e => e.EpisodeFileId = 12345) + .With(e => e.SeriesId = series.SeriesId) + .With(e => e.Quality = QualityTypes.HDTV) + .Build(); + + var episodeOne = Builder.CreateNew() + .With(e => e.EpisodeFileId = episodeFile.EpisodeFileId) + .With(e => e.Title = "Strawberries and Cream (1)") + .With(e => e.SeasonNumber = 3) + .With(e => e.EpisodeNumber = 23) + .With(e => e.SeriesId = series.SeriesId) + .Build(); + + var episodeTwo = Builder.CreateNew() + .With(e => e.EpisodeFileId = episodeFile.EpisodeFileId) + .With(e => e.Title = "Strawberries and Cream (2)") + .With(e => e.SeasonNumber = 3) + .With(e => e.EpisodeNumber = 24) + .With(e => e.SeriesId = series.SeriesId) + .Build(); + + var fakeEpisodeProvider = mocker.GetMock(); + fakeEpisodeProvider.Setup(m => m.EpisodesByFileId(12345)).Returns(new List { episodeOne, episodeTwo }); + + var fakeSeriesProvider = mocker.GetMock(); + fakeSeriesProvider.Setup(m => m.GetSeries(series.SeriesId)).Returns(series); + + //Act + string result = mocker.Resolve().GetNewFilename(episodeFile); + + //Assert + Assert.AreEqual("3x23x24", result); } } } \ No newline at end of file diff --git a/NzbDrone.Core/Helpers/EpisodeSortingHelper.cs b/NzbDrone.Core/Helpers/EpisodeSortingHelper.cs index 97881eeaf..d0c270764 100644 --- a/NzbDrone.Core/Helpers/EpisodeSortingHelper.cs +++ b/NzbDrone.Core/Helpers/EpisodeSortingHelper.cs @@ -28,25 +28,30 @@ namespace NzbDrone.Core.Helpers { Id = 0, Name = "1x05", - Pattern = "%sx%0e" + Pattern = "%sx%0e", + EpisodeSeparator = "x" + }, new EpisodeSortingType { Id = 1, Name = "01x05", - Pattern = "%0sx%0e" + Pattern = "%0sx%0e", + EpisodeSeparator = "x" }, new EpisodeSortingType { Id = 2, Name = "S01E05", - Pattern = "S%0sE%0e" + Pattern = "S%0sE%0e", + EpisodeSeparator = "E" }, new EpisodeSortingType { Id = 3, Name = "s01e05", - Pattern = "s%0se%0e" + Pattern = "s%0se%0e", + EpisodeSeparator = "e" } }; @@ -56,25 +61,25 @@ namespace NzbDrone.Core.Helpers { Id = 0, Name = "Extend", - Pattern = "S01E05-06" + Pattern = "-%0e" }, new EpisodeSortingType { Id = 1, Name = "Duplicate", - Pattern = "S01E05 - S01E06" + Pattern = "%p%0s%x%0e" }, new EpisodeSortingType { Id = 2, Name = "Repeat", - Pattern = "S01E05E06" + Pattern = "%x%0e" }, new EpisodeSortingType { Id = 3, Name = "Scene", - Pattern = "S01E05-E06" + Pattern = "-%x%0e" } }; diff --git a/NzbDrone.Core/Model/EpisodeSortingType.cs b/NzbDrone.Core/Model/EpisodeSortingType.cs index b162428e6..1bb23bdf5 100644 --- a/NzbDrone.Core/Model/EpisodeSortingType.cs +++ b/NzbDrone.Core/Model/EpisodeSortingType.cs @@ -5,5 +5,6 @@ public int Id { get; set; } public string Name { get; set; } public string Pattern { get; set; } + public string EpisodeSeparator { get; set; } } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/RenameProvider.cs b/NzbDrone.Core/Providers/RenameProvider.cs index 51bc6a1ca..370e32a5c 100644 --- a/NzbDrone.Core/Providers/RenameProvider.cs +++ b/NzbDrone.Core/Providers/RenameProvider.cs @@ -7,6 +7,7 @@ using NLog; using NzbDrone.Core.Helpers; using NzbDrone.Core.Model; using NzbDrone.Core.Providers.Core; +using NzbDrone.Core.Repository; namespace NzbDrone.Core.Providers { @@ -186,13 +187,9 @@ namespace NzbDrone.Core.Providers } } - public string GetNewFilename(int episodeFileId) + public string GetNewFilename(EpisodeFile episodeFile) { - //Get all episodes attached to the episodeFileId - //Get the users preferred naming convention for episode - - var episodeFile = _mediaFileProvider.GetEpisodeFile(episodeFileId); - var episodes = _episodeProvider.EpisodesByFileId(episodeFileId); + var episodes = _episodeProvider.EpisodesByFileId(episodeFile.EpisodeFileId); var series = _seriesProvider.GetSeries(episodeFile.SeriesId); var separatorStyle = EpisodeSortingHelper.GetSeparatorStyle(_configProvider.SeparatorStyle); @@ -202,21 +199,19 @@ namespace NzbDrone.Core.Providers var replaceSpaces = _configProvider.ReplaceSpaces; var appendQuality = _configProvider.AppendQuality; + var title = String.Empty; + if (episodes.Count == 1) { - var title = String.Empty; - if (useSeriesName) { title += series.Title; title += separatorStyle.Pattern; } - var number = numberStyle.Pattern.Replace("%s", String.Format("{0}", episodes[0].SeasonNumber)) + title += numberStyle.Pattern.Replace("%s", String.Format("{0}", episodes[0].SeasonNumber)) .Replace("%0s", String.Format("{0:00}", episodes[0].SeasonNumber)) .Replace("%0e", String.Format("{0:00}", episodes[0].EpisodeNumber)); - - title += number; if (useEpisodeName) { @@ -236,7 +231,59 @@ namespace NzbDrone.Core.Providers var multiEpisodeStyle = EpisodeSortingHelper.GetMultiEpisodeStyle(_configProvider.MultiEpisodeStyle); - return String.Empty; + if (useSeriesName) + { + title += series.Title; + title += separatorStyle.Pattern; + } + + title += numberStyle.Pattern.Replace("%s", String.Format("{0}", episodes[0].SeasonNumber)) + .Replace("%0s", String.Format("{0:00}", episodes[0].SeasonNumber)) + .Replace("%0e", String.Format("{0:00}", episodes[0].EpisodeNumber)); + + var numbers = String.Empty; + var episodeNames = episodes[0].Title; + + for (int i = 1; i < episodes.Count; i++) + { + var episode = episodes[i]; + + if (multiEpisodeStyle.Name == "Duplicate") + { + numbers += separatorStyle.Pattern + numberStyle.Pattern.Replace("%s", String.Format("{0}", episode.SeasonNumber)) + .Replace("%0s", String.Format("{0:00}", episode.SeasonNumber)) + .Replace("%0e", String.Format("{0:00}", episode.EpisodeNumber)); + } + else + { + numbers += multiEpisodeStyle.Pattern.Replace("%s", String.Format("{0}", episode.SeasonNumber)) + .Replace("%0s", String.Format("{0:00}", episode.SeasonNumber)) + .Replace("%0e", String.Format("{0:00}", episode.EpisodeNumber)) + .Replace("%x", numberStyle.EpisodeSeparator) + .Replace("%p", separatorStyle.Pattern); + } + + episodeNames += String.Format(" + {0}", episode.Title); + } + + title += numbers; + + if (useEpisodeName) + { + episodeNames = episodeNames.TrimEnd(' ', '+'); + + title += separatorStyle.Pattern; + title += episodeNames; + } + + if (appendQuality) + title += String.Format(" [{0}]", episodeFile.Quality); + + if (replaceSpaces) + title = title.Replace(' ', '.'); + + Logger.Debug("New File Name is: {0}", title); + return title; } } } \ No newline at end of file