mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-17 17:14:18 +02:00
New: Drone now uses the Download Client API to determine if a download is ready for import. (User configuration is required to replace the drone factory with this feature)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Download;
|
||||
@@ -12,39 +13,23 @@ namespace NzbDrone.Core.Queue
|
||||
|
||||
public class QueueService : IQueueService
|
||||
{
|
||||
private readonly IProvideDownloadClient _downloadClientProvider;
|
||||
private readonly IDownloadTrackingService _downloadTrackingService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public QueueService(IProvideDownloadClient downloadClientProvider, Logger logger)
|
||||
public QueueService(IDownloadTrackingService downloadTrackingService, Logger logger)
|
||||
{
|
||||
_downloadClientProvider = downloadClientProvider;
|
||||
_downloadTrackingService = downloadTrackingService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public List<Queue> GetQueue()
|
||||
{
|
||||
var downloadClient = _downloadClientProvider.GetDownloadClient();
|
||||
var queueItems = _downloadTrackingService.GetQueuedDownloads().Select(v => v.DownloadItem).ToList();
|
||||
|
||||
if (downloadClient == null)
|
||||
{
|
||||
_logger.Debug("Download client is not configured.");
|
||||
return new List<Queue>();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var queueItems = downloadClient.GetQueue();
|
||||
|
||||
return MapQueue(queueItems);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error("Error getting queue from download client: " + downloadClient.ToString(), ex);
|
||||
return new List<Queue>();
|
||||
}
|
||||
return MapQueue(queueItems);
|
||||
}
|
||||
|
||||
private List<Queue> MapQueue(IEnumerable<QueueItem> queueItems)
|
||||
private List<Queue> MapQueue(IEnumerable<DownloadClientItem> queueItems)
|
||||
{
|
||||
var queued = new List<Queue>();
|
||||
|
||||
@@ -53,15 +38,16 @@ namespace NzbDrone.Core.Queue
|
||||
foreach (var episode in queueItem.RemoteEpisode.Episodes)
|
||||
{
|
||||
var queue = new Queue();
|
||||
queue.Id = queueItem.Id.GetHashCode() + episode.Id;
|
||||
queue.Id = queueItem.DownloadClientId.GetHashCode() + episode.Id;
|
||||
queue.Series = queueItem.RemoteEpisode.Series;
|
||||
queue.Episode = episode;
|
||||
queue.Quality = queueItem.RemoteEpisode.ParsedEpisodeInfo.Quality;
|
||||
queue.Title = queueItem.Title;
|
||||
queue.Size = queueItem.Size;
|
||||
queue.Sizeleft = queueItem.Sizeleft;
|
||||
queue.Timeleft = queueItem.Timeleft;
|
||||
queue.Status = queueItem.Status;
|
||||
queue.Size = queueItem.TotalSize;
|
||||
queue.Sizeleft = queueItem.RemainingSize;
|
||||
queue.Timeleft = queueItem.RemainingTime;
|
||||
queue.Status = queueItem.Status.ToString();
|
||||
queue.RemoteEpisode = queueItem.RemoteEpisode;
|
||||
queued.Add(queue);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user