From b8af3af9f16db96337832c2989f4e7ff3dc2ed30 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 3 Nov 2024 15:24:06 -0800 Subject: [PATCH] Fixed: Filtering queue by multiple qualities --- src/Sonarr.Api.V3/Queue/QueueController.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Sonarr.Api.V3/Queue/QueueController.cs b/src/Sonarr.Api.V3/Queue/QueueController.cs index 96917878e..0fc12bb14 100644 --- a/src/Sonarr.Api.V3/Queue/QueueController.cs +++ b/src/Sonarr.Api.V3/Queue/QueueController.cs @@ -136,7 +136,7 @@ public object RemoveMany([FromBody] QueueBulkResource resource, [FromQuery] bool [HttpGet] [Produces("application/json")] - public PagingResource GetQueue([FromQuery] PagingRequestResource paging, bool includeUnknownSeriesItems = false, bool includeSeries = false, bool includeEpisode = false, [FromQuery] int[] seriesIds = null, DownloadProtocol? protocol = null, [FromQuery] int[] languages = null, int? quality = null) + public PagingResource GetQueue([FromQuery] PagingRequestResource paging, bool includeUnknownSeriesItems = false, bool includeSeries = false, bool includeEpisode = false, [FromQuery] int[] seriesIds = null, DownloadProtocol? protocol = null, [FromQuery] int[] languages = null, [FromQuery] int[] quality = null) { var pagingResource = new PagingResource(paging); var pagingSpec = pagingResource.MapToPagingSpec( @@ -165,10 +165,10 @@ public PagingResource GetQueue([FromQuery] PagingRequestResource "timeleft", SortDirection.Ascending); - return pagingSpec.ApplyToPage((spec) => GetQueue(spec, seriesIds?.ToHashSet(), protocol, languages?.ToHashSet(), quality, includeUnknownSeriesItems), (q) => MapToResource(q, includeSeries, includeEpisode)); + return pagingSpec.ApplyToPage((spec) => GetQueue(spec, seriesIds?.ToHashSet(), protocol, languages?.ToHashSet(), quality?.ToHashSet(), includeUnknownSeriesItems), (q) => MapToResource(q, includeSeries, includeEpisode)); } - private PagingSpec GetQueue(PagingSpec pagingSpec, HashSet seriesIds, DownloadProtocol? protocol, HashSet languages, int? quality, bool includeUnknownSeriesItems) + private PagingSpec GetQueue(PagingSpec pagingSpec, HashSet seriesIds, DownloadProtocol? protocol, HashSet languages, HashSet quality, bool includeUnknownSeriesItems) { var ascending = pagingSpec.SortDirection == SortDirection.Ascending; var orderByFunc = GetOrderByFunc(pagingSpec); @@ -179,6 +179,8 @@ public PagingResource GetQueue([FromQuery] PagingRequestResource var hasSeriesIdFilter = seriesIds.Any(); var hasLanguageFilter = languages.Any(); + var hasQualityFilter = quality.Any(); + var fullQueue = filteredQueue.Concat(pending).Where(q => { var include = true; @@ -198,9 +200,9 @@ public PagingResource GetQueue([FromQuery] PagingRequestResource include &= q.Languages.Any(l => languages.Contains(l.Id)); } - if (include && quality.HasValue) + if (include && hasQualityFilter) { - include &= q.Quality.Quality.Id == quality.Value; + include &= quality.Contains(q.Quality.Quality.Id); } return include; @@ -282,7 +284,7 @@ public PagingResource GetQueue([FromQuery] PagingRequestResource switch (pagingSpec.SortKey) { case "status": - return q => q.Status; + return q => q.Status.ToString(); case "series.sortTitle": return q => q.Series?.SortTitle ?? q.Title; case "title":