|
|
@ -1,6 +1,8 @@
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using NLog;
|
|
|
|
using NLog;
|
|
|
|
|
|
|
|
using NzbDrone.Core.Configuration;
|
|
|
|
using NzbDrone.Core.History;
|
|
|
|
using NzbDrone.Core.History;
|
|
|
|
using NzbDrone.Core.Messaging.Commands;
|
|
|
|
using NzbDrone.Core.Messaging.Commands;
|
|
|
|
using NzbDrone.Core.Messaging.Events;
|
|
|
|
using NzbDrone.Core.Messaging.Events;
|
|
|
@ -12,27 +14,80 @@ namespace NzbDrone.Core.Download
|
|
|
|
private readonly IProvideDownloadClient _downloadClientProvider;
|
|
|
|
private readonly IProvideDownloadClient _downloadClientProvider;
|
|
|
|
private readonly IHistoryService _historyService;
|
|
|
|
private readonly IHistoryService _historyService;
|
|
|
|
private readonly IEventAggregator _eventAggregator;
|
|
|
|
private readonly IEventAggregator _eventAggregator;
|
|
|
|
|
|
|
|
private readonly IConfigService _configService;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private readonly IDownloadClient _downloadClient;
|
|
|
|
|
|
|
|
|
|
|
|
private static string DOWNLOAD_CLIENT = "downloadClient";
|
|
|
|
private static string DOWNLOAD_CLIENT = "downloadClient";
|
|
|
|
private static string DOWNLOAD_CLIENT_ID = "downloadClientId";
|
|
|
|
private static string DOWNLOAD_CLIENT_ID = "downloadClientId";
|
|
|
|
|
|
|
|
|
|
|
|
public FailedDownloadService(IProvideDownloadClient downloadClientProvider,
|
|
|
|
public FailedDownloadService(IProvideDownloadClient downloadClientProvider,
|
|
|
|
IHistoryService historyService,
|
|
|
|
IHistoryService historyService,
|
|
|
|
IEventAggregator eventAggregator,
|
|
|
|
IEventAggregator eventAggregator,
|
|
|
|
|
|
|
|
IConfigService configService,
|
|
|
|
Logger logger)
|
|
|
|
Logger logger)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_downloadClientProvider = downloadClientProvider;
|
|
|
|
_downloadClientProvider = downloadClientProvider;
|
|
|
|
_historyService = historyService;
|
|
|
|
_historyService = historyService;
|
|
|
|
_eventAggregator = eventAggregator;
|
|
|
|
_eventAggregator = eventAggregator;
|
|
|
|
|
|
|
|
_configService = configService;
|
|
|
|
_logger = logger;
|
|
|
|
_logger = logger;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_downloadClient = _downloadClientProvider.GetDownloadClient();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void CheckForFailedDownloads()
|
|
|
|
private void CheckForFailedDownloads()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var downloadClient = _downloadClientProvider.GetDownloadClient();
|
|
|
|
var grabbedHistory = _historyService.Grabbed();
|
|
|
|
var downloadClientHistory = downloadClient.GetHistory(0, 20).ToList();
|
|
|
|
var failedHistory = _historyService.Failed();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CheckQueue(grabbedHistory, failedHistory);
|
|
|
|
|
|
|
|
CheckHistory(grabbedHistory, failedHistory);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void CheckQueue(List<History.History> grabbedHistory, List<History.History> failedHistory)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var downloadClientQueue = _downloadClient.GetQueue().ToList();
|
|
|
|
|
|
|
|
var failedItems = downloadClientQueue.Where(q => q.Title.StartsWith("ENCRYPTED / ")).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!failedItems.Any())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.Trace("Yay! No encrypted downloads");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var failedItem in failedItems)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var failedLocal = failedItem;
|
|
|
|
|
|
|
|
var historyItems = GetHistoryItems(grabbedHistory, failedLocal.Id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!historyItems.Any())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.Trace("Unable to find matching history item");
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (failedHistory.Any(h => h.Data.ContainsKey(DOWNLOAD_CLIENT_ID) &&
|
|
|
|
|
|
|
|
h.Data[DOWNLOAD_CLIENT_ID].Equals(failedLocal.Id)))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.Trace("Already added to history as failed");
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PublishDownloadFailedEvent(historyItems, "Encypted download detected");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (_configService.RemoveFailedDownloads)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.Info("Removing encrypted download from queue: {0}", failedItem.Title.Replace("ENCRYPTED / ", ""));
|
|
|
|
|
|
|
|
_downloadClient.RemoveFromQueue(failedItem.Id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void CheckHistory(List<History.History> grabbedHistory, List<History.History> failedHistory)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var downloadClientHistory = _downloadClient.GetHistory(0, 20).ToList();
|
|
|
|
var failedItems = downloadClientHistory.Where(h => h.Status == HistoryStatus.Failed).ToList();
|
|
|
|
var failedItems = downloadClientHistory.Where(h => h.Status == HistoryStatus.Failed).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
if (!failedItems.Any())
|
|
|
|
if (!failedItems.Any())
|
|
|
@ -41,15 +96,10 @@ namespace NzbDrone.Core.Download
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var grabbedHistory = _historyService.Grabbed();
|
|
|
|
|
|
|
|
var failedHistory = _historyService.Failed();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var failedItem in failedItems)
|
|
|
|
foreach (var failedItem in failedItems)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var failedLocal = failedItem;
|
|
|
|
var failedLocal = failedItem;
|
|
|
|
var historyItems = grabbedHistory.Where(h => h.Data.ContainsKey(DOWNLOAD_CLIENT) &&
|
|
|
|
var historyItems = GetHistoryItems(grabbedHistory, failedLocal.Id);
|
|
|
|
h.Data[DOWNLOAD_CLIENT_ID].Equals(failedLocal.Id))
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!historyItems.Any())
|
|
|
|
if (!historyItems.Any())
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -64,8 +114,26 @@ namespace NzbDrone.Core.Download
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var historyItem = historyItems.First();
|
|
|
|
PublishDownloadFailedEvent(historyItems, failedItem.Message);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (_configService.RemoveFailedDownloads)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.Info("Removing failed download from history: {0}", failedItem.Title);
|
|
|
|
|
|
|
|
_downloadClient.RemoveFromHistory(failedItem.Id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<History.History> GetHistoryItems(List<History.History> grabbedHistory, string downloadClientId)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return grabbedHistory.Where(h => h.Data.ContainsKey(DOWNLOAD_CLIENT) &&
|
|
|
|
|
|
|
|
h.Data[DOWNLOAD_CLIENT_ID].Equals(downloadClientId))
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void PublishDownloadFailedEvent(List<History.History> historyItems, string message)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var historyItem = historyItems.First();
|
|
|
|
_eventAggregator.PublishEvent(new DownloadFailedEvent
|
|
|
|
_eventAggregator.PublishEvent(new DownloadFailedEvent
|
|
|
|
{
|
|
|
|
{
|
|
|
|
SeriesId = historyItem.SeriesId,
|
|
|
|
SeriesId = historyItem.SeriesId,
|
|
|
@ -74,10 +142,9 @@ namespace NzbDrone.Core.Download
|
|
|
|
SourceTitle = historyItem.SourceTitle,
|
|
|
|
SourceTitle = historyItem.SourceTitle,
|
|
|
|
DownloadClient = historyItem.Data[DOWNLOAD_CLIENT],
|
|
|
|
DownloadClient = historyItem.Data[DOWNLOAD_CLIENT],
|
|
|
|
DownloadClientId = historyItem.Data[DOWNLOAD_CLIENT_ID],
|
|
|
|
DownloadClientId = historyItem.Data[DOWNLOAD_CLIENT_ID],
|
|
|
|
Message = failedItem.Message
|
|
|
|
Message = message
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Execute(FailedDownloadCommand message)
|
|
|
|
public void Execute(FailedDownloadCommand message)
|
|
|
|
{
|
|
|
|
{
|
|
|
|