aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Providers/Trickplay
diff options
context:
space:
mode:
authorTim Eisele <Shadowghost@users.noreply.github.com>2024-09-07 19:23:48 +0200
committerGitHub <noreply@github.com>2024-09-07 11:23:48 -0600
commitc56dbc1c4410e1b0ec31ca901809b6f627bbb6ed (patch)
tree56df7024be555125eae955da94dd5dda248b8f59 /MediaBrowser.Providers/Trickplay
parent675a8a9ec91da47e37ace6161ba5a5a0e20a7839 (diff)
Enhance Trickplay (#11883)
Diffstat (limited to 'MediaBrowser.Providers/Trickplay')
-rw-r--r--MediaBrowser.Providers/Trickplay/TrickplayImagesTask.cs3
-rw-r--r--MediaBrowser.Providers/Trickplay/TrickplayMoveImagesTask.cs110
-rw-r--r--MediaBrowser.Providers/Trickplay/TrickplayProvider.cs6
3 files changed, 115 insertions, 4 deletions
diff --git a/MediaBrowser.Providers/Trickplay/TrickplayImagesTask.cs b/MediaBrowser.Providers/Trickplay/TrickplayImagesTask.cs
index 90c2ff8dd..31c0eeb31 100644
--- a/MediaBrowser.Providers/Trickplay/TrickplayImagesTask.cs
+++ b/MediaBrowser.Providers/Trickplay/TrickplayImagesTask.cs
@@ -98,7 +98,8 @@ public class TrickplayImagesTask : IScheduledTask
try
{
- await _trickplayManager.RefreshTrickplayDataAsync(video, false, cancellationToken).ConfigureAwait(false);
+ var libraryOptions = _libraryManager.GetLibraryOptions(video);
+ await _trickplayManager.RefreshTrickplayDataAsync(video, false, libraryOptions, cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{
diff --git a/MediaBrowser.Providers/Trickplay/TrickplayMoveImagesTask.cs b/MediaBrowser.Providers/Trickplay/TrickplayMoveImagesTask.cs
new file mode 100644
index 000000000..c581fd26c
--- /dev/null
+++ b/MediaBrowser.Providers/Trickplay/TrickplayMoveImagesTask.cs
@@ -0,0 +1,110 @@
+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;
+
+/// <summary>
+/// Class TrickplayMoveImagesTask.
+/// </summary>
+public class TrickplayMoveImagesTask : IScheduledTask
+{
+ private const int QueryPageLimit = 100;
+
+ private readonly ILogger<TrickplayMoveImagesTask> _logger;
+ private readonly ILibraryManager _libraryManager;
+ private readonly ILocalizationManager _localization;
+ private readonly ITrickplayManager _trickplayManager;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="TrickplayMoveImagesTask"/> class.
+ /// </summary>
+ /// <param name="logger">The logger.</param>
+ /// <param name="libraryManager">The library manager.</param>
+ /// <param name="localization">The localization manager.</param>
+ /// <param name="trickplayManager">The trickplay manager.</param>
+ public TrickplayMoveImagesTask(
+ ILogger<TrickplayMoveImagesTask> logger,
+ ILibraryManager libraryManager,
+ ILocalizationManager localization,
+ ITrickplayManager trickplayManager)
+ {
+ _libraryManager = libraryManager;
+ _logger = logger;
+ _localization = localization;
+ _trickplayManager = trickplayManager;
+ }
+
+ /// <inheritdoc />
+ public string Name => _localization.GetLocalizedString("TaskMoveTrickplayImages");
+
+ /// <inheritdoc />
+ public string Description => _localization.GetLocalizedString("TaskMoveTrickplayImagesDescription");
+
+ /// <inheritdoc />
+ public string Key => "MoveTrickplayImages";
+
+ /// <inheritdoc />
+ public string Category => _localization.GetLocalizedString("TasksMaintenanceCategory");
+
+ /// <inheritdoc />
+ public IEnumerable<TaskTriggerInfo> GetDefaultTriggers() => [];
+
+ /// <inheritdoc />
+ public async Task ExecuteAsync(IProgress<double> progress, CancellationToken cancellationToken)
+ {
+ var trickplayItems = await _trickplayManager.GetTrickplayItemsAsync().ConfigureAwait(false);
+ var query = new InternalItemsQuery
+ {
+ MediaTypes = [MediaType.Video],
+ SourceTypes = [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<Video>().ToList();
+ videos.RemoveAll(i => !trickplayItems.Contains(i.Id));
+
+ foreach (var video in videos)
+ {
+ cancellationToken.ThrowIfCancellationRequested();
+
+ try
+ {
+ var libraryOptions = _libraryManager.GetLibraryOptions(video);
+ await _trickplayManager.MoveGeneratedTrickplayDataAsync(video, libraryOptions, cancellationToken).ConfigureAwait(false);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error moving trickplay files for {ItemName}", video.Name);
+ }
+
+ numComplete++;
+ progress.Report(100d * numComplete / numberOfVideos);
+ }
+
+ startIndex += QueryPageLimit;
+ }
+
+ progress.Report(100);
+ }
+}
diff --git a/MediaBrowser.Providers/Trickplay/TrickplayProvider.cs b/MediaBrowser.Providers/Trickplay/TrickplayProvider.cs
index 9dc4446fc..2c74e5f70 100644
--- a/MediaBrowser.Providers/Trickplay/TrickplayProvider.cs
+++ b/MediaBrowser.Providers/Trickplay/TrickplayProvider.cs
@@ -99,7 +99,7 @@ public class TrickplayProvider : ICustomMetadataProvider<Episode>,
{
var libraryOptions = _libraryManager.GetLibraryOptions(video);
bool? enableDuringScan = libraryOptions?.ExtractTrickplayImagesDuringLibraryScan;
- bool replace = options.ReplaceAllImages;
+ bool replace = options.RegenerateTrickplay && options.MetadataRefreshMode > MetadataRefreshMode.Default;
if (!enableDuringScan.GetValueOrDefault(false))
{
@@ -108,11 +108,11 @@ public class TrickplayProvider : ICustomMetadataProvider<Episode>,
if (_config.Configuration.TrickplayOptions.ScanBehavior == TrickplayScanBehavior.Blocking)
{
- await _trickplayManager.RefreshTrickplayDataAsync(video, replace, cancellationToken).ConfigureAwait(false);
+ await _trickplayManager.RefreshTrickplayDataAsync(video, replace, libraryOptions, cancellationToken).ConfigureAwait(false);
}
else
{
- _ = _trickplayManager.RefreshTrickplayDataAsync(video, replace, cancellationToken).ConfigureAwait(false);
+ _ = _trickplayManager.RefreshTrickplayDataAsync(video, replace, libraryOptions, cancellationToken).ConfigureAwait(false);
}
// The core doesn't need to trigger any save operations over this