diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj
index 3985392e1..7f852ed5d 100644
--- a/src/NzbDrone.Core/NzbDrone.Core.csproj
+++ b/src/NzbDrone.Core/NzbDrone.Core.csproj
@@ -327,6 +327,7 @@
+
diff --git a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs
index 492573da1..51076b228 100644
--- a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs
+++ b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs
@@ -5,7 +5,6 @@ using System.Linq;
using System.Text.RegularExpressions;
using NLog;
using NzbDrone.Core.Configuration;
-using NzbDrone.Core.Datastore;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Tv;
@@ -18,39 +17,7 @@ namespace NzbDrone.Core.Organizer
string BuildFilePath(Series series, int seasonNumber, string fileName, string extension);
}
- public interface INamingConfigService
- {
- NamingConfig GetConfig();
- NamingConfig Save(NamingConfig namingConfig);
- }
-
- public class NamingConfigService : INamingConfigService
- {
- private readonly IBasicRepository _repository;
- public NamingConfigService(IBasicRepository repository)
- {
- _repository = repository;
- }
-
- public NamingConfig GetConfig()
- {
- var config = _repository.SingleOrDefault();
-
- if (config == null)
- {
- _repository.Insert(NamingConfig.Default);
- config = _repository.Single();
- }
-
- return config;
- }
-
- public NamingConfig Save(NamingConfig namingConfig)
- {
- return _repository.Upsert(namingConfig);
- }
- }
public class FileNameBuilder : IBuildFileNames
{
@@ -84,9 +51,9 @@ namespace NzbDrone.Core.Organizer
return BuildFilename(episodes, series, episodeFile, nameSpec);
}
- public string BuildFilename(IList episodes, Series series, EpisodeFile episodeFile, NamingConfig nameSpec)
+ public string BuildFilename(IList episodes, Series series, EpisodeFile episodeFile, NamingConfig namingConfig)
{
- if (!nameSpec.RenameEpisodes)
+ if (!namingConfig.RenameEpisodes)
{
if (String.IsNullOrWhiteSpace(episodeFile.SceneName))
{
@@ -96,29 +63,31 @@ namespace NzbDrone.Core.Organizer
return episodeFile.SceneName;
}
- if (String.IsNullOrWhiteSpace(nameSpec.StandardEpisodeFormat) && series.SeriesType == SeriesTypes.Standard)
+ if (String.IsNullOrWhiteSpace(namingConfig.StandardEpisodeFormat) && series.SeriesType == SeriesTypes.Standard)
{
throw new NamingFormatException("Standard episode format cannot be null");
}
- if (String.IsNullOrWhiteSpace(nameSpec.DailyEpisodeFormat) && series.SeriesType == SeriesTypes.Daily)
+ if (String.IsNullOrWhiteSpace(namingConfig.DailyEpisodeFormat) && series.SeriesType == SeriesTypes.Daily)
{
throw new NamingFormatException("Daily episode format cannot be null");
}
var sortedEpisodes = episodes.OrderBy(e => e.EpisodeNumber).ToList();
- var pattern = nameSpec.StandardEpisodeFormat;
+ var pattern = namingConfig.StandardEpisodeFormat;
var episodeTitles = new List
{
Parser.Parser.CleanupEpisodeTitle(sortedEpisodes.First().Title)
};
- var tokenValues = new Dictionary(new FilenameBuilderTokenEqualityComparer());
- tokenValues.Add("{Series Title}", series.Title);
+ var tokenValues = new Dictionary(FilenameBuilderTokenEqualityComparer.Instance)
+ {
+ {"{Series Title}", series.Title}
+ };
if (series.SeriesType == SeriesTypes.Daily)
{
- pattern = nameSpec.DailyEpisodeFormat;
+ pattern = namingConfig.DailyEpisodeFormat;
if (!String.IsNullOrWhiteSpace(episodes.First().AirDate))
{
@@ -146,7 +115,7 @@ namespace NzbDrone.Core.Organizer
foreach (var episode in sortedEpisodes.Skip(1))
{
- switch ((MultiEpisodeStyle)nameSpec.MultiEpisodeStyle)
+ switch ((MultiEpisodeStyle)namingConfig.MultiEpisodeStyle)
{
case MultiEpisodeStyle.Duplicate:
seasonEpisodePattern += episodeFormat.Separator + episodeFormat.SeasonEpisodePattern;
@@ -194,7 +163,7 @@ namespace NzbDrone.Core.Organizer
else
{
- var tokenValues = new Dictionary(new FilenameBuilderTokenEqualityComparer());
+ var tokenValues = new Dictionary(FilenameBuilderTokenEqualityComparer.Instance);
tokenValues.Add("{Series Title}", series.Title);
seasonFolder = ReplaceSeasonTokens(_configService.SeasonFolderFormat, seasonNumber);
@@ -275,38 +244,6 @@ namespace NzbDrone.Core.Organizer
return value.ToString().PadLeft(zeroCount + 1, '0');
}
- 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 GetMultiEpisodeStyle(int id)
- {
- return MultiEpisodeStyles.Single(s => s.Id == id);
- }
}
public enum MultiEpisodeStyle
diff --git a/src/NzbDrone.Core/Organizer/FilenameBuilderTokenEqualityComparer.cs b/src/NzbDrone.Core/Organizer/FilenameBuilderTokenEqualityComparer.cs
index a8ba17a23..16b225131 100644
--- a/src/NzbDrone.Core/Organizer/FilenameBuilderTokenEqualityComparer.cs
+++ b/src/NzbDrone.Core/Organizer/FilenameBuilderTokenEqualityComparer.cs
@@ -6,8 +6,15 @@ namespace NzbDrone.Core.Organizer
{
public class FilenameBuilderTokenEqualityComparer : IEqualityComparer
{
+ public static readonly FilenameBuilderTokenEqualityComparer Instance = new FilenameBuilderTokenEqualityComparer();
+
private static readonly Regex SimpleTokenRegex = new Regex(@"\s|_|\W", RegexOptions.Compiled | RegexOptions.IgnoreCase);
+ private FilenameBuilderTokenEqualityComparer()
+ {
+
+ }
+
public bool Equals(String s1, String s2)
{
return SimplifyToken(s1).Equals(SimplifyToken(s2));
@@ -18,7 +25,7 @@ namespace NzbDrone.Core.Organizer
return SimplifyToken(str).GetHashCode();
}
- private string SimplifyToken(string token)
+ private static string SimplifyToken(string token)
{
return SimpleTokenRegex.Replace(token, String.Empty).ToLower();
}
diff --git a/src/NzbDrone.Core/Organizer/NamingConfigService.cs b/src/NzbDrone.Core/Organizer/NamingConfigService.cs
new file mode 100644
index 000000000..113ef030a
--- /dev/null
+++ b/src/NzbDrone.Core/Organizer/NamingConfigService.cs
@@ -0,0 +1,38 @@
+using NzbDrone.Core.Datastore;
+
+namespace NzbDrone.Core.Organizer
+{
+ public interface INamingConfigService
+ {
+ NamingConfig GetConfig();
+ void Save(NamingConfig namingConfig);
+ }
+
+ public class NamingConfigService : INamingConfigService
+ {
+ private readonly IBasicRepository _repository;
+
+ public NamingConfigService(IBasicRepository repository)
+ {
+ _repository = repository;
+ }
+
+ public NamingConfig GetConfig()
+ {
+ var config = _repository.SingleOrDefault();
+
+ if (config == null)
+ {
+ _repository.Insert(NamingConfig.Default);
+ config = _repository.Single();
+ }
+
+ return config;
+ }
+
+ public void Save(NamingConfig namingConfig)
+ {
+ _repository.Upsert(namingConfig);
+ }
+ }
+}
\ No newline at end of file