From acc25d75580930b37e4f249bddfe213959e7d1dd Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 30 Sep 2014 14:17:48 -0700 Subject: [PATCH] Check history when retrying downloads with SAB Fixed: Retrying a download shouldn't cause drone to lose track of it --- .../SabnzbdTests/SabnzbdFixture.cs | 4 --- .../Download/Clients/Sabnzbd/Sabnzbd.cs | 31 ++++++++++++++----- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs index 7e946b3aa..7a5549bbf 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs @@ -1,17 +1,13 @@ using System; -using System.IO; using System.Linq; using System.Collections.Generic; using FizzWare.NBuilder; using FluentAssertions; using Moq; using NUnit.Framework; -using NzbDrone.Common; using NzbDrone.Core.Download; using NzbDrone.Core.Download.Clients.Sabnzbd; using NzbDrone.Core.Download.Clients.Sabnzbd.Responses; -using NzbDrone.Core.Parser.Model; -using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Tv; using NzbDrone.Test.Common; using NzbDrone.Core.RemotePathMappings; diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs index 35ca256d1..2122777e8 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs @@ -208,27 +208,44 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd 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 history = GetHistory().Where(v => v.DownloadClientId == id).ToList(); + var currentHistory = GetHistory().ToList(); + var currentHistoryItems = currentHistory.Where(v => v.DownloadClientId == id).ToList(); - _proxy.RetryDownload(id, Settings); - - if (history.Count() != 1) + 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.DownloadClientId != currentHistoryItem.DownloadClientId).ToList(); + + _proxy.RetryDownload(id, Settings); + for (int i = 0; i < 3; i++) { - var queue = GetQueue().Where(v => v.Category == history.First().Category && v.Title == history.First().Title).ToList(); + var queue = GetQueue().Where(v => v.Category == currentHistoryItem.Category && + v.Title == currentHistoryItem.Title).ToList(); - if (queue.Count() == 1) + var history = GetHistory().Where(v => v.Category == currentHistoryItem.Category && + v.Title == currentHistoryItem.Title && + otherItemsWithSameTitle.Select(h => h.DownloadClientId) + .Contains(v.DownloadClientId)).ToList(); + + if (queue.Count == 1) { return queue.First().DownloadClientId; } - if (queue.Count() > 2) + if (history.Count == 1) + { + return history.First().DownloadClientId; + } + + if (queue.Count > 1 || history.Count > 1) { _logger.Warn("Multiple items with the correct title. Couldn't get the new nzoid."); return id;