From cfb517a90fc56e6c060558675867c09ea32dc6b8 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 (cherry picked from commit b8af3af9f16db96337832c2989f4e7ff3dc2ed30) Closes #5223 --- src/Lidarr.Api.V1/Queue/QueueController.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Lidarr.Api.V1/Queue/QueueController.cs b/src/Lidarr.Api.V1/Queue/QueueController.cs index 23808a566..730b50436 100644 --- a/src/Lidarr.Api.V1/Queue/QueueController.cs +++ b/src/Lidarr.Api.V1/Queue/QueueController.cs @@ -130,15 +130,15 @@ namespace Lidarr.Api.V1.Queue [HttpGet] [Produces("application/json")] - public PagingResource GetQueue([FromQuery] PagingRequestResource paging, bool includeUnknownArtistItems = false, bool includeArtist = false, bool includeAlbum = false, [FromQuery] int[] artistIds = null, DownloadProtocol? protocol = null, int? quality = null) + public PagingResource GetQueue([FromQuery] PagingRequestResource paging, bool includeUnknownArtistItems = false, bool includeArtist = false, bool includeAlbum = false, [FromQuery] int[] artistIds = null, DownloadProtocol? protocol = null, [FromQuery] int[] quality = null) { var pagingResource = new PagingResource(paging); var pagingSpec = pagingResource.MapToPagingSpec("timeleft", SortDirection.Ascending); - return pagingSpec.ApplyToPage((spec) => GetQueue(spec, artistIds?.ToHashSet(), protocol, quality, includeUnknownArtistItems), (q) => MapToResource(q, includeArtist, includeAlbum)); + return pagingSpec.ApplyToPage((spec) => GetQueue(spec, artistIds?.ToHashSet(), protocol, quality?.ToHashSet(), includeUnknownArtistItems), (q) => MapToResource(q, includeArtist, includeAlbum)); } - private PagingSpec GetQueue(PagingSpec pagingSpec, HashSet artistIds, DownloadProtocol? protocol, int? quality, bool includeUnknownArtistItems) + private PagingSpec GetQueue(PagingSpec pagingSpec, HashSet artistIds, DownloadProtocol? protocol, HashSet quality, bool includeUnknownArtistItems) { var ascending = pagingSpec.SortDirection == SortDirection.Ascending; var orderByFunc = GetOrderByFunc(pagingSpec); @@ -148,6 +148,8 @@ namespace Lidarr.Api.V1.Queue var pending = _pendingReleaseService.GetPendingQueue(); var hasArtistIdFilter = artistIds.Any(); + var hasQualityFilter = quality.Any(); + var fullQueue = filteredQueue.Concat(pending).Where(q => { var include = true; @@ -162,9 +164,9 @@ namespace Lidarr.Api.V1.Queue include &= q.Protocol == protocol.Value; } - if (include && quality.HasValue) + if (include && hasQualityFilter) { - include &= q.Quality.Quality.Id == quality.Value; + include &= quality.Contains(q.Quality.Quality.Id); } return include;