Remove dependency on shared media item queue
This commit is contained in:
parent
2c3577ea23
commit
bcb5e5ea30
@ -53,10 +53,7 @@ public class TroubleshootingController : ControllerBase
|
||||
|
||||
bundle.Append("* Queue contents: ");
|
||||
bundle.Append(Plugin.Instance!.TotalQueued);
|
||||
bundle.Append(" episodes, ");
|
||||
bundle.Append(Plugin.Instance!.AnalysisQueue.Count);
|
||||
bundle.Append(" seasons");
|
||||
bundle.Append('\n');
|
||||
bundle.Append(" episodes\n");
|
||||
|
||||
bundle.Append(FFmpegWrapper.GetChromaprintLogs());
|
||||
|
||||
|
@ -40,7 +40,7 @@ public class VisualizationController : ControllerBase
|
||||
var showSeasons = new Dictionary<string, HashSet<string>>();
|
||||
|
||||
// Loop through all seasons in the analysis queue
|
||||
foreach (var kvp in Plugin.Instance!.AnalysisQueue)
|
||||
foreach (var kvp in Plugin.Instance!.QueuedMediaItems)
|
||||
{
|
||||
// Check that this season contains at least one episode.
|
||||
var episodes = kvp.Value;
|
||||
@ -104,10 +104,8 @@ public class VisualizationController : ControllerBase
|
||||
[HttpGet("Episode/{Id}/Chromaprint")]
|
||||
public ActionResult<uint[]> GetEpisodeFingerprint([FromRoute] Guid id)
|
||||
{
|
||||
var queue = Plugin.Instance!.AnalysisQueue;
|
||||
|
||||
// Search through all queued episodes to find the requested id
|
||||
foreach (var season in queue)
|
||||
foreach (var season in Plugin.Instance!.QueuedMediaItems)
|
||||
{
|
||||
foreach (var needle in season.Value)
|
||||
{
|
||||
@ -180,7 +178,7 @@ public class VisualizationController : ControllerBase
|
||||
/// <returns>Boolean indicating if the requested season was found.</returns>
|
||||
private bool LookupSeasonByName(string series, string season, out List<QueuedEpisode> episodes)
|
||||
{
|
||||
foreach (var queuedEpisodes in Plugin.Instance!.AnalysisQueue)
|
||||
foreach (var queuedEpisodes in Plugin.Instance!.QueuedMediaItems)
|
||||
{
|
||||
var first = queuedEpisodes.Value[0];
|
||||
var firstSeasonName = GetSeasonName(first);
|
||||
|
@ -57,7 +57,7 @@ public class Entrypoint : IServerEntryPoint
|
||||
|
||||
try
|
||||
{
|
||||
// Enqueue all episodes at startup so the fingerprint visualizer works before the task is started.
|
||||
// Enqueue all episodes at startup to ensure any FFmpeg errors appear as early as possible
|
||||
_logger.LogInformation("Running startup enqueue");
|
||||
var queueManager = new QueueManager(_loggerFactory.CreateLogger<QueueManager>(), _libraryManager);
|
||||
queueManager.EnqueueAllEpisodes();
|
||||
@ -67,11 +67,6 @@ public class Entrypoint : IServerEntryPoint
|
||||
_logger.LogError("Unable to run startup enqueue: {Exception}", ex);
|
||||
}
|
||||
|
||||
_logger.LogDebug(
|
||||
"Total enqueued seasons: {Count} ({Episodes} episodes)",
|
||||
Plugin.Instance!.AnalysisQueue.Count,
|
||||
Plugin.Instance!.TotalQueued);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
@ -92,9 +92,9 @@ public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
||||
public Dictionary<Guid, Intro> Intros { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mapping of season ids to episodes that have been queued for fingerprinting.
|
||||
/// Gets the most recent media item queue.
|
||||
/// </summary>
|
||||
public Dictionary<Guid, List<QueuedEpisode>> AnalysisQueue { get; } = new();
|
||||
public Dictionary<Guid, List<QueuedEpisode>> QueuedMediaItems { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the total number of episodes in the queue.
|
||||
|
@ -2,12 +2,12 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Jellyfin.Data.Enums;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
/// <summary>
|
||||
@ -19,7 +19,8 @@ public class QueueManager
|
||||
private ILogger<QueueManager> _logger;
|
||||
|
||||
private double analysisPercent;
|
||||
private IList<string> selectedLibraries;
|
||||
private List<string> selectedLibraries;
|
||||
private Dictionary<Guid, List<QueuedEpisode>> _queuedEpisodes;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="QueueManager"/> class.
|
||||
@ -31,13 +32,15 @@ public class QueueManager
|
||||
_logger = logger;
|
||||
_libraryManager = libraryManager;
|
||||
|
||||
selectedLibraries = new List<string>();
|
||||
selectedLibraries = new();
|
||||
_queuedEpisodes = new();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Iterates through all libraries on the server and queues all episodes for analysis.
|
||||
/// </summary>
|
||||
public void EnqueueAllEpisodes()
|
||||
/// <returns>Queued media items.</returns>
|
||||
public ReadOnlyDictionary<Guid, List<QueuedEpisode>> EnqueueAllEpisodes()
|
||||
{
|
||||
// Assert that ffmpeg with chromaprint is installed
|
||||
if (!FFmpegWrapper.CheckFFmpegVersion())
|
||||
@ -46,20 +49,13 @@ public class QueueManager
|
||||
"ffmpeg with chromaprint is not installed on this system - episodes will not be analyzed. If Jellyfin is running natively, install jellyfin-ffmpeg5. If Jellyfin is running in a container, upgrade it to the latest version of 10.8.0.");
|
||||
}
|
||||
|
||||
Plugin.Instance!.AnalysisQueue.Clear();
|
||||
Plugin.Instance!.TotalQueued = 0;
|
||||
|
||||
LoadAnalysisSettings();
|
||||
|
||||
// For all selected TV show libraries, enqueue all contained items.
|
||||
// For all selected libraries, enqueue all contained episodes.
|
||||
foreach (var folder in _libraryManager.GetVirtualFolders())
|
||||
{
|
||||
if (folder.CollectionType != CollectionTypeOptions.TvShows)
|
||||
{
|
||||
_logger.LogDebug("Not analyzing library \"{Name}\": not a TV show library", folder.Name);
|
||||
continue;
|
||||
}
|
||||
|
||||
// If libraries have been selected for analysis, ensure this library was selected.
|
||||
if (selectedLibraries.Count > 0 && !selectedLibraries.Contains(folder.Name))
|
||||
{
|
||||
@ -81,6 +77,14 @@ public class QueueManager
|
||||
_logger.LogError("Failed to enqueue items from library {Name}: {Exception}", folder.Name, ex);
|
||||
}
|
||||
}
|
||||
|
||||
Plugin.Instance!.QueuedMediaItems.Clear();
|
||||
foreach (var kvp in _queuedEpisodes)
|
||||
{
|
||||
Plugin.Instance!.QueuedMediaItems[kvp.Key] = kvp.Value;
|
||||
}
|
||||
|
||||
return new(_queuedEpisodes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -156,7 +160,7 @@ public class QueueManager
|
||||
{
|
||||
if (item is not Episode episode)
|
||||
{
|
||||
_logger.LogError("Item {Name} is not an episode", item.Name);
|
||||
_logger.LogDebug("Item {Name} is not an episode", item.Name);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -198,11 +202,11 @@ public class QueueManager
|
||||
60 * Plugin.Instance!.Configuration.AnalysisLengthLimit);
|
||||
|
||||
// Allocate a new list for each new season
|
||||
Plugin.Instance!.AnalysisQueue.TryAdd(episode.SeasonId, new List<QueuedEpisode>());
|
||||
_queuedEpisodes.TryAdd(episode.SeasonId, new List<QueuedEpisode>());
|
||||
|
||||
// Queue the episode for analysis
|
||||
var maxCreditsDuration = Plugin.Instance!.Configuration.MaximumEpisodeCreditsDuration * 60;
|
||||
Plugin.Instance.AnalysisQueue[episode.SeasonId].Add(new QueuedEpisode()
|
||||
_queuedEpisodes[episode.SeasonId].Add(new QueuedEpisode()
|
||||
{
|
||||
SeriesName = episode.SeriesName,
|
||||
SeasonNumber = episode.AiredSeasonNumber ?? 0,
|
||||
|
@ -84,9 +84,7 @@ public class DetectCreditsTask : IScheduledTask
|
||||
_loggerFactory.CreateLogger<QueueManager>(),
|
||||
_libraryManager);
|
||||
|
||||
queueManager.EnqueueAllEpisodes();
|
||||
|
||||
var queue = Plugin.Instance!.AnalysisQueue;
|
||||
var queue = queueManager.EnqueueAllEpisodes();
|
||||
|
||||
if (queue.Count == 0)
|
||||
{
|
||||
@ -142,7 +140,11 @@ public class DetectCreditsTask : IScheduledTask
|
||||
ex);
|
||||
}
|
||||
|
||||
progress.Report((totalProcessed * 100) / Plugin.Instance!.TotalQueued);
|
||||
var total = Plugin.Instance!.TotalQueued;
|
||||
if (total > 0)
|
||||
{
|
||||
progress.Report((totalProcessed * 100) / total);
|
||||
}
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
|
@ -83,9 +83,7 @@ public class DetectIntroductionsTask : IScheduledTask
|
||||
_loggerFactory.CreateLogger<QueueManager>(),
|
||||
_libraryManager);
|
||||
|
||||
queueManager.EnqueueAllEpisodes();
|
||||
|
||||
var queue = Plugin.Instance!.AnalysisQueue;
|
||||
var queue = queueManager.EnqueueAllEpisodes();
|
||||
|
||||
if (queue.Count == 0)
|
||||
{
|
||||
@ -162,7 +160,11 @@ public class DetectIntroductionsTask : IScheduledTask
|
||||
EdlManager.UpdateEDLFiles(episodes);
|
||||
}
|
||||
|
||||
progress.Report((totalProcessed * 100) / Plugin.Instance!.TotalQueued);
|
||||
var total = Plugin.Instance!.TotalQueued;
|
||||
if (total > 0)
|
||||
{
|
||||
progress.Report((totalProcessed * 100) / total);
|
||||
}
|
||||
});
|
||||
|
||||
// Turn the regenerate EDL flag off after the scan completes.
|
||||
|
Loading…
x
Reference in New Issue
Block a user