Fixed: Marking queued item as failed not blocking the correct Torrent Info Hash
This commit is contained in:
parent
b1527f9abb
commit
da49f2a2f5
|
@ -185,7 +185,7 @@ namespace NzbDrone.Core.Blocklisting
|
||||||
Indexer = message.Data.GetValueOrDefault("indexer"),
|
Indexer = message.Data.GetValueOrDefault("indexer"),
|
||||||
Protocol = (DownloadProtocol)Convert.ToInt32(message.Data.GetValueOrDefault("protocol")),
|
Protocol = (DownloadProtocol)Convert.ToInt32(message.Data.GetValueOrDefault("protocol")),
|
||||||
Message = message.Message,
|
Message = message.Message,
|
||||||
TorrentInfoHash = message.Data.GetValueOrDefault("torrentInfoHash"),
|
TorrentInfoHash = message.TorrentInfoHash,
|
||||||
Languages = message.Languages
|
Languages = message.Languages
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ namespace NzbDrone.Core.Download
|
||||||
public string DownloadClient { get; set; }
|
public string DownloadClient { get; set; }
|
||||||
public string DownloadId { get; set; }
|
public string DownloadId { get; set; }
|
||||||
public string Message { get; set; }
|
public string Message { get; set; }
|
||||||
|
public string TorrentInfoHash { get; set; }
|
||||||
public Dictionary<string, string> Data { get; set; }
|
public Dictionary<string, string> Data { get; set; }
|
||||||
public TrackedDownload TrackedDownload { get; set; }
|
public TrackedDownload TrackedDownload { get; set; }
|
||||||
public List<Language> Languages { get; set; }
|
public List<Language> Languages { get; set; }
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.Linq;
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
using NzbDrone.Core.Download.TrackedDownloads;
|
using NzbDrone.Core.Download.TrackedDownloads;
|
||||||
using NzbDrone.Core.History;
|
using NzbDrone.Core.History;
|
||||||
|
using NzbDrone.Core.Indexers;
|
||||||
using NzbDrone.Core.Messaging.Events;
|
using NzbDrone.Core.Messaging.Events;
|
||||||
using NzbDrone.Core.Parser.Model;
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
|
||||||
|
@ -12,7 +13,7 @@ namespace NzbDrone.Core.Download
|
||||||
public interface IFailedDownloadService
|
public interface IFailedDownloadService
|
||||||
{
|
{
|
||||||
void MarkAsFailed(int historyId, bool skipRedownload = false);
|
void MarkAsFailed(int historyId, bool skipRedownload = false);
|
||||||
void MarkAsFailed(string downloadId, bool skipRedownload = false);
|
void MarkAsFailed(TrackedDownload trackedDownload, bool skipRedownload = false);
|
||||||
void Check(TrackedDownload trackedDownload);
|
void Check(TrackedDownload trackedDownload);
|
||||||
void ProcessFailed(TrackedDownload trackedDownload);
|
void ProcessFailed(TrackedDownload trackedDownload);
|
||||||
}
|
}
|
||||||
|
@ -20,7 +21,6 @@ namespace NzbDrone.Core.Download
|
||||||
public class FailedDownloadService : IFailedDownloadService
|
public class FailedDownloadService : IFailedDownloadService
|
||||||
{
|
{
|
||||||
private readonly IHistoryService _historyService;
|
private readonly IHistoryService _historyService;
|
||||||
private readonly ITrackedDownloadService _trackedDownloadService;
|
|
||||||
private readonly IEventAggregator _eventAggregator;
|
private readonly IEventAggregator _eventAggregator;
|
||||||
|
|
||||||
public FailedDownloadService(IHistoryService historyService,
|
public FailedDownloadService(IHistoryService historyService,
|
||||||
|
@ -28,7 +28,6 @@ namespace NzbDrone.Core.Download
|
||||||
IEventAggregator eventAggregator)
|
IEventAggregator eventAggregator)
|
||||||
{
|
{
|
||||||
_historyService = historyService;
|
_historyService = historyService;
|
||||||
_trackedDownloadService = trackedDownloadService;
|
|
||||||
_eventAggregator = eventAggregator;
|
_eventAggregator = eventAggregator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,9 +36,10 @@ namespace NzbDrone.Core.Download
|
||||||
var history = _historyService.Get(historyId);
|
var history = _historyService.Get(historyId);
|
||||||
|
|
||||||
var downloadId = history.DownloadId;
|
var downloadId = history.DownloadId;
|
||||||
|
|
||||||
if (downloadId.IsNullOrWhiteSpace())
|
if (downloadId.IsNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
PublishDownloadFailedEvent(new List<EpisodeHistory> { history }, "Manually marked as failed", skipRedownload: skipRedownload);
|
PublishDownloadFailedEvent(history, new List<int> { history.EpisodeId }, "Manually marked as failed", skipRedownload: skipRedownload);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -53,21 +53,19 @@ namespace NzbDrone.Core.Download
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add any other history items for the download ID then filter out any duplicate history items.
|
// Add any other history items for the download ID then filter out any duplicate history items.
|
||||||
grabbedHistory.AddRange(_historyService.Find(downloadId, EpisodeHistoryEventType.Grabbed));
|
grabbedHistory.AddRange(GetGrabbedHistory(downloadId));
|
||||||
grabbedHistory = grabbedHistory.DistinctBy(h => h.Id).ToList();
|
grabbedHistory = grabbedHistory.DistinctBy(h => h.Id).ToList();
|
||||||
|
|
||||||
PublishDownloadFailedEvent(grabbedHistory, "Manually marked as failed");
|
PublishDownloadFailedEvent(history, GetEpisodeIds(grabbedHistory), "Manually marked as failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MarkAsFailed(string downloadId, bool skipRedownload = false)
|
public void MarkAsFailed(TrackedDownload trackedDownload, bool skipRedownload = false)
|
||||||
{
|
{
|
||||||
var history = _historyService.Find(downloadId, EpisodeHistoryEventType.Grabbed);
|
var history = GetGrabbedHistory(trackedDownload.DownloadItem.DownloadId);
|
||||||
|
|
||||||
if (history.Any())
|
if (history.Any())
|
||||||
{
|
{
|
||||||
var trackedDownload = _trackedDownloadService.Find(downloadId);
|
PublishDownloadFailedEvent(history.First(), GetEpisodeIds(history), "Manually marked as failed", trackedDownload, skipRedownload: skipRedownload);
|
||||||
|
|
||||||
PublishDownloadFailedEvent(history, "Manually marked as failed", trackedDownload, skipRedownload: skipRedownload);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,9 +80,7 @@ namespace NzbDrone.Core.Download
|
||||||
if (trackedDownload.DownloadItem.IsEncrypted ||
|
if (trackedDownload.DownloadItem.IsEncrypted ||
|
||||||
trackedDownload.DownloadItem.Status == DownloadItemStatus.Failed)
|
trackedDownload.DownloadItem.Status == DownloadItemStatus.Failed)
|
||||||
{
|
{
|
||||||
var grabbedItems = _historyService
|
var grabbedItems = GetGrabbedHistory(trackedDownload.DownloadItem.DownloadId);
|
||||||
.Find(trackedDownload.DownloadItem.DownloadId, EpisodeHistoryEventType.Grabbed)
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
if (grabbedItems.Empty())
|
if (grabbedItems.Empty())
|
||||||
{
|
{
|
||||||
|
@ -103,9 +99,7 @@ namespace NzbDrone.Core.Download
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var grabbedItems = _historyService
|
var grabbedItems = GetGrabbedHistory(trackedDownload.DownloadItem.DownloadId);
|
||||||
.Find(trackedDownload.DownloadItem.DownloadId, EpisodeHistoryEventType.Grabbed)
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
if (grabbedItems.Empty())
|
if (grabbedItems.Empty())
|
||||||
{
|
{
|
||||||
|
@ -124,18 +118,19 @@ namespace NzbDrone.Core.Download
|
||||||
}
|
}
|
||||||
|
|
||||||
trackedDownload.State = TrackedDownloadState.Failed;
|
trackedDownload.State = TrackedDownloadState.Failed;
|
||||||
PublishDownloadFailedEvent(grabbedItems, failure, trackedDownload);
|
PublishDownloadFailedEvent(grabbedItems.First(), GetEpisodeIds(grabbedItems), failure, trackedDownload);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PublishDownloadFailedEvent(List<EpisodeHistory> historyItems, string message, TrackedDownload trackedDownload = null, bool skipRedownload = false)
|
private void PublishDownloadFailedEvent(EpisodeHistory historyItem, List<int> episodeIds, string message, TrackedDownload trackedDownload = null, bool skipRedownload = false)
|
||||||
{
|
{
|
||||||
var historyItem = historyItems.Last();
|
|
||||||
Enum.TryParse(historyItem.Data.GetValueOrDefault(EpisodeHistory.RELEASE_SOURCE, ReleaseSourceType.Unknown.ToString()), out ReleaseSourceType releaseSource);
|
Enum.TryParse(historyItem.Data.GetValueOrDefault(EpisodeHistory.RELEASE_SOURCE, ReleaseSourceType.Unknown.ToString()), out ReleaseSourceType releaseSource);
|
||||||
|
|
||||||
|
var torrentInfoHash = GetTorrentInfoHash(historyItem, trackedDownload);
|
||||||
|
|
||||||
var downloadFailedEvent = new DownloadFailedEvent
|
var downloadFailedEvent = new DownloadFailedEvent
|
||||||
{
|
{
|
||||||
SeriesId = historyItem.SeriesId,
|
SeriesId = historyItem.SeriesId,
|
||||||
EpisodeIds = historyItems.Select(h => h.EpisodeId).Distinct().ToList(),
|
EpisodeIds = episodeIds,
|
||||||
Quality = historyItem.Quality,
|
Quality = historyItem.Quality,
|
||||||
SourceTitle = historyItem.SourceTitle,
|
SourceTitle = historyItem.SourceTitle,
|
||||||
DownloadClient = historyItem.Data.GetValueOrDefault(EpisodeHistory.DOWNLOAD_CLIENT),
|
DownloadClient = historyItem.Data.GetValueOrDefault(EpisodeHistory.DOWNLOAD_CLIENT),
|
||||||
|
@ -145,10 +140,34 @@ namespace NzbDrone.Core.Download
|
||||||
TrackedDownload = trackedDownload,
|
TrackedDownload = trackedDownload,
|
||||||
Languages = historyItem.Languages,
|
Languages = historyItem.Languages,
|
||||||
SkipRedownload = skipRedownload,
|
SkipRedownload = skipRedownload,
|
||||||
ReleaseSource = releaseSource
|
ReleaseSource = releaseSource,
|
||||||
|
TorrentInfoHash = torrentInfoHash
|
||||||
};
|
};
|
||||||
|
|
||||||
_eventAggregator.PublishEvent(downloadFailedEvent);
|
_eventAggregator.PublishEvent(downloadFailedEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string GetTorrentInfoHash(EpisodeHistory historyItem, TrackedDownload trackedDownload)
|
||||||
|
{
|
||||||
|
if (trackedDownload == null)
|
||||||
|
{
|
||||||
|
return historyItem.Data.GetValueOrDefault("torrentInfoHash", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return trackedDownload.Protocol == DownloadProtocol.Torrent ? trackedDownload.DownloadItem.DownloadId : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<int> GetEpisodeIds(List<EpisodeHistory> historyItems)
|
||||||
|
{
|
||||||
|
return historyItems.Select(h => h.EpisodeId).Distinct().ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<EpisodeHistory> GetGrabbedHistory(string downloadId)
|
||||||
|
{
|
||||||
|
// Sort by date so items are always in the same order
|
||||||
|
return _historyService.Find(downloadId, EpisodeHistoryEventType.Grabbed)
|
||||||
|
.OrderByDescending(h => h.Date)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -323,7 +323,7 @@ namespace Sonarr.Api.V3.Queue
|
||||||
|
|
||||||
if (blocklist)
|
if (blocklist)
|
||||||
{
|
{
|
||||||
_failedDownloadService.MarkAsFailed(trackedDownload.DownloadItem.DownloadId, skipRedownload);
|
_failedDownloadService.MarkAsFailed(trackedDownload, skipRedownload);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!removeFromClient && !blocklist && !changeCategory)
|
if (!removeFromClient && !blocklist && !changeCategory)
|
||||||
|
|
Loading…
Reference in New Issue