1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-21 23:32:27 +00:00

Fixed: Filtering queue by multiple qualities

(cherry picked from commit b8af3af9f16db96337832c2989f4e7ff3dc2ed30)

Closes #5223
This commit is contained in:
Mark McDowall 2024-11-03 15:24:06 -08:00 committed by Bogdan
parent 3f81e0254f
commit cfb517a90f

View file

@ -130,15 +130,15 @@ public object RemoveMany([FromBody] QueueBulkResource resource, [FromQuery] bool
[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 @@ public PagingResource<QueueResource> GetQueue([FromQuery] PagingRequestResource
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 @@ public PagingResource<QueueResource> GetQueue([FromQuery] PagingRequestResource
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;