using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Trickplay;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.Tasks;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Providers.Trickplay;
///
/// Class TrickplayImagesTask.
///
public class TrickplayImagesTask : IScheduledTask
{
private const int QueryPageLimit = 100;
private readonly ILogger _logger;
private readonly ILibraryManager _libraryManager;
private readonly ILocalizationManager _localization;
private readonly ITrickplayManager _trickplayManager;
///
/// Initializes a new instance of the class.
///
/// The logger.
/// The library manager.
/// The localization manager.
/// The trickplay manager.
public TrickplayImagesTask(
ILogger logger,
ILibraryManager libraryManager,
ILocalizationManager localization,
ITrickplayManager trickplayManager)
{
_libraryManager = libraryManager;
_logger = logger;
_localization = localization;
_trickplayManager = trickplayManager;
}
///
public string Name => _localization.GetLocalizedString("TaskRefreshTrickplayImages");
///
public string Description => _localization.GetLocalizedString("TaskRefreshTrickplayImagesDescription");
///
public string Key => "RefreshTrickplayImages";
///
public string Category => _localization.GetLocalizedString("TasksLibraryCategory");
///
public IEnumerable GetDefaultTriggers()
{
return new[]
{
new TaskTriggerInfo
{
Type = TaskTriggerInfo.TriggerDaily,
TimeOfDayTicks = TimeSpan.FromHours(3).Ticks
}
};
}
///
public async Task ExecuteAsync(IProgress progress, CancellationToken cancellationToken)
{
var query = new InternalItemsQuery
{
MediaTypes = new[] { MediaType.Video },
SourceTypes = new[] { SourceType.Library },
IsVirtualItem = false,
IsFolder = false,
Recursive = true,
Limit = QueryPageLimit
};
var numberOfVideos = _libraryManager.GetCount(query);
var startIndex = 0;
var numComplete = 0;
while (startIndex < numberOfVideos)
{
query.StartIndex = startIndex;
var videos = _libraryManager.GetItemList(query).OfType