Merge pull request #119 from RepoDevil/10.8

When a scan is already running, append it
This commit is contained in:
TwistedUmbrellaX 2024-04-16 10:42:23 -04:00 committed by GitHub
commit 0b77809e9f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 42 additions and 15 deletions

View File

@ -26,6 +26,7 @@ public class Entrypoint : IServerEntryPoint
private bool _analyzeAgain;
private static CancellationTokenSource? _cancellationTokenSource;
private static ManualResetEventSlim _autoTaskCompletEvent = new ManualResetEventSlim(false);
private QueueManager _queueManager;
/// <summary>
/// Initializes a new instance of the <see cref="Entrypoint"/> class.
@ -56,6 +57,10 @@ public class Entrypoint : IServerEntryPoint
null,
Timeout.InfiniteTimeSpan,
Timeout.InfiniteTimeSpan);
_queueManager = new QueueManager(
_loggerFactory.CreateLogger<QueueManager>(),
_libraryManager);
}
/// <summary>
@ -92,8 +97,7 @@ public class Entrypoint : IServerEntryPoint
{
// 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.GetMediaItems();
_queueManager.GetMediaItems();
}
catch (Exception ex)
{
@ -121,7 +125,7 @@ public class Entrypoint : IServerEntryPoint
}
// Don't do anything if it's not a supported media type
if (itemChangeEventArgs.Item is not Episode)
if (itemChangeEventArgs.Item is not Episode episode)
{
return;
}
@ -131,10 +135,16 @@ public class Entrypoint : IServerEntryPoint
return;
}
if (Plugin.Instance!.AnalyzerTaskIsRunning)
{
_queueManager.QueueEpisode(episode);
}
else
{
Plugin.Instance!.Configuration.PathRestrictions.Add(itemChangeEventArgs.Item.ContainingFolderPath);
StartTimer();
}
}
/// <summary>
/// Library item was modified.
@ -150,7 +160,7 @@ public class Entrypoint : IServerEntryPoint
}
// Don't do anything if it's not a supported media type
if (itemChangeEventArgs.Item is not Episode)
if (itemChangeEventArgs.Item is not Episode episode)
{
return;
}
@ -160,10 +170,16 @@ public class Entrypoint : IServerEntryPoint
return;
}
if (Plugin.Instance!.AnalyzerTaskIsRunning)
{
_queueManager.QueueEpisode(episode);
}
else
{
Plugin.Instance!.Configuration.PathRestrictions.Add(itemChangeEventArgs.Item.ContainingFolderPath);
StartTimer();
}
}
/// <summary>
/// TaskManager task ended.
@ -284,8 +300,8 @@ public class Entrypoint : IServerEntryPoint
}
}
Plugin.Instance!.AnalyzerTaskIsRunning = false;
Plugin.Instance!.Configuration.PathRestrictions.Clear();
Plugin.Instance!.AnalyzerTaskIsRunning = false;
_autoTaskCompletEvent.Set();
// New item detected, start timer again

View File

@ -171,7 +171,11 @@ public class QueueManager
_logger.LogDebug("Queued {Count} episodes", items.Count);
}
private void QueueEpisode(Episode episode)
/// <summary>
/// Adds a single episode to the current queue for analyzing.
/// </summary>
/// <param name="episode">The episode to analyze.</param>
public void QueueEpisode(Episode episode)
{
if (Plugin.Instance is null)
{

View File

@ -146,6 +146,8 @@ public class BaseItemAnalyzerTask
EdlManager.UpdateEDLFiles(episodes);
}
if (_logger is ILogger<DetectIntrosCreditsTask>)
{
if (_analysisMode == AnalysisMode.Introduction)
{
progress.Report(((totalProcessed * 100) / totalQueued) / 2);
@ -154,6 +156,11 @@ public class BaseItemAnalyzerTask
{
progress.Report((((totalProcessed * 100) / totalQueued) / 2) + 50);
}
}
else
{
progress.Report((totalProcessed * 100) / totalQueued);
}
});
if (