From dade3bb2140309edc480b55a1b47925cc40db5f9 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 15 Apr 2014 07:16:49 -0700 Subject: [PATCH] New: Examples for Series and Season folder format --- src/NzbDrone.Api/Config/NamingConfigModule.cs | 3 +++ .../Config/NamingSampleResource.cs | 2 ++ .../Organizer/FileNameBuilder.cs | 27 ++++++++++++++----- .../Organizer/FilenameSampleService.cs | 15 ++++++++--- .../MediaManagement/Naming/NamingView.js | 6 ++++- .../Naming/NamingViewTemplate.html | 20 ++++++++++++-- 6 files changed, 60 insertions(+), 13 deletions(-) diff --git a/src/NzbDrone.Api/Config/NamingConfigModule.cs b/src/NzbDrone.Api/Config/NamingConfigModule.cs index eb41ef9e9..a571dd400 100644 --- a/src/NzbDrone.Api/Config/NamingConfigModule.cs +++ b/src/NzbDrone.Api/Config/NamingConfigModule.cs @@ -92,6 +92,9 @@ namespace NzbDrone.Api.Config ? "Invalid format" : dailyEpisodeSampleResult.Filename; + sampleResource.SeriesFolderExample = _filenameSampleService.GetSeriesFolderSample(nameSpec); + sampleResource.SeasonFolderExample = _filenameSampleService.GetSeasonFolderSample(nameSpec); + return sampleResource.AsResponse(); } diff --git a/src/NzbDrone.Api/Config/NamingSampleResource.cs b/src/NzbDrone.Api/Config/NamingSampleResource.cs index 7f6d0e99e..56ff031d2 100644 --- a/src/NzbDrone.Api/Config/NamingSampleResource.cs +++ b/src/NzbDrone.Api/Config/NamingSampleResource.cs @@ -5,5 +5,7 @@ public string SingleEpisodeExample { get; set; } public string MultiEpisodeExample { get; set; } public string DailyEpisodeExample { get; set; } + public string SeriesFolderExample { get; set; } + public string SeasonFolderExample { get; set; } } } \ No newline at end of file diff --git a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs index d3caa5729..c09bc0c6d 100644 --- a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs +++ b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs @@ -18,6 +18,8 @@ namespace NzbDrone.Core.Organizer string BuildFilePath(Series series, int seasonNumber, string fileName, string extension); BasicNamingConfig GetBasicNamingConfig(NamingConfig nameSpec); string GetSeriesFolder(string seriesTitle); + string GetSeriesFolder(string seriesTitle, NamingConfig namingConfig); + string GetSeasonFolder(string seriesTitle, int seasonNumber, NamingConfig namingConfig); } public class FileNameBuilder : IBuildFileNames @@ -171,11 +173,7 @@ namespace NzbDrone.Core.Organizer else { var nameSpec = _namingConfigService.GetConfig(); - var tokenValues = new Dictionary(FilenameBuilderTokenEqualityComparer.Instance); - tokenValues.Add("{Series Title}", series.Title); - - seasonFolder = ReplaceSeasonTokens(nameSpec.SeasonFolderFormat, seasonNumber); - seasonFolder = ReplaceTokens(seasonFolder, tokenValues); + seasonFolder = GetSeasonFolder(series.Title, seasonNumber, nameSpec); } seasonFolder = CleanFilename(seasonFolder); @@ -233,14 +231,29 @@ namespace NzbDrone.Core.Organizer } public string GetSeriesFolder(string seriesTitle) + { + var namingConfig = _namingConfigService.GetConfig(); + + return GetSeriesFolder(seriesTitle, namingConfig); + } + + public string GetSeriesFolder(string seriesTitle, NamingConfig namingConfig) { seriesTitle = CleanFilename(seriesTitle); - var nameSpec = _namingConfigService.GetConfig(); var tokenValues = new Dictionary(FilenameBuilderTokenEqualityComparer.Instance); tokenValues.Add("{Series Title}", seriesTitle); - return ReplaceTokens(nameSpec.SeriesFolderFormat, tokenValues); + return ReplaceTokens(namingConfig.SeriesFolderFormat, tokenValues); + } + + public string GetSeasonFolder(string seriesTitle, int seasonNumber, NamingConfig namingConfig) + { + var tokenValues = new Dictionary(FilenameBuilderTokenEqualityComparer.Instance); + tokenValues.Add("{Series Title}", seriesTitle); + + var seasonFolder = ReplaceSeasonTokens(namingConfig.SeasonFolderFormat, seasonNumber); + return ReplaceTokens(seasonFolder, tokenValues); } public static string CleanFilename(string name) diff --git a/src/NzbDrone.Core/Organizer/FilenameSampleService.cs b/src/NzbDrone.Core/Organizer/FilenameSampleService.cs index 668a20966..2857bdd3a 100644 --- a/src/NzbDrone.Core/Organizer/FilenameSampleService.cs +++ b/src/NzbDrone.Core/Organizer/FilenameSampleService.cs @@ -1,9 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using NzbDrone.Core.MediaFiles; -using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Qualities; using NzbDrone.Core.Tv; @@ -14,6 +11,8 @@ namespace NzbDrone.Core.Organizer SampleResult GetStandardSample(NamingConfig nameSpec); SampleResult GetMultiEpisodeSample(NamingConfig nameSpec); SampleResult GetDailySample(NamingConfig nameSpec); + String GetSeriesFolderSample(NamingConfig nameSpec); + String GetSeasonFolderSample(NamingConfig nameSpec); } public class FilenameSampleService : IFilenameSampleService @@ -123,6 +122,16 @@ namespace NzbDrone.Core.Organizer return result; } + public string GetSeriesFolderSample(NamingConfig nameSpec) + { + return _buildFileNames.GetSeriesFolder(_standardSeries.Title, nameSpec); + } + + public string GetSeasonFolderSample(NamingConfig nameSpec) + { + return _buildFileNames.GetSeasonFolder(_standardSeries.Title, _episode1.SeasonNumber, nameSpec); + } + private string BuildSample(List episodes, Series series, EpisodeFile episodeFile, NamingConfig nameSpec) { try diff --git a/src/UI/Settings/MediaManagement/Naming/NamingView.js b/src/UI/Settings/MediaManagement/Naming/NamingView.js index ab0c91a7b..071339d59 100644 --- a/src/UI/Settings/MediaManagement/Naming/NamingView.js +++ b/src/UI/Settings/MediaManagement/Naming/NamingView.js @@ -19,7 +19,9 @@ define( multiEpisodeExample : '.x-multi-episode-example', dailyEpisodeExample : '.x-daily-episode-example', namingTokenHelper : '.x-naming-token-helper', - multiEpisodeStyle : '.x-multi-episode-style' + multiEpisodeStyle : '.x-multi-episode-style', + seriesFolderExample : '.x-series-folder-example', + seasonFolderExample : '.x-season-folder-example' }, events: { @@ -66,6 +68,8 @@ define( this.ui.singleEpisodeExample.html(this.namingSampleModel.get('singleEpisodeExample')); this.ui.multiEpisodeExample.html(this.namingSampleModel.get('multiEpisodeExample')); this.ui.dailyEpisodeExample.html(this.namingSampleModel.get('dailyEpisodeExample')); + this.ui.seriesFolderExample.html(this.namingSampleModel.get('seriesFolderExample')); + this.ui.seasonFolderExample.html(this.namingSampleModel.get('seasonFolderExample')); }, _addToken: function (e) { diff --git a/src/UI/Settings/MediaManagement/Naming/NamingViewTemplate.html b/src/UI/Settings/MediaManagement/Naming/NamingViewTemplate.html index c72a6524e..df3917db9 100644 --- a/src/UI/Settings/MediaManagement/Naming/NamingViewTemplate.html +++ b/src/UI/Settings/MediaManagement/Naming/NamingViewTemplate.html @@ -103,7 +103,7 @@
- +
+ +
+ + +
+ +
+
+ +
+ + +
+ +
+