mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-14 11:23:42 +02:00
Show unknown items in queue
New: Download items from unknown series now appear on the queue and can be imported with Manual Import.
This commit is contained in:
parent
5f6f4915a1
commit
de61ecbfd2
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Datastore.Events;
|
||||
using NzbDrone.Core.Download.Pending;
|
||||
@ -30,7 +30,7 @@ private List<QueueResource> GetQueue()
|
||||
|
||||
private IEnumerable<Core.Queue.Queue> GetQueueItems()
|
||||
{
|
||||
var queue = _queueService.GetQueue();
|
||||
var queue = _queueService.GetQueue().Where(q => q.Series != null);
|
||||
var pending = _pendingReleaseService.GetPendingQueue();
|
||||
|
||||
return queue.Concat(pending);
|
||||
@ -46,4 +46,4 @@ public void Handle(PendingReleasesUpdatedEvent message)
|
||||
BroadcastResourceChange(ModelAction.Sync);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public QueueSpecification(IQueueService queueService,
|
||||
public Decision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
|
||||
{
|
||||
var queue = _queueService.GetQueue();
|
||||
var matchingSeries = queue.Where(q => q.RemoteEpisode.Series.Id == subject.Series.Id);
|
||||
var matchingSeries = queue.Where(q => q.RemoteEpisode.Series != null && q.RemoteEpisode.Series.Id == subject.Series.Id);
|
||||
var matchingEpisode = matchingSeries.Where(q => q.RemoteEpisode.Episodes.Select(e => e.Id).Intersect(subject.Episodes.Select(e => e.Id)).Any());
|
||||
|
||||
foreach (var queueItem in matchingEpisode)
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Common.Crypto;
|
||||
@ -40,38 +40,29 @@ public void Remove(int id)
|
||||
_queue.Remove(Find(id));
|
||||
}
|
||||
|
||||
public void Handle(TrackedDownloadRefreshedEvent message)
|
||||
{
|
||||
_queue = message.TrackedDownloads.OrderBy(c => c.DownloadItem.RemainingTime).SelectMany(MapQueue)
|
||||
.ToList();
|
||||
|
||||
_eventAggregator.PublishEvent(new QueueUpdatedEvent());
|
||||
}
|
||||
|
||||
private IEnumerable<Queue> MapQueue(TrackedDownload trackedDownload)
|
||||
{
|
||||
if (trackedDownload.RemoteEpisode.Episodes != null && trackedDownload.RemoteEpisode.Episodes.Any())
|
||||
{
|
||||
foreach (var episode in trackedDownload.RemoteEpisode.Episodes)
|
||||
{
|
||||
yield return MapEpisode(trackedDownload, episode);
|
||||
yield return MapQueueItem(trackedDownload, episode);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// FIXME: Present queue items with unknown series/episodes
|
||||
yield return MapQueueItem(trackedDownload, null);
|
||||
}
|
||||
}
|
||||
|
||||
private Queue MapEpisode(TrackedDownload trackedDownload, Episode episode)
|
||||
private Queue MapQueueItem(TrackedDownload trackedDownload, Episode episode)
|
||||
{
|
||||
var queue = new Queue
|
||||
{
|
||||
Id = HashConverter.GetHashInt31(string.Format("trackedDownload-{0}-ep{1}", trackedDownload.DownloadItem.DownloadId, episode.Id)),
|
||||
Series = trackedDownload.RemoteEpisode.Series,
|
||||
Episode = episode,
|
||||
Quality = trackedDownload.RemoteEpisode.ParsedEpisodeInfo.Quality,
|
||||
Title = trackedDownload.DownloadItem.Title,
|
||||
Title = Parser.Parser.RemoveFileExtension(trackedDownload.DownloadItem.Title),
|
||||
Size = trackedDownload.DownloadItem.TotalSize,
|
||||
Sizeleft = trackedDownload.DownloadItem.RemainingSize,
|
||||
Timeleft = trackedDownload.DownloadItem.RemainingTime,
|
||||
@ -86,6 +77,15 @@ private Queue MapEpisode(TrackedDownload trackedDownload, Episode episode)
|
||||
Indexer = trackedDownload.Indexer
|
||||
};
|
||||
|
||||
if (episode != null)
|
||||
{
|
||||
queue.Id = HashConverter.GetHashInt31(string.Format("trackedDownload-{0}-ep{1}", trackedDownload.DownloadItem.DownloadId, episode.Id));
|
||||
}
|
||||
else
|
||||
{
|
||||
queue.Id = HashConverter.GetHashInt31(string.Format("trackedDownload-{0}", trackedDownload.DownloadItem.DownloadId));
|
||||
}
|
||||
|
||||
if (queue.Timeleft.HasValue)
|
||||
{
|
||||
queue.EstimatedCompletionTime = DateTime.UtcNow.Add(queue.Timeleft.Value);
|
||||
@ -93,5 +93,13 @@ private Queue MapEpisode(TrackedDownload trackedDownload, Episode episode)
|
||||
|
||||
return queue;
|
||||
}
|
||||
|
||||
public void Handle(TrackedDownloadRefreshedEvent message)
|
||||
{
|
||||
_queue = message.TrackedDownloads.OrderBy(c => c.DownloadItem.RemainingTime).SelectMany(MapQueue)
|
||||
.ToList();
|
||||
|
||||
_eventAggregator.PublishEvent(new QueueUpdatedEvent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Datastore.Events;
|
||||
@ -38,7 +38,7 @@ private List<QueueResource> GetQueue()
|
||||
|
||||
if (seriesIdQuery.HasValue)
|
||||
{
|
||||
return fullQueue.Where(q => q.Series.Id == (int)seriesIdQuery).ToResource(includeSeries, includeEpisode);
|
||||
return fullQueue.Where(q => q.Series?.Id == (int)seriesIdQuery).ToResource(includeSeries, includeEpisode);
|
||||
}
|
||||
|
||||
if (episodeIdsQuery.HasValue)
|
||||
@ -49,7 +49,7 @@ private List<QueueResource> GetQueue()
|
||||
.Select(e => Convert.ToInt32(e))
|
||||
.ToList();
|
||||
|
||||
return fullQueue.Where(q => episodeIds.Contains(q.Episode.Id)).ToResource(includeSeries, includeEpisode);
|
||||
return fullQueue.Where(q => q.Episode != null && episodeIds.Contains(q.Episode.Id)).ToResource(includeSeries, includeEpisode);
|
||||
}
|
||||
|
||||
return fullQueue.ToResource(includeSeries, includeEpisode);
|
||||
@ -65,4 +65,4 @@ public void Handle(PendingReleasesUpdatedEvent message)
|
||||
BroadcastResourceChange(ModelAction.Sync);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Datastore.Events;
|
||||
using NzbDrone.Core.Download.Pending;
|
||||
@ -17,32 +18,39 @@ public class QueueModule : SonarrRestModuleWithSignalR<QueueResource, NzbDrone.C
|
||||
{
|
||||
private readonly IQueueService _queueService;
|
||||
private readonly IPendingReleaseService _pendingReleaseService;
|
||||
private readonly IConfigService _configService;
|
||||
|
||||
public QueueModule(IBroadcastSignalRMessage broadcastSignalRMessage, IQueueService queueService, IPendingReleaseService pendingReleaseService)
|
||||
public QueueModule(IBroadcastSignalRMessage broadcastSignalRMessage,
|
||||
IQueueService queueService,
|
||||
IPendingReleaseService pendingReleaseService,
|
||||
IConfigService configService)
|
||||
: base(broadcastSignalRMessage)
|
||||
{
|
||||
_queueService = queueService;
|
||||
_pendingReleaseService = pendingReleaseService;
|
||||
_configService = configService;
|
||||
GetResourcePaged = GetQueue;
|
||||
}
|
||||
|
||||
private PagingResource<QueueResource> GetQueue(PagingResource<QueueResource> pagingResource)
|
||||
{
|
||||
var pagingSpec = pagingResource.MapToPagingSpec<QueueResource, NzbDrone.Core.Queue.Queue>("timeleft", SortDirection.Ascending);
|
||||
var includeUnknownSeriesItems = Request.GetBooleanQueryParameter("includeUnknownSeriesItems");
|
||||
var includeSeries = Request.GetBooleanQueryParameter("includeSeries");
|
||||
var includeEpisode = Request.GetBooleanQueryParameter("includeEpisode");
|
||||
|
||||
return ApplyToPage(GetQueue, pagingSpec, (q) => MapToResource(q, includeSeries, includeEpisode));
|
||||
return ApplyToPage((spec) => GetQueue(spec, includeUnknownSeriesItems), pagingSpec, (q) => MapToResource(q, includeSeries, includeEpisode));
|
||||
}
|
||||
|
||||
private PagingSpec<NzbDrone.Core.Queue.Queue> GetQueue(PagingSpec<NzbDrone.Core.Queue.Queue> pagingSpec)
|
||||
private PagingSpec<NzbDrone.Core.Queue.Queue> GetQueue(PagingSpec<NzbDrone.Core.Queue.Queue> pagingSpec, bool includeUnknownSeriesItems)
|
||||
{
|
||||
var ascending = pagingSpec.SortDirection == SortDirection.Ascending;
|
||||
var orderByFunc = GetOrderByFunc(pagingSpec);
|
||||
|
||||
var queue = _queueService.GetQueue();
|
||||
var filteredQueue = includeUnknownSeriesItems ? queue : queue.Where(q => q.Series != null);
|
||||
var pending = _pendingReleaseService.GetPendingQueue();
|
||||
var fullQueue = queue.Concat(pending).ToList();
|
||||
var fullQueue = filteredQueue.Concat(pending).ToList();
|
||||
IOrderedEnumerable<NzbDrone.Core.Queue.Queue> ordered;
|
||||
|
||||
if (pagingSpec.SortKey == "episode")
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Download.TrackedDownloads;
|
||||
@ -12,8 +12,8 @@ namespace Sonarr.Api.V3.Queue
|
||||
{
|
||||
public class QueueResource : RestResource
|
||||
{
|
||||
public int SeriesId { get; set; }
|
||||
public int EpisodeId { get; set; }
|
||||
public int? SeriesId { get; set; }
|
||||
public int? EpisodeId { get; set; }
|
||||
public SeriesResource Series { get; set; }
|
||||
public EpisodeResource Episode { get; set; }
|
||||
public QualityModel Quality { get; set; }
|
||||
@ -41,10 +41,10 @@ public static QueueResource ToResource(this NzbDrone.Core.Queue.Queue model, boo
|
||||
return new QueueResource
|
||||
{
|
||||
Id = model.Id,
|
||||
SeriesId = model.Series.Id,
|
||||
EpisodeId = model.Episode.Id,
|
||||
Series = includeSeries ? model.Series.ToResource() : null,
|
||||
Episode = includeEpisode ? model.Episode.ToResource() : null,
|
||||
SeriesId = model.Series?.Id,
|
||||
EpisodeId = model.Episode?.Id,
|
||||
Series = includeSeries && model.Series != null ? model.Series.ToResource() : null,
|
||||
Episode = includeEpisode && model.Episode != null ? model.Episode.ToResource() : null,
|
||||
Quality = model.Quality,
|
||||
Size = model.Size,
|
||||
Title = model.Title,
|
||||
|
@ -47,6 +47,7 @@ private QueueStatusResource GetQueueStatus()
|
||||
var resource = new QueueStatusResource
|
||||
{
|
||||
Count = queue.Count + pending.Count,
|
||||
UnknownCount = queue.Count(q => q.Series == null),
|
||||
Errors = queue.Any(q => q.TrackedDownloadStatus.Equals("Error", StringComparison.InvariantCultureIgnoreCase)),
|
||||
Warnings = queue.Any(q => q.TrackedDownloadStatus.Equals("Warning", StringComparison.InvariantCultureIgnoreCase))
|
||||
};
|
||||
|
@ -1,10 +1,11 @@
|
||||
using Sonarr.Http.REST;
|
||||
using Sonarr.Http.REST;
|
||||
|
||||
namespace Sonarr.Api.V3.Queue
|
||||
{
|
||||
public class QueueStatusResource : RestResource
|
||||
{
|
||||
public int Count { get; set; }
|
||||
public int UnknownCount { get; set; }
|
||||
public bool Errors { get; set; }
|
||||
public bool Warnings { get; set; }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user