mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-07-03 12:23:27 +02:00
Trickplay task pagination
This commit is contained in:
parent
d338253242
commit
f82af04781
|
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Controller.Configuration;
|
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Library;
|
using MediaBrowser.Controller.Library;
|
||||||
using MediaBrowser.Controller.Trickplay;
|
using MediaBrowser.Controller.Trickplay;
|
||||||
|
@ -11,6 +10,7 @@ using MediaBrowser.Model.Entities;
|
||||||
using MediaBrowser.Model.Globalization;
|
using MediaBrowser.Model.Globalization;
|
||||||
using MediaBrowser.Model.Tasks;
|
using MediaBrowser.Model.Tasks;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using TagLib.Ape;
|
||||||
|
|
||||||
namespace MediaBrowser.Providers.Trickplay;
|
namespace MediaBrowser.Providers.Trickplay;
|
||||||
|
|
||||||
|
@ -19,6 +19,8 @@ namespace MediaBrowser.Providers.Trickplay;
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class TrickplayImagesTask : IScheduledTask
|
public class TrickplayImagesTask : IScheduledTask
|
||||||
{
|
{
|
||||||
|
private const int QueryPageLimit = 100;
|
||||||
|
|
||||||
private readonly ILogger<TrickplayImagesTask> _logger;
|
private readonly ILogger<TrickplayImagesTask> _logger;
|
||||||
private readonly ILibraryManager _libraryManager;
|
private readonly ILibraryManager _libraryManager;
|
||||||
private readonly ILocalizationManager _localization;
|
private readonly ILocalizationManager _localization;
|
||||||
|
@ -71,38 +73,46 @@ public class TrickplayImagesTask : IScheduledTask
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task ExecuteAsync(IProgress<double> progress, CancellationToken cancellationToken)
|
public async Task ExecuteAsync(IProgress<double> progress, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var items = _libraryManager.GetItemList(new InternalItemsQuery
|
var query = new InternalItemsQuery
|
||||||
{
|
{
|
||||||
MediaTypes = new[] { MediaType.Video },
|
MediaTypes = new[] { MediaType.Video },
|
||||||
|
SourceTypes = new[] { SourceType.Library },
|
||||||
IsVirtualItem = false,
|
IsVirtualItem = false,
|
||||||
IsFolder = false,
|
IsFolder = false,
|
||||||
Recursive = true
|
Recursive = true,
|
||||||
}).OfType<Video>().ToList();
|
Limit = QueryPageLimit
|
||||||
|
};
|
||||||
|
|
||||||
|
var numberOfVideos = _libraryManager.GetCount(query);
|
||||||
|
|
||||||
|
var startIndex = 0;
|
||||||
var numComplete = 0;
|
var numComplete = 0;
|
||||||
|
|
||||||
foreach (var item in items)
|
while (startIndex < numberOfVideos)
|
||||||
{
|
{
|
||||||
try
|
query.StartIndex = startIndex;
|
||||||
|
var videos = _libraryManager.GetItemList(query).OfType<Video>().ToList();
|
||||||
|
|
||||||
|
foreach (var video in videos)
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
await _trickplayManager.RefreshTrickplayDataAsync(item, false, cancellationToken).ConfigureAwait(false);
|
|
||||||
}
|
try
|
||||||
catch (OperationCanceledException)
|
{
|
||||||
{
|
await _trickplayManager.RefreshTrickplayDataAsync(video, false, cancellationToken).ConfigureAwait(false);
|
||||||
break;
|
}
|
||||||
}
|
catch (Exception ex)
|
||||||
catch (Exception ex)
|
{
|
||||||
{
|
_logger.LogError(ex, "Error creating trickplay files for {ItemName}", video.Name);
|
||||||
_logger.LogError(ex, "Error creating trickplay files for {ItemName}", item.Name);
|
}
|
||||||
|
|
||||||
|
numComplete++;
|
||||||
|
progress.Report(100d * numComplete / numberOfVideos);
|
||||||
}
|
}
|
||||||
|
|
||||||
numComplete++;
|
startIndex += QueryPageLimit;
|
||||||
double percent = numComplete;
|
|
||||||
percent /= items.Count;
|
|
||||||
percent *= 100;
|
|
||||||
|
|
||||||
progress.Report(percent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
progress.Report(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue