diff --git a/src/NzbDrone.Api/Queue/QueueActionModule.cs b/src/NzbDrone.Api/Queue/QueueActionModule.cs index 485d5fde8..1bea3116d 100644 --- a/src/NzbDrone.Api/Queue/QueueActionModule.cs +++ b/src/NzbDrone.Api/Queue/QueueActionModule.cs @@ -60,7 +60,7 @@ namespace NzbDrone.Api.Queue throw new BadRequestException(); } - downloadClient.RemoveItem(trackedDownload.DownloadItem.DownloadId); + downloadClient.RemoveItem(trackedDownload.DownloadItem.DownloadId, true); return new object().AsResponse(); } diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/PneumaticProviderFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/PneumaticProviderFixture.cs index 95a465225..d3de3c1d9 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/PneumaticProviderFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/PneumaticProviderFixture.cs @@ -82,7 +82,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests [Test] public void should_throw_item_is_removed() { - Assert.Throws(() => Subject.RemoveItem("")); + Assert.Throws(() => Subject.RemoveItem("", true)); } [Test] diff --git a/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs b/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs index 52bc34961..d7a0698b4 100644 --- a/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs +++ b/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs @@ -5,7 +5,6 @@ using NzbDrone.Common.Disk; using NzbDrone.Common.Http; using NzbDrone.Common.Extensions; using NzbDrone.Core.MediaFiles.TorrentInfo; -using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Configuration; using NzbDrone.Core.Validation; @@ -25,10 +24,9 @@ namespace NzbDrone.Core.Download.Clients.Deluge IHttpClient httpClient, IConfigService configService, IDiskProvider diskProvider, - IParsingService parsingService, IRemotePathMappingService remotePathMappingService, Logger logger) - : base(torrentFileInfoReader, httpClient, configService, diskProvider, parsingService, remotePathMappingService, logger) + : base(torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger) { _proxy = proxy; } @@ -153,14 +151,9 @@ namespace NzbDrone.Core.Download.Clients.Deluge return items; } - public override void RemoveItem(String hash) + public override void RemoveItem(string downloadId, bool deleteData) { - _proxy.RemoveTorrent(hash.ToLower(), false, Settings); - } - - public override String RetryDownload(String hash) - { - throw new NotSupportedException(); + _proxy.RemoveTorrent(downloadId.ToLower(), deleteData, Settings); } public override DownloadClientStatus GetStatus() @@ -245,7 +238,7 @@ namespace NzbDrone.Core.Download.Clients.Deluge { return null; } - + var enabledPlugins = _proxy.GetEnabledPlugins(Settings); if (!enabledPlugins.Contains("Label")) diff --git a/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs b/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs index ac2001f04..fae79fb13 100644 --- a/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs +++ b/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs @@ -185,16 +185,9 @@ namespace NzbDrone.Core.Download.Clients.Nzbget return GetQueue().Concat(GetHistory()).Where(downloadClientItem => downloadClientItem.Category == Settings.TvCategory); } - public override void RemoveItem(String id) + public override void RemoveItem(string downloadId, bool deleteData) { - _proxy.RemoveItem(id, Settings); - } - - public override String RetryDownload(String id) - { - _proxy.RetryDownload(id, Settings); - - return id; + _proxy.RemoveItem(downloadId, Settings); } public override DownloadClientStatus GetStatus() diff --git a/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs b/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs index add632462..12cfaf82a 100644 --- a/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs +++ b/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs @@ -105,12 +105,7 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic } } - public override void RemoveItem(String id) - { - throw new NotSupportedException(); - } - - public override String RetryDownload(String id) + public override void RemoveItem(string downloadId, bool deleteData) { throw new NotSupportedException(); } diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs index f86b4ee41..462206c3f 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs @@ -1,14 +1,12 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Threading; using FluentValidation.Results; using NLog; using NzbDrone.Common.Disk; using NzbDrone.Common.Extensions; using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; -using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Validation; using NzbDrone.Core.RemotePathMappings; @@ -23,7 +21,6 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd IHttpClient httpClient, IConfigService configService, IDiskProvider diskProvider, - IParsingService parsingService, IRemotePathMappingService remotePathMappingService, Logger logger) : base(httpClient, configService, diskProvider, remotePathMappingService, logger) @@ -190,76 +187,18 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd } } - public override void RemoveItem(String id) + public override void RemoveItem(string downloadId, bool deleteData) { - if (GetQueue().Any(v => v.DownloadId == id)) + if (GetQueue().Any(v => v.DownloadId == downloadId)) { - _proxy.RemoveFrom("queue", id, Settings); + _proxy.RemoveFrom("queue", downloadId, deleteData, Settings); } else { - _proxy.RemoveFrom("history", id, Settings); + _proxy.RemoveFrom("history", downloadId, deleteData, Settings); } } - public override String RetryDownload(String id) - { - // Sabnzbd changed the nzo_id for retried downloads without reporting it back to us. We need to try to determine the new ID. - // Check both the queue and history because sometimes SAB keeps item in history to retry post processing (depends on failure reason) - - var currentHistory = GetHistory().ToList(); - var currentHistoryItems = currentHistory.Where(v => v.DownloadId == id).ToList(); - - if (currentHistoryItems.Count != 1) - { - _logger.Warn("History item missing. Couldn't get the new nzoid."); - return id; - } - - var currentHistoryItem = currentHistoryItems.First(); - var otherItemsWithSameTitle = currentHistory.Where(h => h.Title == currentHistoryItem.Title && - h.DownloadId != currentHistoryItem.DownloadId).ToList(); - - var newId = _proxy.RetryDownload(id, Settings); - - if (newId.IsNotNullOrWhiteSpace()) - { - return newId; - } - - for (int i = 0; i < 3; i++) - { - var queue = GetQueue().Where(v => v.Category == currentHistoryItem.Category && - v.Title == currentHistoryItem.Title).ToList(); - - var history = GetHistory().Where(v => v.Category == currentHistoryItem.Category && - v.Title == currentHistoryItem.Title && - !otherItemsWithSameTitle.Select(h => h.DownloadId) - .Contains(v.DownloadId)).ToList(); - - if (queue.Count == 1) - { - return queue.First().DownloadId; - } - - if (history.Count == 1) - { - return history.First().DownloadId; - } - - if (queue.Count > 1 || history.Count > 1) - { - _logger.Warn("Multiple items with the correct title. Couldn't get the new nzoid."); - return id; - } - - Thread.Sleep(500); - } - - _logger.Warn("No items with the correct title. Couldn't get the new nzoid."); - return id; - } - protected IEnumerable GetCategories(SabnzbdConfig config) { var completeDir = new OsPath(config.Misc.complete_dir); diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs index 5a144f6a4..1ad28aba6 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs @@ -12,7 +12,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd public interface ISabnzbdProxy { SabnzbdAddResponse DownloadNzb(Byte[] nzbData, string name, string category, int priority, SabnzbdSettings settings); - void RemoveFrom(string source, string id, SabnzbdSettings settings); + void RemoveFrom(string source, string id,bool deleteData, SabnzbdSettings settings); string ProcessRequest(IRestRequest restRequest, string action, SabnzbdSettings settings); SabnzbdVersionResponse GetVersion(SabnzbdSettings settings); SabnzbdConfig GetConfig(SabnzbdSettings settings); @@ -48,10 +48,11 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd return response; } - public void RemoveFrom(string source, string id, SabnzbdSettings settings) + public void RemoveFrom(string source, string id, bool deleteData, SabnzbdSettings settings) { var request = new RestRequest(); - var action = String.Format("mode={0}&name=delete&del_files=1&value={1}", source, id); + + var action = String.Format("mode={0}&name=delete&del_files={1}&value={2}", source, deleteData ? 1 : 0, id); ProcessRequest(request, action, settings); } diff --git a/src/NzbDrone.Core/Download/Clients/TorrentBlackhole/TorrentBlackhole.cs b/src/NzbDrone.Core/Download/Clients/TorrentBlackhole/TorrentBlackhole.cs index cdee8dd18..c65608253 100644 --- a/src/NzbDrone.Core/Download/Clients/TorrentBlackhole/TorrentBlackhole.cs +++ b/src/NzbDrone.Core/Download/Clients/TorrentBlackhole/TorrentBlackhole.cs @@ -123,12 +123,7 @@ namespace NzbDrone.Core.Download.Clients.TorrentBlackhole } } - public override void RemoveItem(string id) - { - throw new NotSupportedException(); - } - - public override String RetryDownload(string id) + public override void RemoveItem(string downloadId, bool deleteData) { throw new NotSupportedException(); } diff --git a/src/NzbDrone.Core/Download/Clients/Transmission/Transmission.cs b/src/NzbDrone.Core/Download/Clients/Transmission/Transmission.cs index 7d0fb661e..56b75448f 100644 --- a/src/NzbDrone.Core/Download/Clients/Transmission/Transmission.cs +++ b/src/NzbDrone.Core/Download/Clients/Transmission/Transmission.cs @@ -26,10 +26,9 @@ namespace NzbDrone.Core.Download.Clients.Transmission IHttpClient httpClient, IConfigService configService, IDiskProvider diskProvider, - IParsingService parsingService, IRemotePathMappingService remotePathMappingService, Logger logger) - : base(torrentFileInfoReader, httpClient, configService, diskProvider, parsingService, remotePathMappingService, logger) + : base(torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger) { _proxy = proxy; } @@ -143,14 +142,9 @@ namespace NzbDrone.Core.Download.Clients.Transmission return items; } - public override void RemoveItem(String hash) + public override void RemoveItem(string downloadId, bool deleteData) { - _proxy.RemoveTorrent(hash.ToLower(), false, Settings); - } - - public override String RetryDownload(String hash) - { - throw new NotSupportedException(); + _proxy.RemoveTorrent(downloadId.ToLower(), deleteData, Settings); } public override DownloadClientStatus GetStatus() diff --git a/src/NzbDrone.Core/Download/Clients/UsenetBlackhole/UsenetBlackhole.cs b/src/NzbDrone.Core/Download/Clients/UsenetBlackhole/UsenetBlackhole.cs index 11ca1843e..c18981eca 100644 --- a/src/NzbDrone.Core/Download/Clients/UsenetBlackhole/UsenetBlackhole.cs +++ b/src/NzbDrone.Core/Download/Clients/UsenetBlackhole/UsenetBlackhole.cs @@ -121,12 +121,7 @@ namespace NzbDrone.Core.Download.Clients.UsenetBlackhole } } - public override void RemoveItem(String id) - { - throw new NotSupportedException(); - } - - public override String RetryDownload(String id) + public override void RemoveItem(string downloadId, bool deleteData) { throw new NotSupportedException(); } diff --git a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs index 6aad6070a..60d43295e 100644 --- a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs @@ -6,7 +6,6 @@ using NzbDrone.Common.Extensions; using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; using NzbDrone.Core.MediaFiles.TorrentInfo; -using NzbDrone.Core.Parser; using NLog; using NzbDrone.Core.Validation; using FluentValidation.Results; @@ -25,10 +24,9 @@ namespace NzbDrone.Core.Download.Clients.UTorrent IHttpClient httpClient, IConfigService configService, IDiskProvider diskProvider, - IParsingService parsingService, IRemotePathMappingService remotePathMappingService, Logger logger) - : base(torrentFileInfoReader, httpClient, configService, diskProvider, parsingService, remotePathMappingService, logger) + : base(torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger) { _proxy = proxy; } @@ -143,14 +141,9 @@ namespace NzbDrone.Core.Download.Clients.UTorrent return queueItems; } - public override void RemoveItem(String id) + public override void RemoveItem(string downloadId, bool deleteData) { - _proxy.RemoveTorrent(id, false, Settings); - } - - public override String RetryDownload(String id) - { - throw new NotSupportedException(); + _proxy.RemoveTorrent(downloadId, deleteData, Settings); } public override DownloadClientStatus GetStatus() diff --git a/src/NzbDrone.Core/Download/DownloadClientBase.cs b/src/NzbDrone.Core/Download/DownloadClientBase.cs index bfa6a2275..e492eed81 100644 --- a/src/NzbDrone.Core/Download/DownloadClientBase.cs +++ b/src/NzbDrone.Core/Download/DownloadClientBase.cs @@ -70,8 +70,7 @@ namespace NzbDrone.Core.Download public abstract String Download(RemoteEpisode remoteEpisode); public abstract IEnumerable GetItems(); - public abstract void RemoveItem(string id); - public abstract String RetryDownload(string id); + public abstract void RemoveItem(string downloadId, bool deleteData); public abstract DownloadClientStatus GetStatus(); public ValidationResult Test() diff --git a/src/NzbDrone.Core/Download/DownloadEventHub.cs b/src/NzbDrone.Core/Download/DownloadEventHub.cs index 3479b9b04..ed9d19a80 100644 --- a/src/NzbDrone.Core/Download/DownloadEventHub.cs +++ b/src/NzbDrone.Core/Download/DownloadEventHub.cs @@ -17,7 +17,6 @@ namespace NzbDrone.Core.Download } } - public class DownloadEventHub : IHandle, IHandle { @@ -52,7 +51,7 @@ namespace NzbDrone.Core.Download var trackedDownload = _trackedDownloadService.Find(message.DownloadId); - if (trackedDownload == null || trackedDownload.DownloadItem.IsReadOnly || !_configService.RemoveFailedDownloads) + if (trackedDownload == null || trackedDownload.DownloadItem.IsReadOnly || _configService.RemoveFailedDownloads == false) { return; } @@ -67,7 +66,7 @@ namespace NzbDrone.Core.Download try { _logger.Debug("[{0}] Removing download from {1} history", trackedDownload.DownloadItem.DownloadClient); - downloadClient.RemoveItem(trackedDownload.DownloadItem.DownloadId); + downloadClient.RemoveItem(trackedDownload.DownloadItem.DownloadId, true); trackedDownload.DownloadItem.Removed = true; } catch (NotSupportedException) diff --git a/src/NzbDrone.Core/Download/IDownloadClient.cs b/src/NzbDrone.Core/Download/IDownloadClient.cs index 193c59254..f2b8079c1 100644 --- a/src/NzbDrone.Core/Download/IDownloadClient.cs +++ b/src/NzbDrone.Core/Download/IDownloadClient.cs @@ -12,9 +12,7 @@ namespace NzbDrone.Core.Download String Download(RemoteEpisode remoteEpisode); IEnumerable GetItems(); - void RemoveItem(String id); - String RetryDownload(String id); - + void RemoveItem(string downloadId, bool deleteData); DownloadClientStatus GetStatus(); } } diff --git a/src/NzbDrone.Core/Download/TorrentClientBase.cs b/src/NzbDrone.Core/Download/TorrentClientBase.cs index 8524d7828..475c7af37 100644 --- a/src/NzbDrone.Core/Download/TorrentClientBase.cs +++ b/src/NzbDrone.Core/Download/TorrentClientBase.cs @@ -8,7 +8,6 @@ using NzbDrone.Core.Exceptions; using NzbDrone.Core.Indexers; using NzbDrone.Core.MediaFiles.TorrentInfo; using NzbDrone.Core.Organizer; -using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.Configuration; @@ -27,7 +26,6 @@ namespace NzbDrone.Core.Download IHttpClient httpClient, IConfigService configService, IDiskProvider diskProvider, - IParsingService parsingService, IRemotePathMappingService remotePathMappingService, Logger logger) : base(configService, diskProvider, remotePathMappingService, logger) diff --git a/src/NzbDrone.Core/Download/TrackedDownloads/DownloadMonitoringService.cs b/src/NzbDrone.Core/Download/TrackedDownloads/DownloadMonitoringService.cs index fa7d85412..b11ff9e4b 100644 --- a/src/NzbDrone.Core/Download/TrackedDownloads/DownloadMonitoringService.cs +++ b/src/NzbDrone.Core/Download/TrackedDownloads/DownloadMonitoringService.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using NLog; +using NzbDrone.Common.Extensions; using NzbDrone.Common.TPL; using NzbDrone.Core.Configuration; using NzbDrone.Core.MediaFiles.Events; @@ -111,7 +112,7 @@ namespace NzbDrone.Core.Download.TrackedDownloads } - trackedDownloads.Add(trackedDownload); + trackedDownloads.AddIfNotNull(trackedDownload); } catch (Exception e) diff --git a/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs b/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs index fe6059053..562eb5bb3 100644 --- a/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs +++ b/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs @@ -1,9 +1,7 @@ using System; using NLog; using NzbDrone.Common.Cache; -using NzbDrone.Core.DataAugmentation.Scene; using NzbDrone.Core.History; -using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Parser; namespace NzbDrone.Core.Download.TrackedDownloads @@ -14,8 +12,7 @@ namespace NzbDrone.Core.Download.TrackedDownloads TrackedDownload TrackDownload(DownloadClientDefinition downloadClient, DownloadClientItem downloadItem); } - public class TrackedDownloadService : ITrackedDownloadService, - IHandle + public class TrackedDownloadService : ITrackedDownloadService { private readonly IParsingService _parsingService; private readonly IHistoryService _historyService; @@ -42,7 +39,7 @@ namespace NzbDrone.Core.Download.TrackedDownloads { var existingItem = Find(downloadItem.DownloadId); - if (existingItem != null) + if (existingItem != null && existingItem.State != TrackedDownloadStage.Downloading) { existingItem.DownloadItem = downloadItem; return existingItem; @@ -56,12 +53,6 @@ namespace NzbDrone.Core.Download.TrackedDownloads Protocol = downloadClient.Protocol }; - var historyItem = _historyService.MostRecentForDownloadId(downloadItem.DownloadId); - if (historyItem != null) - { - trackedDownload.State = GetStateFromHistory(historyItem.EventType); - } - try { var parsedEpisodeInfo = Parser.Parser.ParseTitle(trackedDownload.DownloadItem.Title); @@ -81,11 +72,14 @@ namespace NzbDrone.Core.Download.TrackedDownloads return null; } - if (trackedDownload.State != TrackedDownloadStage.Downloading) + var historyItem = _historyService.MostRecentForDownloadId(downloadItem.DownloadId); + if (historyItem != null) { - _cache.Set(downloadItem.DownloadId, trackedDownload); + trackedDownload.State = GetStateFromHistory(historyItem.EventType); } + _cache.Set(downloadItem.DownloadId, trackedDownload); + return trackedDownload; } @@ -102,9 +96,5 @@ namespace NzbDrone.Core.Download.TrackedDownloads } } - public void Handle(SceneMappingsUpdatedEvent message) - { - _cache.Clear(); - } } } \ No newline at end of file diff --git a/src/NzbDrone.Update.Test/StartNzbDroneService.cs b/src/NzbDrone.Update.Test/StartNzbDroneService.cs index 801326c6e..ab9f2f665 100644 --- a/src/NzbDrone.Update.Test/StartNzbDroneService.cs +++ b/src/NzbDrone.Update.Test/StartNzbDroneService.cs @@ -32,7 +32,7 @@ namespace NzbDrone.Update.Test Subject.Start(AppType.Service, targetFolder); - Mocker.GetMock().Verify(c => c.SpawnNewProcess("c:\\NzbDrone\\NzbDrone.Console.exe", "--" + StartupContext.NO_BROWSER), Times.Once()); + Mocker.GetMock().Verify(c => c.SpawnNewProcess("c:\\NzbDrone\\NzbDrone.Console.exe", "/" + StartupContext.NO_BROWSER), Times.Once()); ExceptionVerification.ExpectedWarns(1); }