Check history when retrying downloads with SAB

Fixed: Retrying a download shouldn't cause drone to lose track of it
pull/2/head
Mark McDowall 10 years ago
parent fde38938b8
commit acc25d7558

@ -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;

@ -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();
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)
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;

Loading…
Cancel
Save