diff --git a/src/NzbDrone.Api/Config/NamingConfigModule.cs b/src/NzbDrone.Api/Config/NamingConfigModule.cs index 474bcae45e..42efaa49a4 100644 --- a/src/NzbDrone.Api/Config/NamingConfigModule.cs +++ b/src/NzbDrone.Api/Config/NamingConfigModule.cs @@ -34,11 +34,6 @@ public NamingConfigModule(INamingConfigService namingConfigService, Get["/samples"] = x => GetExamples(this.Bind()); SharedValidator.RuleFor(c => c.MultiEpisodeStyle).InclusiveBetween(0, 5); - /*SharedValidator.RuleFor(c => c.StandardEpisodeFormat).ValidEpisodeFormat(); - SharedValidator.RuleFor(c => c.DailyEpisodeFormat).ValidDailyEpisodeFormat(); - SharedValidator.RuleFor(c => c.AnimeEpisodeFormat).ValidAnimeEpisodeFormat(); - SharedValidator.RuleFor(c => c.SeriesFolderFormat).ValidSeriesFolderFormat(); - SharedValidator.RuleFor(c => c.SeasonFolderFormat).ValidSeasonFolderFormat();*/ SharedValidator.RuleFor(c => c.StandardMovieFormat).ValidMovieFormat(); SharedValidator.RuleFor(c => c.MovieFolderFormat).ValidMovieFolderFormat(); } @@ -56,12 +51,6 @@ private NamingConfigResource GetNamingConfig() var nameSpec = _namingConfigService.GetConfig(); var resource = nameSpec.ToResource(); - //if (resource.StandardEpisodeFormat.IsNotNullOrWhiteSpace()) - //{ - // var basicConfig = _filenameBuilder.GetBasicNamingConfig(nameSpec); - // basicConfig.AddToResource(resource); - //} - if (resource.StandardMovieFormat.IsNotNullOrWhiteSpace()) { var basicConfig = _filenameBuilder.GetBasicNamingConfig(nameSpec); @@ -80,48 +69,13 @@ private JsonResponse GetExamples(NamingConfigResource conf { var nameSpec = config.ToModel(); var sampleResource = new NamingSampleResource(); - - //var singleEpisodeSampleResult = _filenameSampleService.GetStandardSample(nameSpec); - //var multiEpisodeSampleResult = _filenameSampleService.GetMultiEpisodeSample(nameSpec); - //var dailyEpisodeSampleResult = _filenameSampleService.GetDailySample(nameSpec); - //var animeEpisodeSampleResult = _filenameSampleService.GetAnimeSample(nameSpec); - //var animeMultiEpisodeSampleResult = _filenameSampleService.GetAnimeMultiEpisodeSample(nameSpec); var movieSampleResult = _filenameSampleService.GetMovieSample(nameSpec); - - - //sampleResource.SingleEpisodeExample = _filenameValidationService.ValidateStandardFilename(singleEpisodeSampleResult) != null - // ? "Invalid format" - // : singleEpisodeSampleResult.FileName; - - //sampleResource.MultiEpisodeExample = _filenameValidationService.ValidateStandardFilename(multiEpisodeSampleResult) != null - // ? "Invalid format" - // : multiEpisodeSampleResult.FileName; - - //sampleResource.DailyEpisodeExample = _filenameValidationService.ValidateDailyFilename(dailyEpisodeSampleResult) != null - // ? "Invalid format" - // : dailyEpisodeSampleResult.FileName; - - //sampleResource.AnimeEpisodeExample = _filenameValidationService.ValidateAnimeFilename(animeEpisodeSampleResult) != null - // ? "Invalid format" - // : animeEpisodeSampleResult.FileName; - - //sampleResource.AnimeMultiEpisodeExample = _filenameValidationService.ValidateAnimeFilename(animeMultiEpisodeSampleResult) != null - // ? "Invalid format" - // : animeMultiEpisodeSampleResult.FileName; sampleResource.MovieExample = nameSpec.StandardMovieFormat.IsNullOrWhiteSpace() ? "Invalid Format" : movieSampleResult.FileName; - //sampleResource.SeriesFolderExample = nameSpec.SeriesFolderFormat.IsNullOrWhiteSpace() - // ? "Invalid format" - // : _filenameSampleService.GetSeriesFolderSample(nameSpec); - - //sampleResource.SeasonFolderExample = nameSpec.SeasonFolderFormat.IsNullOrWhiteSpace() - // ? "Invalid format" - // : _filenameSampleService.GetSeasonFolderSample(nameSpec); - sampleResource.MovieFolderExample = nameSpec.MovieFolderFormat.IsNullOrWhiteSpace() ? "Invalid format" : _filenameSampleService.GetMovieFolderSample(nameSpec); @@ -137,12 +91,6 @@ private void ValidateFormatResult(NamingConfig nameSpec) var validationFailures = new List(); - //validationFailures.AddIfNotNull(singleEpisodeValidationResult); - //validationFailures.AddIfNotNull(multiEpisodeValidationResult); - //validationFailures.AddIfNotNull(dailyEpisodeValidationResult); - //validationFailures.AddIfNotNull(animeEpisodeValidationResult); - //validationFailures.AddIfNotNull(animeMultiEpisodeValidationResult); - //validationFailures.AddIfNotNull(standardMovieValidationResult); if (validationFailures.Any()) diff --git a/src/NzbDrone.Api/Config/NamingConfigResource.cs b/src/NzbDrone.Api/Config/NamingConfigResource.cs index e78395bbf6..9e657e36e4 100644 --- a/src/NzbDrone.Api/Config/NamingConfigResource.cs +++ b/src/NzbDrone.Api/Config/NamingConfigResource.cs @@ -7,6 +7,7 @@ public class NamingConfigResource : RestResource { public bool RenameEpisodes { get; set; } public bool ReplaceIllegalCharacters { get; set; } + public ColonReplacementFormat ColonReplacementFormat { get; set; } public string StandardMovieFormat { get; set; } public string MovieFolderFormat { get; set; } public int MultiEpisodeStyle { get; set; } @@ -28,6 +29,7 @@ public static NamingConfigResource ToResource(this NamingConfig model) RenameEpisodes = model.RenameEpisodes, ReplaceIllegalCharacters = model.ReplaceIllegalCharacters, + ColonReplacementFormat = model.ColonReplacementFormat, MultiEpisodeStyle = model.MultiEpisodeStyle, StandardMovieFormat = model.StandardMovieFormat, MovieFolderFormat = model.MovieFolderFormat @@ -58,12 +60,7 @@ public static NamingConfig ToModel(this NamingConfigResource resource) RenameEpisodes = resource.RenameEpisodes, ReplaceIllegalCharacters = resource.ReplaceIllegalCharacters, - //MultiEpisodeStyle = resource.MultiEpisodeStyle, - //StandardEpisodeFormat = resource.StandardEpisodeFormat, - //DailyEpisodeFormat = resource.DailyEpisodeFormat, - //AnimeEpisodeFormat = resource.AnimeEpisodeFormat, - //SeriesFolderFormat = resource.SeriesFolderFormat, - //SeasonFolderFormat = resource.SeasonFolderFormat, + ColonReplacementFormat = resource.ColonReplacementFormat, StandardMovieFormat = resource.StandardMovieFormat, MovieFolderFormat = resource.MovieFolderFormat }; diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/UsenetDownloadStationFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/UsenetDownloadStationFixture.cs index fafdddaa76..26fd069bc2 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/UsenetDownloadStationFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/UsenetDownloadStationFixture.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using FluentAssertions; @@ -66,7 +66,7 @@ public void Setup() Detail = new Dictionary { { "destination","shared/folder" }, - { "uri", FileNameBuilder.CleanFileName(_remoteEpisode.Release.Title) + ".nzb" } + { "uri", CleanFileName(_remoteEpisode.Release.Title) } }, Transfer = new Dictionary { @@ -89,7 +89,7 @@ public void Setup() Detail = new Dictionary { { "destination","shared/folder" }, - { "uri", FileNameBuilder.CleanFileName(_remoteEpisode.Release.Title) + ".nzb" } + { "uri", CleanFileName(_remoteEpisode.Release.Title) } }, Transfer = new Dictionary { @@ -112,7 +112,7 @@ public void Setup() Detail = new Dictionary { { "destination","shared/folder" }, - { "uri", FileNameBuilder.CleanFileName(_remoteEpisode.Release.Title) + ".nzb" } + { "uri", CleanFileName(_remoteEpisode.Release.Title) } }, Transfer = new Dictionary { @@ -135,7 +135,7 @@ public void Setup() Detail = new Dictionary { { "destination","shared/folder" }, - { "uri", FileNameBuilder.CleanFileName(_remoteEpisode.Release.Title) + ".nzb" } + { "uri", CleanFileName(_remoteEpisode.Release.Title) } }, Transfer = new Dictionary { @@ -158,7 +158,7 @@ public void Setup() Detail = new Dictionary { { "destination","shared/folder" }, - { "uri", FileNameBuilder.CleanFileName(_remoteEpisode.Release.Title) + ".nzb" } + { "uri", CleanFileName(_remoteEpisode.Release.Title) } }, Transfer = new Dictionary { @@ -247,6 +247,11 @@ protected void GivenAllKindOfTasks() .Returns(tasks); } + protected static string CleanFileName(String name) + { + return FileNameBuilder.CleanFileName(name, NamingConfig.Default) + ".nzb"; + } + [Test] public void Download_with_TvDirectory_should_force_directory() { diff --git a/src/NzbDrone.Core.Test/OrganizerTests/CleanFixture.cs b/src/NzbDrone.Core.Test/OrganizerTests/CleanFixture.cs index e9746de0b8..7e72d6ae29 100644 --- a/src/NzbDrone.Core.Test/OrganizerTests/CleanFixture.cs +++ b/src/NzbDrone.Core.Test/OrganizerTests/CleanFixture.cs @@ -12,8 +12,8 @@ public class CleanFixture : CoreTest "Mission Impossible - no [HDTV-720p]")] public void CleanFileName(string name, string expectedName) { - FileNameBuilder.CleanFileName(name).Should().Be(expectedName); + FileNameBuilder.CleanFileName(name, NamingConfig.Default).Should().Be(expectedName); } } -} \ No newline at end of file +} diff --git a/src/NzbDrone.Core/Datastore/Migration/146_naming_config_colon_replacement_format.cs b/src/NzbDrone.Core/Datastore/Migration/146_naming_config_colon_replacement_format.cs new file mode 100644 index 0000000000..3bbd64f528 --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/146_naming_config_colon_replacement_format.cs @@ -0,0 +1,14 @@ +using FluentMigrator; +using NzbDrone.Core.Datastore.Migration.Framework; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(146)] + public class naming_config_colon_action : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + Alter.Table("NamingConfig").AddColumn("ColonReplacementFormat").AsInt32().NotNullable().WithDefaultValue(0); + } + } +} diff --git a/src/NzbDrone.Core/Download/Clients/Blackhole/ScanWatchFolder.cs b/src/NzbDrone.Core/Download/Clients/Blackhole/ScanWatchFolder.cs index d6e80e3fd3..78980c4623 100644 --- a/src/NzbDrone.Core/Download/Clients/Blackhole/ScanWatchFolder.cs +++ b/src/NzbDrone.Core/Download/Clients/Blackhole/ScanWatchFolder.cs @@ -1,4 +1,4 @@ -using NLog; +using NLog; using NzbDrone.Common.Cache; using NzbDrone.Common.Crypto; using NzbDrone.Common.Disk; @@ -23,13 +23,15 @@ public class ScanWatchFolder : IScanWatchFolder private readonly Logger _logger; private readonly IDiskProvider _diskProvider; private readonly IDiskScanService _diskScanService; + private readonly INamingConfigService _namingConfigService; private readonly ICached> _watchFolderItemCache; - public ScanWatchFolder(ICacheManager cacheManager, IDiskScanService diskScanService, IDiskProvider diskProvider, Logger logger) + public ScanWatchFolder(ICacheManager cacheManager, IDiskScanService diskScanService, INamingConfigService namingConfigService, IDiskProvider diskProvider, Logger logger) { _logger = logger; _diskProvider = diskProvider; _diskScanService = diskScanService; + _namingConfigService = namingConfigService; _watchFolderItemCache = cacheManager.GetCache>(GetType()); } @@ -50,9 +52,12 @@ public IEnumerable GetItems(string watchFolder, TimeSpan waitPe private IEnumerable GetDownloadItems(string watchFolder, Dictionary lastWatchItems, TimeSpan waitPeriod) { + // get a fresh naming config each time, in case the user has made changes + NamingConfig namingConfig = _namingConfigService.GetConfig(); + foreach (var folder in _diskProvider.GetDirectories(watchFolder)) { - var title = FileNameBuilder.CleanFileName(Path.GetFileName(folder)); + var title = FileNameBuilder.CleanFileName(Path.GetFileName(folder), namingConfig); var newWatchItem = new WatchFolderItem { @@ -88,7 +93,7 @@ private IEnumerable GetDownloadItems(string watchFolder, Dictio foreach (var videoFile in _diskScanService.GetVideoFiles(watchFolder, false)) { - var title = FileNameBuilder.CleanFileName(Path.GetFileName(videoFile)); + var title = FileNameBuilder.CleanFileName(Path.GetFileName(videoFile), namingConfig); var newWatchItem = new WatchFolderItem { diff --git a/src/NzbDrone.Core/Download/Clients/Blackhole/TorrentBlackhole.cs b/src/NzbDrone.Core/Download/Clients/Blackhole/TorrentBlackhole.cs index d977d6ae55..c3a246f1eb 100644 --- a/src/NzbDrone.Core/Download/Clients/Blackhole/TorrentBlackhole.cs +++ b/src/NzbDrone.Core/Download/Clients/Blackhole/TorrentBlackhole.cs @@ -28,10 +28,11 @@ public TorrentBlackhole(IScanWatchFolder scanWatchFolder, ITorrentFileInfoReader torrentFileInfoReader, IHttpClient httpClient, IConfigService configService, + INamingConfigService namingConfigService, IDiskProvider diskProvider, IRemotePathMappingService remotePathMappingService, Logger logger) - : base(torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger) + : base(torrentFileInfoReader, httpClient, configService, namingConfigService, diskProvider, remotePathMappingService, logger) { _scanWatchFolder = scanWatchFolder; @@ -47,7 +48,7 @@ protected override string AddFromMagnetLink(RemoteMovie remoteMovie, string hash var title = remoteMovie.Release.Title; - title = FileNameBuilder.CleanFileName(title); + title = CleanFileName(title); var filepath = Path.Combine(Settings.TorrentFolder, string.Format("{0}.magnet", title)); @@ -66,7 +67,7 @@ protected override string AddFromTorrentFile(RemoteMovie remoteMovie, string has { var title = remoteMovie.Release.Title; - title = FileNameBuilder.CleanFileName(title); + title = CleanFileName(title); var filepath = Path.Combine(Settings.TorrentFolder, string.Format("{0}.torrent", title)); diff --git a/src/NzbDrone.Core/Download/Clients/Blackhole/UsenetBlackhole.cs b/src/NzbDrone.Core/Download/Clients/Blackhole/UsenetBlackhole.cs index ba0896787a..47a46c5273 100644 --- a/src/NzbDrone.Core/Download/Clients/Blackhole/UsenetBlackhole.cs +++ b/src/NzbDrone.Core/Download/Clients/Blackhole/UsenetBlackhole.cs @@ -22,10 +22,11 @@ public class UsenetBlackhole : UsenetClientBase public UsenetBlackhole(IScanWatchFolder scanWatchFolder, IHttpClient httpClient, IConfigService configService, + INamingConfigService namingConfigService, IDiskProvider diskProvider, IRemotePathMappingService remotePathMappingService, Logger logger) - : base(httpClient, configService, diskProvider, remotePathMappingService, logger) + : base(httpClient, configService, namingConfigService, diskProvider, remotePathMappingService, logger) { _scanWatchFolder = scanWatchFolder; @@ -36,7 +37,7 @@ protected override string AddFromNzbFile(RemoteMovie remoteMovie, string filenam { var title = remoteMovie.Release.Title; - title = FileNameBuilder.CleanFileName(title); + title = CleanFileName(title); var filepath = Path.Combine(Settings.NzbFolder, title + ".nzb"); diff --git a/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs b/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs index 55b71345e7..6c8185006a 100644 --- a/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs +++ b/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs @@ -12,6 +12,7 @@ using FluentValidation.Results; using System.Net; using NzbDrone.Core.RemotePathMappings; +using NzbDrone.Core.Organizer; namespace NzbDrone.Core.Download.Clients.Deluge { @@ -23,10 +24,11 @@ public Deluge(IDelugeProxy proxy, ITorrentFileInfoReader torrentFileInfoReader, IHttpClient httpClient, IConfigService configService, + INamingConfigService namingConfigService, IDiskProvider diskProvider, IRemotePathMappingService remotePathMappingService, Logger logger) - : base(torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger) + : base(torrentFileInfoReader, httpClient, configService, namingConfigService, diskProvider, remotePathMappingService, logger) { _proxy = proxy; } diff --git a/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs b/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs index 9f77add30f..2d16f8b4d4 100644 --- a/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs +++ b/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs @@ -11,6 +11,7 @@ using NzbDrone.Core.Configuration; using NzbDrone.Core.Download.Clients.DownloadStation.Proxies; using NzbDrone.Core.MediaFiles.TorrentInfo; +using NzbDrone.Core.Organizer; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.RemotePathMappings; using NzbDrone.Core.Validation; @@ -33,10 +34,11 @@ public TorrentDownloadStation(ISharedFolderResolver sharedFolderResolver, ITorrentFileInfoReader torrentFileInfoReader, IHttpClient httpClient, IConfigService configService, + INamingConfigService namingConfigService, IDiskProvider diskProvider, IRemotePathMappingService remotePathMappingService, Logger logger) - : base(torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger) + : base(torrentFileInfoReader, httpClient, configService, namingConfigService, diskProvider, remotePathMappingService, logger) { _dsInfoProxy = dsInfoProxy; _dsTaskProxy = dsTaskProxy; diff --git a/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs b/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs index 0f318f323d..e8113a9085 100644 --- a/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs +++ b/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs @@ -9,6 +9,7 @@ using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; using NzbDrone.Core.Download.Clients.DownloadStation.Proxies; +using NzbDrone.Core.Organizer; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.RemotePathMappings; using NzbDrone.Core.Validation; @@ -30,11 +31,12 @@ public UsenetDownloadStation(ISharedFolderResolver sharedFolderResolver, IDownloadStationTaskProxy dsTaskProxy, IHttpClient httpClient, IConfigService configService, + INamingConfigService namingConfigService, IDiskProvider diskProvider, IRemotePathMappingService remotePathMappingService, Logger logger ) - : base(httpClient, configService, diskProvider, remotePathMappingService, logger) + : base(httpClient, configService, namingConfigService, diskProvider, remotePathMappingService, logger) { _dsInfoProxy = dsInfoProxy; _dsTaskProxy = dsTaskProxy; diff --git a/src/NzbDrone.Core/Download/Clients/Hadouken/Hadouken.cs b/src/NzbDrone.Core/Download/Clients/Hadouken/Hadouken.cs index 1ef2a3f5f5..47807958e5 100644 --- a/src/NzbDrone.Core/Download/Clients/Hadouken/Hadouken.cs +++ b/src/NzbDrone.Core/Download/Clients/Hadouken/Hadouken.cs @@ -9,6 +9,7 @@ using NzbDrone.Core.Configuration; using NzbDrone.Core.Download.Clients.Hadouken.Models; using NzbDrone.Core.MediaFiles.TorrentInfo; +using NzbDrone.Core.Organizer; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.RemotePathMappings; using NzbDrone.Core.Validation; @@ -23,10 +24,11 @@ public Hadouken(IHadoukenProxy proxy, ITorrentFileInfoReader torrentFileInfoReader, IHttpClient httpClient, IConfigService configService, + INamingConfigService namingConfigService, IDiskProvider diskProvider, IRemotePathMappingService remotePathMappingService, Logger logger) - : base(torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger) + : base(torrentFileInfoReader, httpClient, configService, namingConfigService, diskProvider, remotePathMappingService, logger) { _proxy = proxy; } diff --git a/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortex.cs b/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortex.cs index 1a59369338..330706b6b1 100644 --- a/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortex.cs +++ b/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortex.cs @@ -11,6 +11,7 @@ using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Validation; using NzbDrone.Core.RemotePathMappings; +using NzbDrone.Core.Organizer; namespace NzbDrone.Core.Download.Clients.NzbVortex { @@ -21,10 +22,11 @@ public class NzbVortex : UsenetClientBase public NzbVortex(INzbVortexProxy proxy, IHttpClient httpClient, IConfigService configService, + INamingConfigService namingConfigService, IDiskProvider diskProvider, IRemotePathMappingService remotePathMappingService, Logger logger) - : base(httpClient, configService, diskProvider, remotePathMappingService, logger) + : base(httpClient, configService, namingConfigService, diskProvider, remotePathMappingService, logger) { _proxy = proxy; } diff --git a/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs b/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs index aa07d6519c..beaabf2415 100644 --- a/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs +++ b/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs @@ -11,6 +11,7 @@ using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Validation; using NzbDrone.Core.RemotePathMappings; +using NzbDrone.Core.Organizer; namespace NzbDrone.Core.Download.Clients.Nzbget { @@ -23,10 +24,11 @@ public class Nzbget : UsenetClientBase public Nzbget(INzbgetProxy proxy, IHttpClient httpClient, IConfigService configService, + INamingConfigService namingConfigService, IDiskProvider diskProvider, IRemotePathMappingService remotePathMappingService, Logger logger) - : base(httpClient, configService, diskProvider, remotePathMappingService, logger) + : base(httpClient, configService, namingConfigService, diskProvider, remotePathMappingService, logger) { _proxy = proxy; } diff --git a/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs b/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs index 1d38046b61..9bc7d98b53 100644 --- a/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs +++ b/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs @@ -20,10 +20,11 @@ public class Pneumatic : DownloadClientBase public Pneumatic(IHttpClient httpClient, IConfigService configService, + INamingConfigService namingConfigService, IDiskProvider diskProvider, IRemotePathMappingService remotePathMappingService, Logger logger) - : base(configService, diskProvider, remotePathMappingService, logger) + : base(configService, namingConfigService, diskProvider, remotePathMappingService, logger) { _httpClient = httpClient; } @@ -43,7 +44,7 @@ public override string Download(RemoteMovie remoteMovie) // throw new NotSupportedException("Full season releases are not supported with Pneumatic."); //} - title = FileNameBuilder.CleanFileName(title); + title = CleanFileName(title); //Save to the Pneumatic directory (The user will need to ensure its accessible by XBMC) var nzbFile = Path.Combine(Settings.NzbFolder, title + ".nzb"); @@ -70,7 +71,7 @@ public override IEnumerable GetItems() continue; } - var title = FileNameBuilder.CleanFileName(Path.GetFileName(file)); + var title = CleanFileName(Path.GetFileName(file)); var historyItem = new DownloadClientItem { diff --git a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs index fd48381ef3..07e248befa 100644 --- a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs @@ -12,6 +12,7 @@ using System.Net; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.RemotePathMappings; +using NzbDrone.Core.Organizer; namespace NzbDrone.Core.Download.Clients.QBittorrent { @@ -23,10 +24,11 @@ public QBittorrent(IQBittorrentProxy proxy, ITorrentFileInfoReader torrentFileInfoReader, IHttpClient httpClient, IConfigService configService, + INamingConfigService namingConfigService, IDiskProvider diskProvider, IRemotePathMappingService remotePathMappingService, Logger logger) - : base(torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger) + : base(torrentFileInfoReader, httpClient, configService, namingConfigService, diskProvider, remotePathMappingService, logger) { _proxy = proxy; } diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs index 898f5ba2f3..f1fee1c68c 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs @@ -11,6 +11,7 @@ using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Validation; using NzbDrone.Core.RemotePathMappings; +using NzbDrone.Core.Organizer; namespace NzbDrone.Core.Download.Clients.Sabnzbd { @@ -21,10 +22,11 @@ public class Sabnzbd : UsenetClientBase public Sabnzbd(ISabnzbdProxy proxy, IHttpClient httpClient, IConfigService configService, + INamingConfigService namingConfigService, IDiskProvider diskProvider, IRemotePathMappingService remotePathMappingService, Logger logger) - : base(httpClient, configService, diskProvider, remotePathMappingService, logger) + : base(httpClient, configService, namingConfigService, diskProvider, remotePathMappingService, logger) { _proxy = proxy; } diff --git a/src/NzbDrone.Core/Download/Clients/Transmission/Transmission.cs b/src/NzbDrone.Core/Download/Clients/Transmission/Transmission.cs index 058023d0ca..3c2e25e367 100644 --- a/src/NzbDrone.Core/Download/Clients/Transmission/Transmission.cs +++ b/src/NzbDrone.Core/Download/Clients/Transmission/Transmission.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Text.RegularExpressions; using NzbDrone.Common.Disk; using NzbDrone.Common.Http; @@ -7,6 +7,7 @@ using FluentValidation.Results; using NzbDrone.Core.MediaFiles.TorrentInfo; using NzbDrone.Core.RemotePathMappings; +using NzbDrone.Core.Organizer; namespace NzbDrone.Core.Download.Clients.Transmission { @@ -16,10 +17,11 @@ public Transmission(ITransmissionProxy proxy, ITorrentFileInfoReader torrentFileInfoReader, IHttpClient httpClient, IConfigService configService, + INamingConfigService namingConfigService, IDiskProvider diskProvider, IRemotePathMappingService remotePathMappingService, Logger logger) - : base(proxy, torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger) + : base(proxy, torrentFileInfoReader, httpClient, configService, namingConfigService, diskProvider, remotePathMappingService, logger) { } diff --git a/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionBase.cs b/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionBase.cs index 4098955eac..ecc53a1d49 100644 --- a/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionBase.cs +++ b/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionBase.cs @@ -9,6 +9,7 @@ using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; using NzbDrone.Core.MediaFiles.TorrentInfo; +using NzbDrone.Core.Organizer; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.RemotePathMappings; using NzbDrone.Core.Validation; @@ -23,10 +24,11 @@ public TransmissionBase(ITransmissionProxy proxy, ITorrentFileInfoReader torrentFileInfoReader, IHttpClient httpClient, IConfigService configService, + INamingConfigService namingConfigService, IDiskProvider diskProvider, IRemotePathMappingService remotePathMappingService, Logger logger) - : base(torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger) + : base(torrentFileInfoReader, httpClient, configService, namingConfigService, diskProvider, remotePathMappingService, logger) { _proxy = proxy; } diff --git a/src/NzbDrone.Core/Download/Clients/Vuze/Vuze.cs b/src/NzbDrone.Core/Download/Clients/Vuze/Vuze.cs index dc3bb712e8..3c0abba99d 100644 --- a/src/NzbDrone.Core/Download/Clients/Vuze/Vuze.cs +++ b/src/NzbDrone.Core/Download/Clients/Vuze/Vuze.cs @@ -1,10 +1,11 @@ -using FluentValidation.Results; +using FluentValidation.Results; using NLog; using NzbDrone.Common.Disk; using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; using NzbDrone.Core.Download.Clients.Transmission; using NzbDrone.Core.MediaFiles.TorrentInfo; +using NzbDrone.Core.Organizer; using NzbDrone.Core.RemotePathMappings; namespace NzbDrone.Core.Download.Clients.Vuze @@ -17,10 +18,11 @@ public Vuze(ITransmissionProxy proxy, ITorrentFileInfoReader torrentFileInfoReader, IHttpClient httpClient, IConfigService configService, + INamingConfigService namingConfigService, IDiskProvider diskProvider, IRemotePathMappingService remotePathMappingService, Logger logger) - : base(proxy, torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger) + : base(proxy, torrentFileInfoReader, httpClient, configService, namingConfigService, diskProvider, remotePathMappingService, logger) { } diff --git a/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrent.cs b/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrent.cs index ed43b89fdc..3ea705dd2b 100644 --- a/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrent.cs @@ -15,6 +15,7 @@ using NzbDrone.Core.Parser.Model; using NzbDrone.Core.RemotePathMappings; using NzbDrone.Core.ThingiProvider; +using NzbDrone.Core.Organizer; namespace NzbDrone.Core.Download.Clients.RTorrent { @@ -27,11 +28,12 @@ public RTorrent(IRTorrentProxy proxy, ITorrentFileInfoReader torrentFileInfoReader, IHttpClient httpClient, IConfigService configService, + INamingConfigService namingConfigService, IDiskProvider diskProvider, IRemotePathMappingService remotePathMappingService, IRTorrentDirectoryValidator rTorrentDirectoryValidator, Logger logger) - : base(torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger) + : base(torrentFileInfoReader, httpClient, configService, namingConfigService, diskProvider, remotePathMappingService, logger) { _proxy = proxy; _rTorrentDirectoryValidator = rTorrentDirectoryValidator; diff --git a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs index d903a19f31..1994b2f106 100644 --- a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs @@ -13,6 +13,7 @@ using NzbDrone.Core.Parser.Model; using NzbDrone.Core.RemotePathMappings; using NzbDrone.Common.Cache; +using NzbDrone.Core.Organizer; namespace NzbDrone.Core.Download.Clients.UTorrent { @@ -26,10 +27,11 @@ public UTorrent(IUTorrentProxy proxy, ITorrentFileInfoReader torrentFileInfoReader, IHttpClient httpClient, IConfigService configService, + INamingConfigService namingConfigService, IDiskProvider diskProvider, IRemotePathMappingService remotePathMappingService, Logger logger) - : base(torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger) + : base(torrentFileInfoReader, httpClient, configService, namingConfigService, diskProvider, remotePathMappingService, logger) { _proxy = proxy; diff --git a/src/NzbDrone.Core/Download/DownloadClientBase.cs b/src/NzbDrone.Core/Download/DownloadClientBase.cs index 9db311c536..838ec64246 100644 --- a/src/NzbDrone.Core/Download/DownloadClientBase.cs +++ b/src/NzbDrone.Core/Download/DownloadClientBase.cs @@ -11,6 +11,7 @@ using NzbDrone.Core.RemotePathMappings; using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.Validation; +using NzbDrone.Core.Organizer; namespace NzbDrone.Core.Download { @@ -18,6 +19,7 @@ public abstract class DownloadClientBase : IDownloadClient where TSettings : IProviderConfig, new() { protected readonly IConfigService _configService; + protected readonly INamingConfigService _namingConfigService; protected readonly IDiskProvider _diskProvider; protected readonly IRemotePathMappingService _remotePathMappingService; protected readonly Logger _logger; @@ -39,12 +41,14 @@ public IEnumerable GetDefaultDefinitions() protected TSettings Settings => (TSettings)Definition.Settings; - protected DownloadClientBase(IConfigService configService, + protected DownloadClientBase(IConfigService configService, + INamingConfigService namingConfigService, IDiskProvider diskProvider, IRemotePathMappingService remotePathMappingService, Logger logger) { _configService = configService; + _namingConfigService = namingConfigService; _diskProvider = diskProvider; _remotePathMappingService = remotePathMappingService; _logger = logger; @@ -151,6 +155,13 @@ protected ValidationFailure TestFolder(string folder, string propertyName, bool return null; } + // proxy method to pass in our naming config + protected String CleanFileName(string name) + { + // get a fresh naming config each time, in case the user has made changes + NamingConfig namingConfig = _namingConfigService.GetConfig(); + return FileNameBuilder.CleanFileName(name, namingConfig); + } } } diff --git a/src/NzbDrone.Core/Download/TorrentClientBase.cs b/src/NzbDrone.Core/Download/TorrentClientBase.cs index 52415d552f..d5ca429261 100644 --- a/src/NzbDrone.Core/Download/TorrentClientBase.cs +++ b/src/NzbDrone.Core/Download/TorrentClientBase.cs @@ -25,10 +25,11 @@ public abstract class TorrentClientBase : DownloadClientBase : DownloadClientBase + @@ -1300,4 +1301,4 @@ --> - \ No newline at end of file + diff --git a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs index 8bbdd639f0..73cf999cde 100644 --- a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs +++ b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs @@ -248,8 +248,9 @@ public string GetMovieFolder(Movie movie, NamingConfig namingConfig = null) { AddMovieFileTokens(tokenHandlers, new MovieFile { SceneName = $"{movie.Title} {movie.Year}", RelativePath = $"{movie.Title} {movie.Year}"}); } - - return CleanFolderName(ReplaceTokens(namingConfig.MovieFolderFormat, tokenHandlers, namingConfig)); + + string name = ReplaceTokens(namingConfig.MovieFolderFormat, tokenHandlers, namingConfig); + return CleanFolderName(name, namingConfig); } public static string CleanTitle(string title) @@ -283,11 +284,14 @@ public static string TitleThe(string title) return title.Trim(); } - public static string CleanFileName(string name, bool replace = true) + public static string CleanFileName(string name, NamingConfig namingConfig) { + bool replace = namingConfig.ReplaceIllegalCharacters; + var colonReplacementFormat = namingConfig.ColonReplacementFormat.GetFormatString(); + string result = name; string[] badCharacters = { "\\", "/", "<", ">", "?", "*", ":", "|", "\"" }; - string[] goodCharacters = { "+", "+", "", "", "!", "-", "", "", "" }; + string[] goodCharacters = { "+", "+", "", "", "!", "-", colonReplacementFormat, "", "" }; for (int i = 0; i < badCharacters.Length; i++) { @@ -297,12 +301,12 @@ public static string CleanFileName(string name, bool replace = true) return result.Trim(); } - public static string CleanFolderName(string name) + public static string CleanFolderName(string name, NamingConfig namingConfig) { name = FileNameCleanupRegex.Replace(name, match => match.Captures[0].Value[0].ToString()); name = name.Trim(' ', '.'); - return CleanFileName(name); + return CleanFileName(name, namingConfig); } private void AddMovieTokens(Dictionary> tokenHandlers, Movie movie) @@ -557,7 +561,7 @@ private string ReplaceToken(Match match, Dictionary -
- - -
-
-
-
-
+
+ + +
+
+
+
+ +
+
+ + + + + + + +
+ +
+
+
+
@@ -80,71 +101,6 @@
- {{!--
- - -
- - -
- -
-
- -
- - -
-
-
-
--}} - - {{!--
- - -
- - -
- -
-
- -
- - -
-
-
-
-
--}} -
@@ -173,43 +129,6 @@
- {{!--
- - -
-
- -
- - -
-
-
-
--}} - - {{!--
-
- - -
- -
-
-
--}} -
@@ -218,37 +137,6 @@
- {{!--
- - -
-

-
-
- -
- - -
-

-
-
- -
- -
-

-
-
- -
- - -
-

-
-
--}} -
@@ -256,12 +144,4 @@

- - {{!--
- - -
-

-
-
--}}