Fixed: Filtering queue by multiple qualities

(cherry picked from commit b8af3af9f16db96337832c2989f4e7ff3dc2ed30)

Closes #5223
pull/1829/head
Mark McDowall 3 weeks ago committed by Bogdan
parent 3f81e0254f
commit cfb517a90f

@ -130,15 +130,15 @@ namespace Lidarr.Api.V1.Queue
[HttpGet] [HttpGet]
[Produces("application/json")] [Produces("application/json")]
public PagingResource<QueueResource> 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<QueueResource> 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<QueueResource>(paging); var pagingResource = new PagingResource<QueueResource>(paging);
var pagingSpec = pagingResource.MapToPagingSpec<QueueResource, NzbDrone.Core.Queue.Queue>("timeleft", SortDirection.Ascending); var pagingSpec = pagingResource.MapToPagingSpec<QueueResource, NzbDrone.Core.Queue.Queue>("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<NzbDrone.Core.Queue.Queue> GetQueue(PagingSpec<NzbDrone.Core.Queue.Queue> pagingSpec, HashSet<int> artistIds, DownloadProtocol? protocol, int? quality, bool includeUnknownArtistItems) private PagingSpec<NzbDrone.Core.Queue.Queue> GetQueue(PagingSpec<NzbDrone.Core.Queue.Queue> pagingSpec, HashSet<int> artistIds, DownloadProtocol? protocol, HashSet<int> quality, bool includeUnknownArtistItems)
{ {
var ascending = pagingSpec.SortDirection == SortDirection.Ascending; var ascending = pagingSpec.SortDirection == SortDirection.Ascending;
var orderByFunc = GetOrderByFunc(pagingSpec); var orderByFunc = GetOrderByFunc(pagingSpec);
@ -148,6 +148,8 @@ namespace Lidarr.Api.V1.Queue
var pending = _pendingReleaseService.GetPendingQueue(); var pending = _pendingReleaseService.GetPendingQueue();
var hasArtistIdFilter = artistIds.Any(); var hasArtistIdFilter = artistIds.Any();
var hasQualityFilter = quality.Any();
var fullQueue = filteredQueue.Concat(pending).Where(q => var fullQueue = filteredQueue.Concat(pending).Where(q =>
{ {
var include = true; var include = true;
@ -162,9 +164,9 @@ namespace Lidarr.Api.V1.Queue
include &= q.Protocol == protocol.Value; 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; return include;

Loading…
Cancel
Save