diff --git a/NzbDrone.Core.Test/OrganizerTests/GetNewFilenameFixture.cs b/NzbDrone.Core.Test/OrganizerTests/GetNewFilenameFixture.cs index 52e9975f9..0e810bc87 100644 --- a/NzbDrone.Core.Test/OrganizerTests/GetNewFilenameFixture.cs +++ b/NzbDrone.Core.Test/OrganizerTests/GetNewFilenameFixture.cs @@ -51,7 +51,7 @@ public void GetNewFilename_Series_Episode_Quality_S01E05_Dash() nameSpecification.IncludeSeriesName = true; nameSpecification.IncludeEpisodeTitle = true; nameSpecification.AppendQuality = true; - nameSpecification.SeparatorStyle = 0; + nameSpecification.Separator = " - "; nameSpecification.NumberStyle = 2; nameSpecification.ReplaceSpaces = false; @@ -78,7 +78,7 @@ public void GetNewFilename_Episode_Quality_1x05_Dash() nameSpecification.IncludeSeriesName = false; nameSpecification.IncludeEpisodeTitle = true; nameSpecification.AppendQuality = true; - nameSpecification.SeparatorStyle = 0; + nameSpecification.Separator = " - "; nameSpecification.NumberStyle = 0; nameSpecification.ReplaceSpaces = false; @@ -105,7 +105,7 @@ public void GetNewFilename_Series_Quality_01x05_Space() nameSpecification.IncludeSeriesName = true; nameSpecification.IncludeEpisodeTitle = false; nameSpecification.AppendQuality = true; - nameSpecification.SeparatorStyle = 1; + nameSpecification.Separator = " "; nameSpecification.NumberStyle = 1; nameSpecification.ReplaceSpaces = false; @@ -132,7 +132,7 @@ public void GetNewFilename_Series_s01e05_Space() nameSpecification.IncludeSeriesName = true; nameSpecification.IncludeEpisodeTitle = false; nameSpecification.AppendQuality = false; - nameSpecification.SeparatorStyle = 1; + nameSpecification.Separator = " "; nameSpecification.NumberStyle = 3; nameSpecification.ReplaceSpaces = false; @@ -160,7 +160,7 @@ public void GetNewFilename_Series_Episode_s01e05_Periods() nameSpecification.IncludeSeriesName = true; nameSpecification.IncludeEpisodeTitle = true; nameSpecification.AppendQuality = false; - nameSpecification.SeparatorStyle = 1; + nameSpecification.Separator = " "; nameSpecification.NumberStyle = 3; nameSpecification.ReplaceSpaces = true; @@ -187,7 +187,7 @@ public void GetNewFilename_Series_Episode_s01e05_Dash_Periods_Quality() nameSpecification.IncludeSeriesName = true; nameSpecification.IncludeEpisodeTitle = true; nameSpecification.AppendQuality = true; - nameSpecification.SeparatorStyle = 0; + nameSpecification.Separator = " - "; nameSpecification.NumberStyle = 3; nameSpecification.ReplaceSpaces = true; @@ -214,7 +214,7 @@ public void GetNewFilename_S01E05_Dash() nameSpecification.IncludeSeriesName = false; nameSpecification.IncludeEpisodeTitle = false; nameSpecification.AppendQuality = false; - nameSpecification.SeparatorStyle = 0; + nameSpecification.Separator = " - "; nameSpecification.NumberStyle = 2; nameSpecification.ReplaceSpaces = false; @@ -242,7 +242,7 @@ public void GetNewFilename_multi_Series_Episode_Quality_S01E05_Scene_Dash() nameSpecification.IncludeSeriesName = true; nameSpecification.IncludeEpisodeTitle = true; nameSpecification.AppendQuality = true; - nameSpecification.SeparatorStyle = 0; + nameSpecification.Separator = " - "; nameSpecification.NumberStyle = 2; nameSpecification.ReplaceSpaces = false; nameSpecification.MultiEpisodeStyle = 3; @@ -276,7 +276,7 @@ public void GetNewFilename_multi_Episode_Quality_1x05_Repeat_Dash() nameSpecification.IncludeSeriesName = false; nameSpecification.IncludeEpisodeTitle = true; nameSpecification.AppendQuality = true; - nameSpecification.SeparatorStyle = 0; + nameSpecification.Separator = " - "; nameSpecification.NumberStyle = 0; nameSpecification.ReplaceSpaces = false; nameSpecification.MultiEpisodeStyle = 2; @@ -310,7 +310,7 @@ public void GetNewFilename_multi_Episode_Quality_01x05_Repeat_Space() nameSpecification.IncludeSeriesName = false; nameSpecification.IncludeEpisodeTitle = true; nameSpecification.AppendQuality = true; - nameSpecification.SeparatorStyle = 1; + nameSpecification.Separator = " "; nameSpecification.NumberStyle = 0; nameSpecification.ReplaceSpaces = false; nameSpecification.MultiEpisodeStyle = 2; @@ -344,7 +344,7 @@ public void GetNewFilename_multi_Series_Episode_s01e05_Duplicate_Period() nameSpecification.IncludeSeriesName = true; nameSpecification.IncludeEpisodeTitle = true; nameSpecification.AppendQuality = false; - nameSpecification.SeparatorStyle = 1; + nameSpecification.Separator = " "; nameSpecification.NumberStyle = 3; nameSpecification.ReplaceSpaces = true; nameSpecification.MultiEpisodeStyle = 1; @@ -378,7 +378,7 @@ public void GetNewFilename_multi_Series_S01E05_Extend_Dash_Period() nameSpecification.IncludeSeriesName = true; nameSpecification.IncludeEpisodeTitle = false; nameSpecification.AppendQuality = false; - nameSpecification.SeparatorStyle = 0; + nameSpecification.Separator = " - "; nameSpecification.NumberStyle = 2; nameSpecification.ReplaceSpaces = true; nameSpecification.MultiEpisodeStyle = 0; @@ -412,7 +412,7 @@ public void GetNewFilename_multi_1x05_Repeat_Dash_Period() nameSpecification.IncludeSeriesName = false; nameSpecification.IncludeEpisodeTitle = false; nameSpecification.AppendQuality = false; - nameSpecification.SeparatorStyle = 0; + nameSpecification.Separator = " - "; nameSpecification.NumberStyle = 0; nameSpecification.ReplaceSpaces = true; nameSpecification.MultiEpisodeStyle = 2; @@ -444,7 +444,7 @@ public void GetNewFilename_should_append_proper_when_proper_and_append_quality_i nameSpecification.IncludeSeriesName = true; nameSpecification.IncludeEpisodeTitle = true; nameSpecification.AppendQuality = true; - nameSpecification.SeparatorStyle = 0; + nameSpecification.Separator = " - "; nameSpecification.NumberStyle = 2; nameSpecification.ReplaceSpaces = false; @@ -469,7 +469,7 @@ public void GetNewFilename_should_not_append_proper_when_not_proper_and_append_q nameSpecification.IncludeSeriesName = true; nameSpecification.IncludeEpisodeTitle = true; nameSpecification.AppendQuality = true; - nameSpecification.SeparatorStyle = 0; + nameSpecification.Separator = " - "; nameSpecification.NumberStyle = 2; nameSpecification.ReplaceSpaces = false; @@ -494,7 +494,7 @@ public void GetNewFilename_should_not_append_proper_when_proper_and_append_quali nameSpecification.IncludeSeriesName = true; nameSpecification.IncludeEpisodeTitle = true; nameSpecification.AppendQuality = false; - nameSpecification.SeparatorStyle = 0; + nameSpecification.Separator = " - "; nameSpecification.NumberStyle = 2; nameSpecification.ReplaceSpaces = false; @@ -519,7 +519,7 @@ public void GetNewFilename_should_order_multiple_episode_files_in_numerical_orde nameSpecification.IncludeSeriesName = true; nameSpecification.IncludeEpisodeTitle = true; nameSpecification.AppendQuality = false; - nameSpecification.SeparatorStyle = 0; + nameSpecification.Separator = " - "; nameSpecification.NumberStyle = 2; nameSpecification.ReplaceSpaces = false; nameSpecification.MultiEpisodeStyle = 3; @@ -553,7 +553,7 @@ public void GetNewFilename_Series_Episode_Quality_S01E05_Period() nameSpecification.IncludeSeriesName = true; nameSpecification.IncludeEpisodeTitle = true; nameSpecification.AppendQuality = true; - nameSpecification.SeparatorStyle = 2; + nameSpecification.Separator = "."; nameSpecification.NumberStyle = 2; nameSpecification.ReplaceSpaces = false; @@ -580,7 +580,7 @@ public void GetNewFilename_Episode_Quality_1x05_Period() nameSpecification.IncludeSeriesName = false; nameSpecification.IncludeEpisodeTitle = true; nameSpecification.AppendQuality = true; - nameSpecification.SeparatorStyle = 2; + nameSpecification.Separator = "."; ; nameSpecification.NumberStyle = 0; nameSpecification.ReplaceSpaces = false; @@ -605,7 +605,7 @@ public void GetNewFilename_UseSceneName_when_sceneName_isNull() nameSpecification.IncludeSeriesName = false; nameSpecification.IncludeEpisodeTitle = true; nameSpecification.AppendQuality = true; - nameSpecification.SeparatorStyle = 2; + nameSpecification.Separator = "."; ; nameSpecification.NumberStyle = 0; nameSpecification.ReplaceSpaces = false; nameSpecification.UseSceneName = true; @@ -636,7 +636,7 @@ public void GetNewFilename_UseSceneName_when_sceneName_isNotNull() nameSpecification.IncludeSeriesName = false; nameSpecification.IncludeEpisodeTitle = true; nameSpecification.AppendQuality = true; - nameSpecification.SeparatorStyle = 2; + nameSpecification.Separator = "."; nameSpecification.NumberStyle = 0; nameSpecification.ReplaceSpaces = false; nameSpecification.UseSceneName = true; @@ -667,7 +667,7 @@ public void should_only_have_one_episodeTitle_when_episode_titles_are_the_same() nameSpecification.IncludeSeriesName = true; nameSpecification.IncludeEpisodeTitle = true; nameSpecification.AppendQuality = false; - nameSpecification.SeparatorStyle = 0; + nameSpecification.Separator = " - "; nameSpecification.NumberStyle = 2; nameSpecification.ReplaceSpaces = false; nameSpecification.MultiEpisodeStyle = 3; @@ -699,7 +699,7 @@ public void should_have_two_episodeTitles_when_episode_titles_are_not_the_same() nameSpecification.IncludeSeriesName = true; nameSpecification.IncludeEpisodeTitle = true; nameSpecification.AppendQuality = false; - nameSpecification.SeparatorStyle = 0; + nameSpecification.Separator = " - "; nameSpecification.NumberStyle = 2; nameSpecification.ReplaceSpaces = false; nameSpecification.MultiEpisodeStyle = 3; @@ -731,7 +731,7 @@ public void should_have_two_episodeTitles_when_distinct_count_is_two() nameSpecification.IncludeSeriesName = true; nameSpecification.IncludeEpisodeTitle = true; nameSpecification.AppendQuality = false; - nameSpecification.SeparatorStyle = 0; + nameSpecification.Separator = " - "; nameSpecification.NumberStyle = 2; nameSpecification.ReplaceSpaces = false; nameSpecification.MultiEpisodeStyle = 3; @@ -768,7 +768,7 @@ public void should_use_airDate_if_series_isDaily() nameSpecification.IncludeSeriesName = true; nameSpecification.IncludeEpisodeTitle = true; nameSpecification.AppendQuality = true; - nameSpecification.SeparatorStyle = 0; + nameSpecification.Separator = " - "; nameSpecification.NumberStyle = 2; nameSpecification.ReplaceSpaces = false; @@ -797,7 +797,7 @@ public void should_use_airDate_if_series_isDaily_no_episode_title() nameSpecification.IncludeSeriesName = true; nameSpecification.IncludeEpisodeTitle = false; nameSpecification.AppendQuality = false; - nameSpecification.SeparatorStyle = 0; + nameSpecification.Separator = " - "; nameSpecification.NumberStyle = 2; nameSpecification.ReplaceSpaces = false; @@ -826,7 +826,7 @@ public void should_set_airdate_to_unknown_if_not_available() nameSpecification.IncludeSeriesName = true; nameSpecification.IncludeEpisodeTitle = true; nameSpecification.AppendQuality = false; - nameSpecification.SeparatorStyle = 0; + nameSpecification.Separator = " - "; nameSpecification.NumberStyle = 2; nameSpecification.ReplaceSpaces = false; diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpDropFolderFixture.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpDropFolderFixture.cs index d4fa3ddce..01413dc33 100644 --- a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpDropFolderFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpDropFolderFixture.cs @@ -111,7 +111,7 @@ public void should_move_file_if_a_conflict_is_found() .Returns(newFilename); Mocker.GetMock().Setup(s => s.BuildFilePath(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) - .Returns(new FileInfo(newFilePath)); + .Returns(newFilePath); Mocker.GetMock() .Setup(s => s.FileExists(filename)) diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/MoveEpisodeFileFixture.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/MoveEpisodeFileFixture.cs index 7d4ad806e..b65bbd6bb 100644 --- a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/MoveEpisodeFileFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/MoveEpisodeFileFixture.cs @@ -42,11 +42,11 @@ public void should_not_move_file_if_source_and_destination_are_the_same_path() .Build().ToList(); const string filename = @"30 Rock - S01E01 - TBD"; - var fi = new FileInfo(Path.Combine(@"C:\Test\TV\30 Rock\Season 01\", filename + ".avi")); + var fi = Path.Combine(@"C:\Test\TV\30 Rock\Season 01\", filename + ".avi"); var file = Builder.CreateNew() .With(f => f.SeriesId = fakeSeries.Id) - .With(f => f.Path = fi.FullName) + .With(f => f.Path = fi) .Build(); Mocker.GetMock() @@ -88,7 +88,7 @@ public void should_use_EpisodeFiles_quality() .Build().ToList(); const string filename = @"30 Rock - S01E01 - TBD"; - var fi = new FileInfo(Path.Combine(@"C:\Test\TV\30 Rock\Season 01\", filename + ".mkv")); + var fi = Path.Combine(@"C:\Test\TV\30 Rock\Season 01\", filename + ".mkv"); var currentFilename = Path.Combine(@"C:\Test\TV\30 Rock\Season 01\", "30.Rock.S01E01.Test.WED-DL.mkv"); const string message = "30 Rock - 1x01 - [WEBDL]"; @@ -140,7 +140,7 @@ public void should_log_error_and_return_null_when_source_file_does_not_exists() .Build().ToList(); const string filename = @"30 Rock - S01E01 - TBD"; - var fi = new FileInfo(Path.Combine(@"C:\Test\TV\30 Rock\Season 01\", filename + ".mkv")); + var fi = Path.Combine(@"C:\Test\TV\30 Rock\Season 01\", filename + ".mkv"); var currentFilename = Path.Combine(@"C:\Test\TV\30 Rock\Season 01\", "30.Rock.S01E01.Test.WED-DL.mkv"); const string message = "30 Rock - 1x01 - [WEBDL]"; diff --git a/NzbDrone.Core/Helpers/EpisodeSortingHelper.cs b/NzbDrone.Core/Helpers/EpisodeSortingHelper.cs deleted file mode 100644 index 35cdcc5f2..000000000 --- a/NzbDrone.Core/Helpers/EpisodeSortingHelper.cs +++ /dev/null @@ -1,137 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using NzbDrone.Core.Model; - -namespace NzbDrone.Core.Helpers -{ - public static class EpisodeSortingHelper - { - private static readonly List SeparatorStyles = new List - { - new EpisodeSortingType - { - Id = 0, - Name = "Dash", - Pattern = " - " - }, - new EpisodeSortingType - { - Id = 1, - Name = "Space", - Pattern = " " - }, - new EpisodeSortingType - { - Id = 2, - Name = "Period", - Pattern = "." - } - }; - - private static readonly List NumberStyles = new List - { - new EpisodeSortingType - { - Id = 0, - Name = "1x05", - Pattern = "%sx%0e", - EpisodeSeparator = "x" - - }, - new EpisodeSortingType - { - Id = 1, - Name = "01x05", - Pattern = "%0sx%0e", - EpisodeSeparator = "x" - }, - new EpisodeSortingType - { - Id = 2, - Name = "S01E05", - Pattern = "S%0sE%0e", - EpisodeSeparator = "E" - }, - new EpisodeSortingType - { - Id = 3, - Name = "s01e05", - Pattern = "s%0se%0e", - EpisodeSeparator = "e" - } - }; - - private static readonly List MultiEpisodeStyles = new List - { - new EpisodeSortingType - { - Id = 0, - Name = "Extend", - Pattern = "-%0e" - }, - new EpisodeSortingType - { - Id = 1, - Name = "Duplicate", - Pattern = "%p%0s%x%0e" - }, - new EpisodeSortingType - { - Id = 2, - Name = "Repeat", - Pattern = "%x%0e" - }, - new EpisodeSortingType - { - Id = 3, - Name = "Scene", - Pattern = "-%x%0e" - } - }; - - public static List GetSeparatorStyles() - { - return SeparatorStyles; - } - - public static List GetNumberStyles() - { - return NumberStyles; - } - - public static List GetMultiEpisodeStyles() - { - return MultiEpisodeStyles; - } - - public static EpisodeSortingType GetSeparatorStyle(int id) - { - return SeparatorStyles.Single(s => s.Id == id); - } - - public static EpisodeSortingType GetNumberStyle(int id) - { - return NumberStyles.Single(s => s.Id == id); - } - - public static EpisodeSortingType GetMultiEpisodeStyle(int id) - { - return MultiEpisodeStyles.Single(s => s.Id == id); - } - - public static EpisodeSortingType GetSeparatorStyle(string name) - { - return SeparatorStyles.Single(s => s.Name == name); - } - - public static EpisodeSortingType GetNumberStyle(string name) - { - return NumberStyles.Single(s => s.Name == name); - } - - public static EpisodeSortingType GetMultiEpisodeStyle(string name) - { - return MultiEpisodeStyles.Single(s => s.Name == name); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 1bddb48eb..a7bfe8056 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -195,7 +195,6 @@ - @@ -234,6 +233,7 @@ + @@ -256,6 +256,7 @@ + @@ -501,7 +502,6 @@ - diff --git a/NzbDrone.Core/Model/EpisodeSortingType.cs b/NzbDrone.Core/Organizer/EpisodeSortingType.cs similarity index 85% rename from NzbDrone.Core/Model/EpisodeSortingType.cs rename to NzbDrone.Core/Organizer/EpisodeSortingType.cs index 1bb23bdf5..d68549f07 100644 --- a/NzbDrone.Core/Model/EpisodeSortingType.cs +++ b/NzbDrone.Core/Organizer/EpisodeSortingType.cs @@ -1,4 +1,4 @@ -namespace NzbDrone.Core.Model +namespace NzbDrone.Core.Organizer { public class EpisodeSortingType { diff --git a/NzbDrone.Core/Organizer/FileNameBuilder.cs b/NzbDrone.Core/Organizer/FileNameBuilder.cs index f7c9c5128..0f742fca0 100644 --- a/NzbDrone.Core/Organizer/FileNameBuilder.cs +++ b/NzbDrone.Core/Organizer/FileNameBuilder.cs @@ -4,45 +4,15 @@ 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 UseSceneName { get; set; } - - public int SeparatorStyle { get; set; } - - public int NumberStyle { get; set; } - - public bool IncludeSeriesName { get; set; } - - public int MultiEpisodeStyle { get; set; } - - public bool IncludeEpisodeTitle { get; set; } - - public bool AppendQuality { get; set; } - - public bool ReplaceSpaces { get; set; } - - public string SeasonFolderFormat { get; set; } - } - - public interface IBuildFileNames { string BuildFilename(IList episodes, Series series, EpisodeFile episodeFile); - FileInfo BuildFilePath(Series series, int seasonNumber, string fileName, string extension); + string BuildFilePath(Series series, int seasonNumber, string fileName, string extension); } public class FileNameBuilder : IBuildFileNames @@ -69,13 +39,9 @@ public string BuildFilename(IList episodes, Series series, EpisodeFile if (nameSpec.UseSceneName) { - _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 Path.GetFileNameWithoutExtension(episodeFile.Path); } return episodeFile.SceneName; @@ -83,18 +49,18 @@ public string BuildFilename(IList episodes, Series series, EpisodeFile var sortedEpisodes = episodes.OrderBy(e => e.EpisodeNumber); - var separatorStyle = EpisodeSortingHelper.GetSeparatorStyle(nameSpec.SeparatorStyle); - var numberStyle = EpisodeSortingHelper.GetNumberStyle(nameSpec.NumberStyle); + var numberStyle = GetNumberStyle(nameSpec.NumberStyle); - var episodeNames = new List(); + var episodeNames = new List + { + Parser.CleanupEpisodeTitle(sortedEpisodes.First().Title) + }; - episodeNames.Add(Parser.CleanupEpisodeTitle(sortedEpisodes.First().Title)); - - string result = String.Empty; + var result = String.Empty; if (nameSpec.IncludeSeriesName) { - result += series.Title + separatorStyle.Pattern; + result += series.Title + nameSpec.Separator; } if (series.SeriesTypes == SeriesTypes.Standard) @@ -105,13 +71,13 @@ public string BuildFilename(IList episodes, Series series, EpisodeFile if (episodes.Count > 1) { var multiEpisodeStyle = - EpisodeSortingHelper.GetMultiEpisodeStyle(nameSpec.MultiEpisodeStyle); + GetMultiEpisodeStyle(nameSpec.MultiEpisodeStyle); foreach (var episode in sortedEpisodes.Skip(1)) { if (multiEpisodeStyle.Name == "Duplicate") { - result += separatorStyle.Pattern + numberStyle.Pattern; + result += nameSpec.Separator + numberStyle.Pattern; } else { @@ -127,7 +93,7 @@ public string BuildFilename(IList episodes, Series series, EpisodeFile .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); + .Replace("%p", nameSpec.Separator); } else @@ -142,10 +108,10 @@ public string BuildFilename(IList episodes, Series series, EpisodeFile if (nameSpec.IncludeEpisodeTitle) { if (episodeNames.Distinct().Count() == 1) - result += separatorStyle.Pattern + episodeNames.First(); + result += nameSpec.Separator + episodeNames.First(); else - result += separatorStyle.Pattern + String.Join(" + ", episodeNames.Distinct()); + result += nameSpec.Separator + String.Join(" + ", episodeNames.Distinct()); } if (nameSpec.AppendQuality) @@ -163,7 +129,7 @@ public string BuildFilename(IList episodes, Series series, EpisodeFile return CleanFilename(result.Trim()); } - public FileInfo BuildFilePath(Series series, int seasonNumber, string fileName, string extension) + public string BuildFilePath(Series series, int seasonNumber, string fileName, string extension) { var nameSpec = GetSpecification(); @@ -178,9 +144,7 @@ public FileInfo BuildFilePath(Series series, int seasonNumber, string fileName, path = Path.Combine(path, seasonFolder); } - path = Path.Combine(path, fileName + extension); - - return new FileInfo(path); + return Path.Combine(path, fileName + extension); } @@ -195,5 +159,78 @@ public static string CleanFilename(string name) return result.Trim(); } + + + private static readonly List NumberStyles = new List + { + new EpisodeSortingType + { + Id = 0, + Name = "1x05", + Pattern = "%sx%0e", + EpisodeSeparator = "x" + + }, + new EpisodeSortingType + { + Id = 1, + Name = "01x05", + Pattern = "%0sx%0e", + EpisodeSeparator = "x" + }, + new EpisodeSortingType + { + Id = 2, + Name = "S01E05", + Pattern = "S%0sE%0e", + EpisodeSeparator = "E" + }, + new EpisodeSortingType + { + Id = 3, + Name = "s01e05", + Pattern = "s%0se%0e", + EpisodeSeparator = "e" + } + }; + + private static readonly List MultiEpisodeStyles = new List + { + new EpisodeSortingType + { + Id = 0, + Name = "Extend", + Pattern = "-%0e" + }, + new EpisodeSortingType + { + Id = 1, + Name = "Duplicate", + Pattern = "%p%0s%x%0e" + }, + new EpisodeSortingType + { + Id = 2, + Name = "Repeat", + Pattern = "%x%0e" + }, + new EpisodeSortingType + { + Id = 3, + Name = "Scene", + Pattern = "-%x%0e" + } + }; + + + private static EpisodeSortingType GetNumberStyle(int id) + { + return NumberStyles.Single(s => s.Id == id); + } + + private static EpisodeSortingType GetMultiEpisodeStyle(int id) + { + return MultiEpisodeStyles.Single(s => s.Id == id); + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Organizer/NameSpecification.cs b/NzbDrone.Core/Organizer/NameSpecification.cs new file mode 100644 index 000000000..081f5494c --- /dev/null +++ b/NzbDrone.Core/Organizer/NameSpecification.cs @@ -0,0 +1,30 @@ +using NzbDrone.Core.Datastore; + +namespace NzbDrone.Core.Organizer +{ + public class NameSpecification : ModelBase + { + public static NameSpecification Default + { + get { return new NameSpecification(); } + } + + public bool UseSceneName { get; set; } + + public string Separator { get; set; } + + public int NumberStyle { get; set; } + + public bool IncludeSeriesName { get; set; } + + public int MultiEpisodeStyle { get; set; } + + public bool IncludeEpisodeTitle { get; set; } + + public bool AppendQuality { get; set; } + + public bool ReplaceSpaces { get; set; } + + public string SeasonFolderFormat { get; set; } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Providers/DiskScanProvider.cs b/NzbDrone.Core/Providers/DiskScanProvider.cs index d8c232087..b7cf4a8ad 100644 --- a/NzbDrone.Core/Providers/DiskScanProvider.cs +++ b/NzbDrone.Core/Providers/DiskScanProvider.cs @@ -192,7 +192,7 @@ public virtual EpisodeFile MoveEpisodeFile(EpisodeFile episodeFile, bool newDown var newFile = _buildFileNames.BuildFilePath(series, episodes.First().SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path)); //Only rename if existing and new filenames don't match - if (DiskProvider.PathEquals(episodeFile.Path, newFile.FullName)) + if (DiskProvider.PathEquals(episodeFile.Path, newFile)) { Logger.Debug("Skipping file rename, source and destination are the same: {0}", episodeFile.Path); return null; @@ -204,23 +204,23 @@ public virtual EpisodeFile MoveEpisodeFile(EpisodeFile episodeFile, bool newDown return null; } - _diskProvider.CreateDirectory(newFile.DirectoryName); + _diskProvider.CreateDirectory(new FileInfo(newFile).DirectoryName); - Logger.Debug("Moving [{0}] > [{1}]", episodeFile.Path, newFile.FullName); - _diskProvider.MoveFile(episodeFile.Path, newFile.FullName); + Logger.Debug("Moving [{0}] > [{1}]", episodeFile.Path, newFile); + _diskProvider.MoveFile(episodeFile.Path, newFile); //Wrapped in Try/Catch to prevent this from causing issues with remote NAS boxes, the move worked, which is more important. try { - _diskProvider.InheritFolderPermissions(newFile.FullName); + _diskProvider.InheritFolderPermissions(newFile); } catch (UnauthorizedAccessException ex) { - Logger.Debug("Unable to apply folder permissions to: ", newFile.FullName); + Logger.Debug("Unable to apply folder permissions to: ", newFile); Logger.TraceException(ex.Message, ex); } - episodeFile.Path = newFile.FullName; + episodeFile.Path = newFile; _mediaFileService.Update(episodeFile); var parseResult = Parser.ParsePath(episodeFile.Path);