mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 05:23:31 -07:00
New: Option to ignore items when removing from queue instead of removing from client
This commit is contained in:
parent
d83e20937d
commit
48750780fe
21 changed files with 277 additions and 65 deletions
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Lidarr.Http;
|
||||
using Lidarr.Http.Extensions;
|
||||
using Lidarr.Http.REST;
|
||||
|
@ -15,6 +16,7 @@ namespace Lidarr.Api.V1.Queue
|
|||
private readonly IQueueService _queueService;
|
||||
private readonly ITrackedDownloadService _trackedDownloadService;
|
||||
private readonly IFailedDownloadService _failedDownloadService;
|
||||
private readonly IIgnoredDownloadService _ignoredDownloadService;
|
||||
private readonly IProvideDownloadClient _downloadClientProvider;
|
||||
private readonly IPendingReleaseService _pendingReleaseService;
|
||||
private readonly IDownloadService _downloadService;
|
||||
|
@ -22,6 +24,7 @@ namespace Lidarr.Api.V1.Queue
|
|||
public QueueActionModule(IQueueService queueService,
|
||||
ITrackedDownloadService trackedDownloadService,
|
||||
IFailedDownloadService failedDownloadService,
|
||||
IIgnoredDownloadService ignoredDownloadService,
|
||||
IProvideDownloadClient downloadClientProvider,
|
||||
IPendingReleaseService pendingReleaseService,
|
||||
IDownloadService downloadService)
|
||||
|
@ -29,6 +32,7 @@ namespace Lidarr.Api.V1.Queue
|
|||
_queueService = queueService;
|
||||
_trackedDownloadService = trackedDownloadService;
|
||||
_failedDownloadService = failedDownloadService;
|
||||
_ignoredDownloadService = ignoredDownloadService;
|
||||
_downloadClientProvider = downloadClientProvider;
|
||||
_pendingReleaseService = pendingReleaseService;
|
||||
_downloadService = downloadService;
|
||||
|
@ -75,10 +79,11 @@ namespace Lidarr.Api.V1.Queue
|
|||
|
||||
private object Remove(int id)
|
||||
{
|
||||
var removeFromClient = Request.GetBooleanQueryParameter("removeFromClient", true);
|
||||
var blacklist = Request.GetBooleanQueryParameter("blacklist");
|
||||
var skipReDownload = Request.GetBooleanQueryParameter("skipredownload");
|
||||
|
||||
var trackedDownload = Remove(id, blacklist, skipReDownload);
|
||||
var trackedDownload = Remove(id, removeFromClient, blacklist, skipReDownload);
|
||||
|
||||
if (trackedDownload != null)
|
||||
{
|
||||
|
@ -90,6 +95,7 @@ namespace Lidarr.Api.V1.Queue
|
|||
|
||||
private object Remove()
|
||||
{
|
||||
var removeFromClient = Request.GetBooleanQueryParameter("removeFromClient", true);
|
||||
var blacklist = Request.GetBooleanQueryParameter("blacklist");
|
||||
var skipReDownload = Request.GetBooleanQueryParameter("skipredownload");
|
||||
|
||||
|
@ -98,7 +104,7 @@ namespace Lidarr.Api.V1.Queue
|
|||
|
||||
foreach (var id in resource.Ids)
|
||||
{
|
||||
var trackedDownload = Remove(id, blacklist, skipReDownload);
|
||||
var trackedDownload = Remove(id, removeFromClient, blacklist, skipReDownload);
|
||||
|
||||
if (trackedDownload != null)
|
||||
{
|
||||
|
@ -111,7 +117,7 @@ namespace Lidarr.Api.V1.Queue
|
|||
return new object();
|
||||
}
|
||||
|
||||
private TrackedDownload Remove(int id, bool blacklist, bool skipReDownload)
|
||||
private TrackedDownload Remove(int id, bool removeFromClient, bool blacklist, bool skipReDownload)
|
||||
{
|
||||
var pendingRelease = _pendingReleaseService.FindPendingQueueItem(id);
|
||||
|
||||
|
@ -129,20 +135,31 @@ namespace Lidarr.Api.V1.Queue
|
|||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var downloadClient = _downloadClientProvider.Get(trackedDownload.DownloadClient);
|
||||
|
||||
if (downloadClient == null)
|
||||
if (removeFromClient)
|
||||
{
|
||||
throw new BadRequestException();
|
||||
}
|
||||
var downloadClient = _downloadClientProvider.Get(trackedDownload.DownloadClient);
|
||||
|
||||
downloadClient.RemoveItem(trackedDownload.DownloadItem.DownloadId, true);
|
||||
if (downloadClient == null)
|
||||
{
|
||||
throw new BadRequestException();
|
||||
}
|
||||
|
||||
downloadClient.RemoveItem(trackedDownload.DownloadItem.DownloadId, true);
|
||||
}
|
||||
|
||||
if (blacklist)
|
||||
{
|
||||
_failedDownloadService.MarkAsFailed(trackedDownload.DownloadItem.DownloadId, skipReDownload);
|
||||
}
|
||||
|
||||
if (!removeFromClient && !blacklist)
|
||||
{
|
||||
if (!_ignoredDownloadService.IgnoreDownload(trackedDownload))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return trackedDownload;
|
||||
}
|
||||
|
||||
|
|
17
src/NzbDrone.Core/Download/DownloadIgnoredEvent.cs
Normal file
17
src/NzbDrone.Core/Download/DownloadIgnoredEvent.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using System.Collections.Generic;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Core.Qualities;
|
||||
|
||||
namespace NzbDrone.Core.Download
|
||||
{
|
||||
public class DownloadIgnoredEvent : IEvent
|
||||
{
|
||||
public int ArtistId { get; set; }
|
||||
public List<int> AlbumIds { get; set; }
|
||||
public QualityModel Quality { get; set; }
|
||||
public string SourceTitle { get; set; }
|
||||
public string DownloadClient { get; set; }
|
||||
public string DownloadId { get; set; }
|
||||
public string Message { get; set; }
|
||||
}
|
||||
}
|
52
src/NzbDrone.Core/Download/IgnoredDownloadService.cs
Normal file
52
src/NzbDrone.Core/Download/IgnoredDownloadService.cs
Normal file
|
@ -0,0 +1,52 @@
|
|||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Download.TrackedDownloads;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
|
||||
namespace NzbDrone.Core.Download
|
||||
{
|
||||
public interface IIgnoredDownloadService
|
||||
{
|
||||
bool IgnoreDownload(TrackedDownload trackedDownload);
|
||||
}
|
||||
|
||||
public class IgnoredDownloadService : IIgnoredDownloadService
|
||||
{
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public IgnoredDownloadService(IEventAggregator eventAggregator,
|
||||
Logger logger)
|
||||
{
|
||||
_eventAggregator = eventAggregator;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public bool IgnoreDownload(TrackedDownload trackedDownload)
|
||||
{
|
||||
var artist = trackedDownload.RemoteAlbum.Artist;
|
||||
var albums = trackedDownload.RemoteAlbum.Albums;
|
||||
|
||||
if (artist == null || albums.Empty())
|
||||
{
|
||||
_logger.Warn("Unable to ignore download for unknown artist/album");
|
||||
return false;
|
||||
}
|
||||
|
||||
var downloadIgnoredEvent = new DownloadIgnoredEvent
|
||||
{
|
||||
ArtistId = artist.Id,
|
||||
AlbumIds = albums.Select(e => e.Id).ToList(),
|
||||
Quality = trackedDownload.RemoteAlbum.ParsedAlbumInfo.Quality,
|
||||
SourceTitle = trackedDownload.DownloadItem.Title,
|
||||
DownloadClient = trackedDownload.DownloadItem.DownloadClient,
|
||||
DownloadId = trackedDownload.DownloadItem.DownloadId,
|
||||
Message = "Manually ignored"
|
||||
};
|
||||
|
||||
_eventAggregator.PublishEvent(downloadIgnoredEvent);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -131,8 +131,10 @@ namespace NzbDrone.Core.Download.TrackedDownloads
|
|||
|
||||
private bool DownloadIsTrackable(TrackedDownload trackedDownload)
|
||||
{
|
||||
// If the download has already been imported or failed don't track it
|
||||
if (trackedDownload.State == TrackedDownloadState.Imported || trackedDownload.State == TrackedDownloadState.DownloadFailed)
|
||||
// If the download has already been imported or failed or the user ignored it don't track it
|
||||
if (trackedDownload.State == TrackedDownloadState.Imported ||
|
||||
trackedDownload.State == TrackedDownloadState.DownloadFailed ||
|
||||
trackedDownload.State == TrackedDownloadState.Ignored)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -41,7 +41,8 @@ namespace NzbDrone.Core.Download.TrackedDownloads
|
|||
ImportPending,
|
||||
Importing,
|
||||
ImportFailed,
|
||||
Imported
|
||||
Imported,
|
||||
Ignored
|
||||
}
|
||||
|
||||
public enum TrackedDownloadStatus
|
||||
|
|
|
@ -252,6 +252,8 @@ namespace NzbDrone.Core.Download.TrackedDownloads
|
|||
return TrackedDownloadState.Imported;
|
||||
case HistoryEventType.DownloadFailed:
|
||||
return TrackedDownloadState.DownloadFailed;
|
||||
case HistoryEventType.DownloadIgnored:
|
||||
return TrackedDownloadState.Ignored;
|
||||
}
|
||||
|
||||
// Since DownloadComplete is a new event type, we can't assume it exists for old downloads
|
||||
|
|
|
@ -41,6 +41,7 @@ namespace NzbDrone.Core.History
|
|||
TrackFileRenamed = 6,
|
||||
AlbumImportIncomplete = 7,
|
||||
DownloadImported = 8,
|
||||
TrackFileRetagged = 9
|
||||
TrackFileRetagged = 9,
|
||||
DownloadIgnored = 10
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,8 @@ namespace NzbDrone.Core.History
|
|||
IHandle<TrackFileDeletedEvent>,
|
||||
IHandle<TrackFileRenamedEvent>,
|
||||
IHandle<TrackFileRetaggedEvent>,
|
||||
IHandle<ArtistDeletedEvent>
|
||||
IHandle<ArtistDeletedEvent>,
|
||||
IHandle<DownloadIgnoredEvent>
|
||||
{
|
||||
private readonly IHistoryRepository _historyRepository;
|
||||
private readonly Logger _logger;
|
||||
|
@ -369,6 +370,31 @@ namespace NzbDrone.Core.History
|
|||
_historyRepository.DeleteForArtist(message.Artist.Id);
|
||||
}
|
||||
|
||||
public void Handle(DownloadIgnoredEvent message)
|
||||
{
|
||||
var historyToAdd = new List<History>();
|
||||
foreach (var albumId in message.AlbumIds)
|
||||
{
|
||||
var history = new History
|
||||
{
|
||||
EventType = HistoryEventType.DownloadIgnored,
|
||||
Date = DateTime.UtcNow,
|
||||
Quality = message.Quality,
|
||||
SourceTitle = message.SourceTitle,
|
||||
ArtistId = message.ArtistId,
|
||||
AlbumId = albumId,
|
||||
DownloadId = message.DownloadId
|
||||
};
|
||||
|
||||
history.Data.Add("DownloadClient", message.DownloadClient);
|
||||
history.Data.Add("Message", message.Message);
|
||||
|
||||
historyToAdd.Add(history);
|
||||
}
|
||||
|
||||
_historyRepository.InsertMany(historyToAdd);
|
||||
}
|
||||
|
||||
public List<History> Since(DateTime date, HistoryEventType? eventType)
|
||||
{
|
||||
return _historyRepository.Since(date, eventType);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue