feat: prioritise and blacklist media and overview in setting page of progress in adding info
This commit is contained in:
@@ -3,8 +3,10 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Jellyfin.Data.Enums;
|
||||
using Jellyfin.Plugin.JRay.Models;
|
||||
using Jellyfin.Plugin.JRay.Services;
|
||||
using Jellyfin.Plugin.JRay.Services.Interfaces;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -26,16 +28,19 @@ public class TasksController : ControllerBase
|
||||
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
private readonly ITruthDataService _truthDataService;
|
||||
private readonly IMediaPolicyStore _policyStore;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TasksController"/> class.
|
||||
/// </summary>
|
||||
/// <param name="libraryManager">The Jellyfin library manager.</param>
|
||||
/// <param name="truthDataService">The truth data service.</param>
|
||||
public TasksController(ILibraryManager libraryManager, ITruthDataService truthDataService)
|
||||
/// <param name="policyStore">The prioritise/ignore policy store.</param>
|
||||
public TasksController(ILibraryManager libraryManager, ITruthDataService truthDataService, IMediaPolicyStore policyStore)
|
||||
{
|
||||
_libraryManager = libraryManager;
|
||||
_truthDataService = truthDataService;
|
||||
_policyStore = policyStore;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -48,6 +53,7 @@ public class TasksController : ControllerBase
|
||||
public ActionResult<IEnumerable<PendingExtractionItem>> GetPending([FromQuery] int limit = DefaultLimit)
|
||||
{
|
||||
var effectiveLimit = Math.Clamp(limit, 1, MaxLimit);
|
||||
var rules = _policyStore.GetRules();
|
||||
|
||||
var items = _libraryManager.GetItemList(new InternalItemsQuery
|
||||
{
|
||||
@@ -56,17 +62,38 @@ public class TasksController : ControllerBase
|
||||
Recursive = true,
|
||||
});
|
||||
|
||||
// Keep only items that still need truth data, then apply the policy:
|
||||
// drop anything ignored, and order prioritised items ahead of the rest.
|
||||
// Randomise within each tier so the backlog still spreads across workers.
|
||||
var pending = items
|
||||
.Where(item => !string.IsNullOrEmpty(item.Path) && !_truthDataService.HasTruth(item.Id, item.Path))
|
||||
.OrderBy(_ => Random.Shared.Next())
|
||||
.Take(effectiveLimit)
|
||||
.Select(item => new PendingExtractionItem
|
||||
.Select(item => new
|
||||
{
|
||||
ItemId = item.Id,
|
||||
Path = item.Path,
|
||||
Name = item.Name
|
||||
Item = item,
|
||||
Action = PolicyResolver.Resolve(rules, item.Id, GetSeriesId(item), item.Genres)
|
||||
})
|
||||
.Where(x => x.Action != PolicyAction.Ignore)
|
||||
.OrderByDescending(x => x.Action == PolicyAction.Prioritise)
|
||||
.ThenBy(_ => Random.Shared.Next())
|
||||
.Take(effectiveLimit)
|
||||
.Select(x => new PendingExtractionItem
|
||||
{
|
||||
ItemId = x.Item.Id,
|
||||
Path = x.Item.Path,
|
||||
Name = x.Item.Name
|
||||
});
|
||||
|
||||
return Ok(pending);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the series id for an episode, or <see cref="Guid.Empty"/> for any
|
||||
/// other item type (so series rules only ever match episodes).
|
||||
/// </summary>
|
||||
/// <param name="item">The library item.</param>
|
||||
/// <returns>The owning series id, or empty.</returns>
|
||||
internal static Guid GetSeriesId(BaseItem item)
|
||||
{
|
||||
return item is Episode episode ? episode.SeriesId : Guid.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user