From 38932d82dbbb84c3627e0ae3d0c950189a6b3a49 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sat, 14 Apr 2018 23:03:32 -0400 Subject: [PATCH] Added: Enable Download Client Priorities (#2699) Fixes #229 --- .../NzbVortexTests/NzbVortexFixture.cs | 2 +- .../NzbgetTests/NzbgetFixture.cs | 2 +- .../QBittorrentTests/QBittorrentFixture.cs | 39 +++++++++++ .../SabnzbdTests/SabnzbdFixture.cs | 2 +- .../Download/Clients/Deluge/Deluge.cs | 16 +++++ .../Download/Clients/Deluge/DelugeSettings.cs | 10 ++- .../Download/Clients/NzbVortex/NzbVortex.cs | 2 +- .../Clients/NzbVortex/NzbVortexSettings.cs | 14 ++-- .../Download/Clients/Nzbget/Nzbget.cs | 2 +- .../Download/Clients/Nzbget/NzbgetSettings.cs | 12 ++-- .../Clients/QBittorrent/QBittorrent.cs | 70 ++++++++++++++++++- .../QBittorrent/QBittorrentPreferences.cs | 5 +- .../QBittorrent/QBittorrentSettings.cs | 10 ++- .../Download/Clients/Sabnzbd/Sabnzbd.cs | 5 +- .../Clients/Sabnzbd/SabnzbdSettings.cs | 12 ++-- .../Clients/Transmission/TransmissionBase.cs | 18 +++++ .../Transmission/TransmissionSettings.cs | 10 ++- .../Download/Clients/rTorrent/RTorrent.cs | 8 ++- .../Clients/rTorrent/RTorrentSettings.cs | 8 ++- .../Download/Clients/uTorrent/UTorrent.cs | 16 ++--- .../Clients/uTorrent/UTorrentSettings.cs | 10 +-- src/NzbDrone.Core/Movies/Movie.cs | 18 +++++ src/UI/Form/CheckboxTemplate.hbs | 2 +- src/UI/Form/SelectTemplate.hbs | 2 +- 24 files changed, 242 insertions(+), 53 deletions(-) diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbVortexTests/NzbVortexFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbVortexTests/NzbVortexFixture.cs index ea412e73d..3673f34b6 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbVortexTests/NzbVortexFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbVortexTests/NzbVortexFixture.cs @@ -33,7 +33,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbVortexTests Port = 2222, ApiKey = "1234-ABCD", TvCategory = "tv", - RecentTvPriority = (int)NzbgetPriority.High + RecentMoviePriority = (int)NzbgetPriority.High }; _queued = new NzbVortexQueueItem diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetTests/NzbgetFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetTests/NzbgetFixture.cs index 6b03660c6..d5bc1eda3 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetTests/NzbgetFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetTests/NzbgetFixture.cs @@ -31,7 +31,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests Username = "admin", Password = "pass", MovieCategory = "movie", - RecentTvPriority = (int)NzbgetPriority.High + RecentMoviePriority = (int)NzbgetPriority.High }; _queued = new NzbgetQueueItem diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs index d7ff95b83..245dbb4c7 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs @@ -89,6 +89,12 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests }); } + protected void GivenHighPriority() + { + Subject.Definition.Settings.As().OlderMoviePriority = (int) QBittorrentPriority.First; + Subject.Definition.Settings.As().RecentMoviePriority = (int) QBittorrentPriority.First; + } + protected void GivenMaxRatio(float maxRatio, bool removeOnMaxRatio = true) { Mocker.GetMock() @@ -265,6 +271,39 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests id.Should().Be(expectedHash); } + [Test] + public void Download_should_set_top_priority() + { + GivenHighPriority(); + GivenSuccessfulDownload(); + + var remoteMovie = CreateRemoteMovie(); + + var id = Subject.Download(remoteMovie); + + Mocker.GetMock() + .Verify(v => v.MoveTorrentToTopInQueue(It.IsAny(), It.IsAny()), Times.Once()); + } + + [Test] + public void Download_should_not_fail_if_top_priority_not_available() + { + GivenHighPriority(); + GivenSuccessfulDownload(); + + Mocker.GetMock() + .Setup(v => v.MoveTorrentToTopInQueue(It.IsAny(), It.IsAny())) + .Throws(new HttpException(new HttpResponse(new HttpRequest("http://me.local/"), new HttpHeader(), new byte[0], System.Net.HttpStatusCode.Forbidden))); + + var remoteMovie = CreateRemoteMovie(); + + var id = Subject.Download(remoteMovie); + + id.Should().NotBeNullOrEmpty(); + + ExceptionVerification.ExpectedWarns(1); + } + [Test] public void should_return_status_with_outputdirs() { diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs index 181d827b8..1b72fb9f7 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs @@ -37,7 +37,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests Username = "admin", Password = "pass", MovieCategory = "movie", - RecentTvPriority = (int)SabnzbdPriority.High + RecentMoviePriority = (int)SabnzbdPriority.High }; _queued = new SabnzbdQueue { diff --git a/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs b/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs index b5ca8c7f7..55b71345e 100644 --- a/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs +++ b/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs @@ -42,6 +42,14 @@ namespace NzbDrone.Core.Download.Clients.Deluge _proxy.SetTorrentConfiguration(actualHash, "remove_at_ratio", false, Settings); + var isRecentMovie = remoteMovie.Movie.IsRecentMovie; + + if (isRecentMovie && Settings.RecentMoviePriority == (int)DelugePriority.First || + !isRecentMovie && Settings.OlderMoviePriority == (int)DelugePriority.First) + { + _proxy.MoveTorrentToTopInQueue(actualHash, Settings); + } + return actualHash.ToUpper(); } @@ -56,6 +64,14 @@ namespace NzbDrone.Core.Download.Clients.Deluge _proxy.SetTorrentConfiguration(actualHash, "remove_at_ratio", false, Settings); + var isRecentMovie = remoteMovie.Movie.IsRecentMovie; + + if (isRecentMovie && Settings.RecentMoviePriority == (int)DelugePriority.First || + !isRecentMovie && Settings.OlderMoviePriority == (int)DelugePriority.First) + { + _proxy.MoveTorrentToTopInQueue(actualHash, Settings); + } + return actualHash.ToUpper(); } diff --git a/src/NzbDrone.Core/Download/Clients/Deluge/DelugeSettings.cs b/src/NzbDrone.Core/Download/Clients/Deluge/DelugeSettings.cs index 2ced9ab5f..ad8794314 100644 --- a/src/NzbDrone.Core/Download/Clients/Deluge/DelugeSettings.cs +++ b/src/NzbDrone.Core/Download/Clients/Deluge/DelugeSettings.cs @@ -1,4 +1,4 @@ -using FluentValidation; +using FluentValidation; using NzbDrone.Core.Annotations; using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.Validation; @@ -43,7 +43,13 @@ namespace NzbDrone.Core.Download.Clients.Deluge [FieldDefinition(4, Label = "Category", Type = FieldType.Textbox, HelpText = "Adding a category specific to Radarr avoids conflicts with unrelated downloads, but it's optional")] public string MovieCategory { get; set; } - [FieldDefinition(5, Label = "Use SSL", Type = FieldType.Checkbox)] + [FieldDefinition(5, Label = "Recent Priority", Type = FieldType.Select, SelectOptions = typeof(DelugePriority), HelpText = "Priority to use when grabbing movies that released within the last 21 days")] + public int RecentMoviePriority { get; set; } + + [FieldDefinition(6, Label = "Older Priority", Type = FieldType.Select, SelectOptions = typeof(DelugePriority), HelpText = "Priority to use when grabbing movies that released over 21 days ago")] + public int OlderMoviePriority { get; set; } + + [FieldDefinition(7, Label = "Use SSL", Type = FieldType.Checkbox)] public bool UseSsl { get; set; } public NzbDroneValidationResult Validate() diff --git a/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortex.cs b/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortex.cs index 1753aabda..1a5936933 100644 --- a/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortex.cs +++ b/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortex.cs @@ -31,7 +31,7 @@ namespace NzbDrone.Core.Download.Clients.NzbVortex protected override string AddFromNzbFile(RemoteMovie remoteMovie, string filename, byte[] fileContents) { - var priority = Settings.RecentTvPriority; + var priority = remoteMovie.Movie.IsRecentMovie ? Settings.RecentMoviePriority : Settings.OlderMoviePriority; var response = _proxy.DownloadNzb(fileContents, filename, priority, Settings); diff --git a/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortexSettings.cs b/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortexSettings.cs index 8e956cbd9..20a2bece4 100644 --- a/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortexSettings.cs +++ b/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortexSettings.cs @@ -1,4 +1,4 @@ -using FluentValidation; +using FluentValidation; using NzbDrone.Core.Annotations; using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.Validation; @@ -30,8 +30,8 @@ namespace NzbDrone.Core.Download.Clients.NzbVortex Host = "localhost"; Port = 4321; TvCategory = "Movies"; - RecentTvPriority = (int)NzbVortexPriority.Normal; - OlderTvPriority = (int)NzbVortexPriority.Normal; + RecentMoviePriority = (int)NzbVortexPriority.Normal; + OlderMoviePriority = (int)NzbVortexPriority.Normal; } [FieldDefinition(0, Label = "Host", Type = FieldType.Textbox)] @@ -46,11 +46,11 @@ namespace NzbDrone.Core.Download.Clients.NzbVortex [FieldDefinition(3, Label = "Group", Type = FieldType.Textbox, HelpText = "Adding a category specific to Radarr avoids conflicts with unrelated downloads, but it's optional")] public string TvCategory { get; set; } - [FieldDefinition(4, Label = "Recent Priority", Type = FieldType.Select, SelectOptions = typeof(NzbVortexPriority), HelpText = "Priority to use when grabbing releases that aired within the last 14 days")] - public int RecentTvPriority { get; set; } + [FieldDefinition(4, Label = "Recent Priority", Type = FieldType.Select, SelectOptions = typeof(NzbVortexPriority), HelpText = "Priority to use when grabbing movies that released within the last 21 days")] + public int RecentMoviePriority { get; set; } - [FieldDefinition(5, Label = "Older Priority", Type = FieldType.Select, SelectOptions = typeof(NzbVortexPriority), HelpText = "Priority to use when grabbing releases that aired over 14 days ago")] - public int OlderTvPriority { get; set; } + [FieldDefinition(5, Label = "Older Priority", Type = FieldType.Select, SelectOptions = typeof(NzbVortexPriority), HelpText = "Priority to use when grabbing movies that released over 21 days ago")] + public int OlderMoviePriority { get; set; } public NzbDroneValidationResult Validate() { diff --git a/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs b/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs index 8e697bf88..aa07d6519 100644 --- a/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs +++ b/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs @@ -35,7 +35,7 @@ namespace NzbDrone.Core.Download.Clients.Nzbget { var category = Settings.MovieCategory; - var priority = Settings.RecentTvPriority; + var priority = remoteMovie.Movie.IsRecentMovie ? Settings.RecentMoviePriority : Settings.OlderMoviePriority; var addpaused = Settings.AddPaused; diff --git a/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetSettings.cs b/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetSettings.cs index d0a8ee0a6..a377e72cf 100644 --- a/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetSettings.cs +++ b/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetSettings.cs @@ -29,8 +29,8 @@ namespace NzbDrone.Core.Download.Clients.Nzbget MovieCategory = "Movies"; Username = "nzbget"; Password = "tegbzn6789"; - RecentTvPriority = (int)NzbgetPriority.Normal; - OlderTvPriority = (int)NzbgetPriority.Normal; + RecentMoviePriority = (int)NzbgetPriority.Normal; + OlderMoviePriority = (int)NzbgetPriority.Normal; } [FieldDefinition(0, Label = "Host", Type = FieldType.Textbox)] @@ -48,11 +48,11 @@ namespace NzbDrone.Core.Download.Clients.Nzbget [FieldDefinition(4, Label = "Category", Type = FieldType.Textbox, HelpText = "Adding a category specific to Radarr avoids conflicts with unrelated downloads, but it's optional")] public string MovieCategory { get; set; } - [FieldDefinition(5, Label = "Recent Priority", Type = FieldType.Select, SelectOptions = typeof(NzbgetPriority), HelpText = "Priority to use when grabbing releases that aired within the last 14 days")] - public int RecentTvPriority { get; set; } + [FieldDefinition(5, Label = "Recent Priority", Type = FieldType.Select, SelectOptions = typeof(NzbgetPriority), HelpText = "Priority to use when grabbing movies that released within the last 21 days")] + public int RecentMoviePriority { get; set; } - [FieldDefinition(6, Label = "Older Priority", Type = FieldType.Select, SelectOptions = typeof(NzbgetPriority), HelpText = "Priority to use when grabbing releases that aired over 14 days ago")] - public int OlderTvPriority { get; set; } + [FieldDefinition(6, Label = "Older Priority", Type = FieldType.Select, SelectOptions = typeof(NzbgetPriority), HelpText = "Priority to use when grabbing movies that released over 21 days ago")] + public int OlderMoviePriority { get; set; } [FieldDefinition(7, Label = "Use SSL", Type = FieldType.Checkbox)] public bool UseSsl { get; set; } diff --git a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs index c1b10f3a1..fd48381ef 100644 --- a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs @@ -40,6 +40,14 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent _proxy.SetTorrentLabel(hash.ToLower(), Settings.MovieCategory, Settings); } + var isRecentMovie = remoteMovie.Movie.IsRecentMovie; + + if (isRecentMovie && Settings.RecentMoviePriority == (int)QBittorrentPriority.First || + !isRecentMovie && Settings.OlderMoviePriority == (int)QBittorrentPriority.First) + { + _proxy.MoveTorrentToTopInQueue(hash.ToLower(), Settings); + } + SetInitialState(hash.ToLower()); return hash; @@ -49,9 +57,31 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent { _proxy.AddTorrentFromFile(filename, fileContent, Settings); - if (Settings.MovieCategory.IsNotNullOrWhiteSpace()) + try { - _proxy.SetTorrentLabel(hash.ToLower(), Settings.MovieCategory, Settings); + if (Settings.MovieCategory.IsNotNullOrWhiteSpace()) + { + _proxy.SetTorrentLabel(hash.ToLower(), Settings.MovieCategory, Settings); + } + } + catch (Exception ex) + { + _logger.Warn(ex, "Failed to set the torrent label for {0}.", filename); + } + + try + { + var isRecentMovie = remoteMovie.Movie.IsRecentMovie; + + if (isRecentMovie && Settings.RecentMoviePriority == (int)QBittorrentPriority.First || + !isRecentMovie && Settings.OlderMoviePriority == (int)QBittorrentPriority.First) + { + _proxy.MoveTorrentToTopInQueue(hash.ToLower(), Settings); + } + } + catch (Exception ex) + { + _logger.Warn(ex, "Failed to set the torrent priority for {0}.", filename); } SetInitialState(hash); @@ -165,6 +195,7 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent { failures.AddIfNotNull(TestConnection()); if (failures.Any()) return; + failures.AddIfNotNull(TestPrioritySupport()); failures.AddIfNotNull(TestGetTorrents()); } @@ -241,6 +272,41 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent return null; } + private ValidationFailure TestPrioritySupport() + { + var recentPriorityDefault = Settings.RecentMoviePriority == (int)QBittorrentPriority.Last; + var olderPriorityDefault = Settings.OlderMoviePriority == (int)QBittorrentPriority.Last; + + if (olderPriorityDefault && recentPriorityDefault) + { + return null; + } + + try + { + var config = _proxy.GetConfig(Settings); + + if (!config.QueueingEnabled) + { + if (!recentPriorityDefault) + { + return new NzbDroneValidationFailure(nameof(Settings.RecentMoviePriority), "Queueing not enabled") { DetailedDescription = "Torrent Queueing is not enabled in your qBittorrent settings. Enable it in qBittorrent or select 'Last' as priority." }; + } + else if (!olderPriorityDefault) + { + return new NzbDroneValidationFailure(nameof(Settings.OlderMoviePriority), "Queueing not enabled") { DetailedDescription = "Torrent Queueing is not enabled in your qBittorrent settings. Enable it in qBittorrent or select 'Last' as priority." }; + } + } + } + catch (Exception ex) + { + _logger.Error(ex, "Failed to test qBittorrent"); + return new NzbDroneValidationFailure(String.Empty, "Unknown exception: " + ex.Message); + } + + return null; + } + private ValidationFailure TestGetTorrents() { try diff --git a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentPreferences.cs b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentPreferences.cs index 9fddb1116..2f647f5c9 100644 --- a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentPreferences.cs +++ b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentPreferences.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +using Newtonsoft.Json; namespace NzbDrone.Core.Download.Clients.QBittorrent { @@ -16,5 +16,8 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent [JsonProperty(PropertyName = "max_ratio_act")] public bool RemoveOnMaxRatio { get; set; } // Action performed when a torrent reaches the maximum share ratio. [false = pause, true = remove] + + [JsonProperty(PropertyName = "queueing_enabled")] + public bool QueueingEnabled { get; set; } = true; } } diff --git a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentSettings.cs b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentSettings.cs index db0ab9c76..95a4cbbf5 100644 --- a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentSettings.cs +++ b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentSettings.cs @@ -40,10 +40,16 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent [FieldDefinition(4, Label = "Category", Type = FieldType.Textbox, HelpText = "Adding a category specific to Radarr avoids conflicts with unrelated downloads, but it's optional")] public string MovieCategory { get; set; } - [FieldDefinition(5, Label = "Initial State", Type = FieldType.Select, SelectOptions = typeof(QBittorrentState), HelpText = "Initial state for torrents added to qBittorrent")] + [FieldDefinition(5, Label = "Recent Priority", Type = FieldType.Select, SelectOptions = typeof(QBittorrentPriority), HelpText = "Priority to use when grabbing movies that released within the last 21 days")] + public int RecentMoviePriority { get; set; } + + [FieldDefinition(6, Label = "Older Priority", Type = FieldType.Select, SelectOptions = typeof(QBittorrentPriority), HelpText = "Priority to use when grabbing movies that released over 21 days ago")] + public int OlderMoviePriority { get; set; } + + [FieldDefinition(7, Label = "Initial State", Type = FieldType.Select, SelectOptions = typeof(QBittorrentState), HelpText = "Initial state for torrents added to qBittorrent")] public int InitialState { get; set; } - [FieldDefinition(6, Label = "Use SSL", Type = FieldType.Checkbox, HelpText = "Use a secure connection. See Options -> Web UI -> 'Use HTTPS instead of HTTP' in qBittorrent.")] + [FieldDefinition(8, Label = "Use SSL", Type = FieldType.Checkbox, HelpText = "Use a secure connection. See Options -> Web UI -> 'Use HTTPS instead of HTTP' in qBittorrent.")] public bool UseSsl { get; set; } public NzbDroneValidationResult Validate() diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs index 8ed22975b..898f5ba2f 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs @@ -35,7 +35,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd protected override string AddFromNzbFile(RemoteMovie remoteMovie, string filename, byte[] fileContents) { var category = Settings.MovieCategory; - var priority = Settings.RecentTvPriority; + var priority = remoteMovie.Movie.IsRecentMovie ? Settings.RecentMoviePriority : Settings.OlderMoviePriority; var response = _proxy.DownloadNzb(fileContents, filename, category, priority, Settings); @@ -81,7 +81,8 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd queueItem.CanBeRemoved = true; queueItem.CanMoveFiles = true; - if (sabQueue.Paused || sabQueueItem.Status == SabnzbdDownloadStatus.Paused) + if ((sabQueue.Paused && sabQueueItem.Priority != SabnzbdPriority.Force) || + sabQueueItem.Status == SabnzbdDownloadStatus.Paused) { queueItem.Status = DownloadItemStatus.Paused; diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdSettings.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdSettings.cs index 6c47b6e73..64ab3d3df 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdSettings.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdSettings.cs @@ -39,8 +39,8 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd Host = "localhost"; Port = 8080; MovieCategory = "movies"; - RecentTvPriority = (int)SabnzbdPriority.Default; - OlderTvPriority = (int)SabnzbdPriority.Default; + RecentMoviePriority = (int)SabnzbdPriority.Default; + OlderMoviePriority = (int)SabnzbdPriority.Default; } [FieldDefinition(0, Label = "Host", Type = FieldType.Textbox)] @@ -61,11 +61,11 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd [FieldDefinition(5, Label = "Category", Type = FieldType.Textbox, HelpText = "Adding a category specific to Radarr avoids conflicts with unrelated downloads, but it's optional")] public string MovieCategory { get; set; } - [FieldDefinition(6, Label = "Recent Priority", Type = FieldType.Select, SelectOptions = typeof(SabnzbdPriority), HelpText = "Priority to use when grabbing releases that aired within the last 14 days")] - public int RecentTvPriority { get; set; } + [FieldDefinition(6, Label = "Recent Priority", Type = FieldType.Select, SelectOptions = typeof(SabnzbdPriority), HelpText = "Priority to use when grabbing movies that released within the last 21 days")] + public int RecentMoviePriority { get; set; } - [FieldDefinition(7, Label = "Older Priority", Type = FieldType.Select, SelectOptions = typeof(SabnzbdPriority), HelpText = "Priority to use when grabbing releases that aired over 14 days ago")] - public int OlderTvPriority { get; set; } + [FieldDefinition(7, Label = "Older Priority", Type = FieldType.Select, SelectOptions = typeof(SabnzbdPriority), HelpText = "Priority to use when grabbing movies that released over 21 days ago")] + public int OlderMoviePriority { get; set; } [FieldDefinition(8, Label = "Use SSL", Type = FieldType.Checkbox)] public bool UseSsl { get; set; } diff --git a/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionBase.cs b/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionBase.cs index a0af58dfd..4098955ea 100644 --- a/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionBase.cs +++ b/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionBase.cs @@ -139,12 +139,30 @@ namespace NzbDrone.Core.Download.Clients.Transmission protected override string AddFromMagnetLink(RemoteMovie remoteMovie, string hash, string magnetLink) { _proxy.AddTorrentFromUrl(magnetLink, GetDownloadDirectory(), Settings); + + var isRecentMovie = remoteMovie.Movie.IsRecentMovie; + + if (isRecentMovie && Settings.RecentMoviePriority == (int)TransmissionPriority.First || + !isRecentMovie && Settings.OlderMoviePriority == (int)TransmissionPriority.First) + { + _proxy.MoveTorrentToTopInQueue(hash, Settings); + } + return hash; } protected override string AddFromTorrentFile(RemoteMovie remoteMovie, string hash, string filename, byte[] fileContent) { _proxy.AddTorrentFromData(fileContent, GetDownloadDirectory(), Settings); + + var isRecentMovie = remoteMovie.Movie.IsRecentMovie; + + if (isRecentMovie && Settings.RecentMoviePriority == (int)TransmissionPriority.First || + !isRecentMovie && Settings.OlderMoviePriority == (int)TransmissionPriority.First) + { + _proxy.MoveTorrentToTopInQueue(hash, Settings); + } + return hash; } diff --git a/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionSettings.cs b/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionSettings.cs index 70b536c73..dbd01fda4 100644 --- a/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionSettings.cs +++ b/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionSettings.cs @@ -1,4 +1,4 @@ -using System.Text.RegularExpressions; +using System.Text.RegularExpressions; using FluentValidation; using NzbDrone.Core.Annotations; using NzbDrone.Core.ThingiProvider; @@ -57,7 +57,13 @@ namespace NzbDrone.Core.Download.Clients.Transmission [FieldDefinition(6, Label = "Directory", Type = FieldType.Textbox, Advanced = true, HelpText = "Optional location to put downloads in, leave blank to use the default Transmission location")] public string MovieDirectory { get; set; } - [FieldDefinition(7, Label = "Use SSL", Type = FieldType.Checkbox)] + [FieldDefinition(7, Label = "Recent Priority", Type = FieldType.Select, SelectOptions = typeof(TransmissionPriority), HelpText = "Priority to use when grabbing movies that released within the last 21 days")] + public int RecentMoviePriority { get; set; } + + [FieldDefinition(8, Label = "Older Priority", Type = FieldType.Select, SelectOptions = typeof(TransmissionPriority), HelpText = "Priority to use when grabbing movies that released over 21 days ago")] + public int OlderMoviePriority { get; set; } + + [FieldDefinition(9, Label = "Use SSL", Type = FieldType.Checkbox)] public bool UseSsl { get; set; } public NzbDroneValidationResult Validate() diff --git a/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrent.cs b/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrent.cs index c2ad6343d..ed43b89fd 100644 --- a/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrent.cs @@ -39,7 +39,9 @@ namespace NzbDrone.Core.Download.Clients.RTorrent protected override string AddFromMagnetLink(RemoteMovie remoteMovie, string hash, string magnetLink) { - _proxy.AddTorrentFromUrl(magnetLink, Settings.MovieCategory, RTorrentPriority.Normal, Settings.MovieDirectory, Settings); + var priority = (RTorrentPriority)(remoteMovie.Movie.IsRecentMovie ? Settings.RecentMoviePriority : Settings.OlderMoviePriority); + + _proxy.AddTorrentFromUrl(magnetLink, Settings.MovieCategory, priority, Settings.MovieDirectory, Settings); var tries = 10; var retryDelay = 500; @@ -57,7 +59,9 @@ namespace NzbDrone.Core.Download.Clients.RTorrent protected override string AddFromTorrentFile(RemoteMovie remoteMovie, string hash, string filename, byte[] fileContent) { - _proxy.AddTorrentFromFile(filename, fileContent, Settings.MovieCategory, RTorrentPriority.Normal, Settings.MovieDirectory, Settings); + var priority = (RTorrentPriority)(remoteMovie.Movie.IsRecentMovie ? Settings.RecentMoviePriority : Settings.OlderMoviePriority); + + _proxy.AddTorrentFromFile(filename, fileContent, Settings.MovieCategory, priority, Settings.MovieDirectory, Settings); var tries = 10; var retryDelay = 500; diff --git a/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrentSettings.cs b/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrentSettings.cs index 495f9b499..8dd886a09 100644 --- a/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrentSettings.cs +++ b/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrentSettings.cs @@ -1,4 +1,4 @@ -using FluentValidation; +using FluentValidation; using NzbDrone.Core.Annotations; using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.Validation; @@ -53,6 +53,12 @@ namespace NzbDrone.Core.Download.Clients.RTorrent [FieldDefinition(7, Label = "Directory", Type = FieldType.Textbox, Advanced = true, HelpText = "Optional location to put downloads in, leave blank to use the default rTorrent location")] public string MovieDirectory { get; set; } + [FieldDefinition(8, Label = "Recent Priority", Type = FieldType.Select, SelectOptions = typeof(RTorrentPriority), HelpText = "Priority to use when grabbing movies that released within the last 21 days")] + public int RecentMoviePriority { get; set; } + + [FieldDefinition(9, Label = "Older Priority", Type = FieldType.Select, SelectOptions = typeof(RTorrentPriority), HelpText = "Priority to use when grabbing movies that released over 21 days ago")] + public int OlderMoviePriority { get; set; } + public NzbDroneValidationResult Validate() { return new NzbDroneValidationResult(Validator.Validate(this)); diff --git a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs index 97e6509bb..d903a19f3 100644 --- a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs @@ -41,13 +41,13 @@ namespace NzbDrone.Core.Download.Clients.UTorrent _proxy.AddTorrentFromUrl(magnetLink, Settings); _proxy.SetTorrentLabel(hash, Settings.MovieCategory, Settings); - /*var isRecentEpisode = remoteEpisode.IsRecentEpisode(); + var isRecentMovie = remoteMovie.Movie.IsRecentMovie; - if (isRecentEpisode && Settings.RecentTvPriority == (int)UTorrentPriority.First || - !isRecentEpisode && Settings.OlderTvPriority == (int)UTorrentPriority.First) + if (isRecentMovie && Settings.RecentMoviePriority == (int)UTorrentPriority.First || + !isRecentMovie && Settings.OlderMoviePriority == (int)UTorrentPriority.First) { _proxy.MoveTorrentToTopInQueue(hash, Settings); - }*/ + } _proxy.SetState(hash, (UTorrentState)Settings.IntialState, Settings); @@ -59,13 +59,13 @@ namespace NzbDrone.Core.Download.Clients.UTorrent _proxy.AddTorrentFromFile(filename, fileContent, Settings); _proxy.SetTorrentLabel(hash, Settings.MovieCategory, Settings); - /*var isRecentEpisode = remoteEpisode.IsRecentEpisode(); + var isRecentMovie = remoteMovie.Movie.IsRecentMovie; - if (isRecentEpisode && Settings.RecentTvPriority == (int)UTorrentPriority.First || - !isRecentEpisode && Settings.OlderTvPriority == (int)UTorrentPriority.First) + if (isRecentMovie && Settings.RecentMoviePriority == (int)UTorrentPriority.First || + !isRecentMovie && Settings.OlderMoviePriority == (int)UTorrentPriority.First) { _proxy.MoveTorrentToTopInQueue(hash, Settings); - }*/ + } _proxy.SetState(hash, (UTorrentState)Settings.IntialState, Settings); diff --git a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentSettings.cs b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentSettings.cs index ae21c4a00..2b772ddcf 100644 --- a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentSettings.cs +++ b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentSettings.cs @@ -1,4 +1,4 @@ -using FluentValidation; +using FluentValidation; using NzbDrone.Core.Annotations; using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.Validation; @@ -41,11 +41,11 @@ namespace NzbDrone.Core.Download.Clients.UTorrent [FieldDefinition(4, Label = "Category", Type = FieldType.Textbox, HelpText = "Adding a category specific to Radarr avoids conflicts with unrelated downloads, but it's optional")] public string MovieCategory { get; set; } - [FieldDefinition(5, Label = "Recent Priority", Type = FieldType.Select, SelectOptions = typeof(UTorrentPriority), HelpText = "Priority to use when grabbing releases that aired within the last 14 days")] - public int RecentTvPriority { get; set; } + [FieldDefinition(5, Label = "Recent Priority", Type = FieldType.Select, SelectOptions = typeof(UTorrentPriority), HelpText = "Priority to use when grabbing movies that released within the last 21 days")] + public int RecentMoviePriority { get; set; } - [FieldDefinition(6, Label = "Older Priority", Type = FieldType.Select, SelectOptions = typeof(UTorrentPriority), HelpText = "Priority to use when grabbing releases that aired over 14 days ago")] - public int OlderTvPriority { get; set; } + [FieldDefinition(6, Label = "Older Priority", Type = FieldType.Select, SelectOptions = typeof(UTorrentPriority), HelpText = "Priority to use when grabbing movies that released over 21 days ago")] + public int OlderMoviePriority { get; set; } [FieldDefinition(7, Label = "Initial State", Type = FieldType.Select, SelectOptions = typeof(UTorrentState), HelpText = "Initial state for torrents added to uTorrent")] public int IntialState { get; set; } diff --git a/src/NzbDrone.Core/Movies/Movie.cs b/src/NzbDrone.Core/Movies/Movie.cs index ccc0a2981..7d06c53d9 100644 --- a/src/NzbDrone.Core/Movies/Movie.cs +++ b/src/NzbDrone.Core/Movies/Movie.cs @@ -61,6 +61,24 @@ namespace NzbDrone.Core.Movies public string YouTubeTrailerId{ get; set; } public string Studio { get; set; } + public bool IsRecentMovie + { + get + { + if (PhysicalRelease.HasValue) + { + return PhysicalRelease.Value >= DateTime.UtcNow.AddDays(-21); + } + + if (InCinemas.HasValue) + { + return InCinemas.Value >= DateTime.UtcNow.AddDays(-120); + } + + return true; + } + } + public bool HasFile => MovieFileId > 0; public string FolderName() diff --git a/src/UI/Form/CheckboxTemplate.hbs b/src/UI/Form/CheckboxTemplate.hbs index d3803ab70..526804714 100644 --- a/src/UI/Form/CheckboxTemplate.hbs +++ b/src/UI/Form/CheckboxTemplate.hbs @@ -4,7 +4,7 @@