Import Keyframes into database (#13771)

* Migrate keyframe data into database

* Clear database table before import to handle failed migrations
This commit is contained in:
Tim Eisele
2025-04-03 02:06:40 +02:00
committed by GitHub
parent 49ac705867
commit 0573999d5e
22 changed files with 2128 additions and 78 deletions

View File

@@ -9,7 +9,6 @@ using Jellyfin.MediaEncoding.Hls.Extractors;
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.Tasks;
@@ -23,7 +22,7 @@ public class KeyframeExtractionScheduledTask : IScheduledTask
private readonly ILocalizationManager _localizationManager;
private readonly ILibraryManager _libraryManager;
private readonly IKeyframeExtractor[] _keyframeExtractors;
private static readonly BaseItemKind[] _itemTypes = { BaseItemKind.Episode, BaseItemKind.Movie };
private static readonly BaseItemKind[] _itemTypes = [BaseItemKind.Episode, BaseItemKind.Movie];
/// <summary>
/// Initializes a new instance of the <see cref="KeyframeExtractionScheduledTask"/> class.
@@ -55,11 +54,11 @@ public class KeyframeExtractionScheduledTask : IScheduledTask
{
var query = new InternalItemsQuery
{
MediaTypes = new[] { MediaType.Video },
MediaTypes = [MediaType.Video],
IsVirtualItem = false,
IncludeItemTypes = _itemTypes,
DtoOptions = new DtoOptions(true),
SourceTypes = new[] { SourceType.Library },
SourceTypes = [SourceType.Library],
Recursive = true,
Limit = Pagesize
};
@@ -74,19 +73,16 @@ public class KeyframeExtractionScheduledTask : IScheduledTask
query.StartIndex = startIndex;
var videos = _libraryManager.GetItemList(query);
var currentPageCount = videos.Count;
// TODO parallelize with Parallel.ForEach?
for (var i = 0; i < currentPageCount; i++)
foreach (var video in videos)
{
var video = videos[i];
// Only local files supported
if (video.IsFileProtocol && File.Exists(video.Path))
var path = video.Path;
if (File.Exists(path))
{
for (var j = 0; j < _keyframeExtractors.Length; j++)
foreach (var extractor in _keyframeExtractors)
{
var extractor = _keyframeExtractors[j];
// The cache decorator will make sure to save them in the data dir
if (extractor.TryExtractKeyframes(video.Path, out _))
// The cache decorator will make sure to save the keyframes
if (extractor.TryExtractKeyframes(video.Id, path, out _))
{
break;
}
@@ -107,5 +103,5 @@ public class KeyframeExtractionScheduledTask : IScheduledTask
}
/// <inheritdoc />
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers() => Enumerable.Empty<TaskTriggerInfo>();
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers() => [];
}