From 3096f3fe6a33a898bdc0a59e453135d17cc942e2 Mon Sep 17 00:00:00 2001 From: TwistedUmbrellaX Date: Sun, 14 Apr 2024 09:50:56 -0400 Subject: [PATCH 1/3] When a scan is already running, append it --- .../Entrypoint.cs | 36 +++++++++++++------ .../QueueManager.cs | 6 +++- .../ScheduledTasks/DetectCreditsTask.cs | 5 --- .../ScheduledTasks/DetectIntrosCreditsTask.cs | 5 --- .../ScheduledTasks/DetectIntrosTask.cs | 5 --- 5 files changed, 31 insertions(+), 26 deletions(-) diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs index 97abcc7..faf14aa 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs @@ -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; /// /// Initializes a new instance of the class. @@ -56,6 +57,10 @@ public class Entrypoint : IServerEntryPoint null, Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan); + + _queueManager = new QueueManager( + _loggerFactory.CreateLogger(), + _libraryManager); } /// @@ -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(), _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,9 +135,15 @@ public class Entrypoint : IServerEntryPoint return; } - Plugin.Instance!.Configuration.PathRestrictions.Add(itemChangeEventArgs.Item.ContainingFolderPath); - - StartTimer(); + if (Plugin.Instance!.AnalyzerTaskIsRunning) + { + _queueManager.QueueEpisode(episode); + } + else + { + Plugin.Instance!.Configuration.PathRestrictions.Add(itemChangeEventArgs.Item.ContainingFolderPath); + StartTimer(); + } } /// @@ -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,9 +170,15 @@ public class Entrypoint : IServerEntryPoint return; } - Plugin.Instance!.Configuration.PathRestrictions.Add(itemChangeEventArgs.Item.ContainingFolderPath); - - StartTimer(); + if (Plugin.Instance!.AnalyzerTaskIsRunning) + { + _queueManager.QueueEpisode(episode); + } + else + { + Plugin.Instance!.Configuration.PathRestrictions.Add(itemChangeEventArgs.Item.ContainingFolderPath); + StartTimer(); + } } /// diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/QueueManager.cs b/ConfusedPolarBear.Plugin.IntroSkipper/QueueManager.cs index ccc1d1c..564d631 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/QueueManager.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/QueueManager.cs @@ -171,7 +171,11 @@ public class QueueManager _logger.LogDebug("Queued {Count} episodes", items.Count); } - private void QueueEpisode(Episode episode) + /// + /// Adds a single episode to the current queue for analyzing. + /// + /// The episode to analyze. + public void QueueEpisode(Episode episode) { if (Plugin.Instance is null) { diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectCreditsTask.cs b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectCreditsTask.cs index bacb457..2402976 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectCreditsTask.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectCreditsTask.cs @@ -74,11 +74,6 @@ public class DetectCreditsTask : IScheduledTask { return Task.CompletedTask; } - else if (Plugin.Instance!.AnalyzerTaskIsRunning && Entrypoint.AutomaticTaskState == TaskState.Running) - { - _logger.LogInformation("Automatic Task is {0} and will be canceled.", Entrypoint.AutomaticTaskState); - Entrypoint.CancelAutomaticTask(); - } _logger.LogInformation("Scheduled Task is starting"); Plugin.Instance!.AnalyzerTaskIsRunning = true; diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosCreditsTask.cs b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosCreditsTask.cs index f58472c..89edea1 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosCreditsTask.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosCreditsTask.cs @@ -73,11 +73,6 @@ public class DetectIntrosCreditsTask : IScheduledTask { return Task.CompletedTask; } - else if (Plugin.Instance!.AnalyzerTaskIsRunning && Entrypoint.AutomaticTaskState == TaskState.Running) - { - _logger.LogInformation("Automatic Task is {0} and will be canceled.", Entrypoint.AutomaticTaskState); - Entrypoint.CancelAutomaticTask(); - } _logger.LogInformation("Scheduled Task is starting"); Plugin.Instance!.AnalyzerTaskIsRunning = true; diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosTask.cs b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosTask.cs index c92f800..bbf98ec 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosTask.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosTask.cs @@ -73,11 +73,6 @@ public class DetectIntrosTask : IScheduledTask { return Task.CompletedTask; } - else if (Plugin.Instance!.AnalyzerTaskIsRunning && Entrypoint.AutomaticTaskState == TaskState.Running) - { - _logger.LogInformation("Automatic Task is {0} and will be canceled.", Entrypoint.AutomaticTaskState); - Entrypoint.CancelAutomaticTask(); - } _logger.LogInformation("Scheduled Task is starting"); Plugin.Instance!.AnalyzerTaskIsRunning = true; From de60fd236f63596f9e05885ebc49e76582679422 Mon Sep 17 00:00:00 2001 From: TwistedUmbrellaX Date: Sun, 14 Apr 2024 10:20:18 -0400 Subject: [PATCH 2/3] Still cancel automation for scheduled The priority should starts at scheduled task (a full scan), but automatic scans will add items to them. Library scan is next, but again it should allow appending. Item scans should be last and get overridden by the other two. --- .../ScheduledTasks/DetectCreditsTask.cs | 5 +++++ .../ScheduledTasks/DetectIntrosCreditsTask.cs | 5 +++++ .../ScheduledTasks/DetectIntrosTask.cs | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectCreditsTask.cs b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectCreditsTask.cs index 2402976..bacb457 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectCreditsTask.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectCreditsTask.cs @@ -74,6 +74,11 @@ public class DetectCreditsTask : IScheduledTask { return Task.CompletedTask; } + else if (Plugin.Instance!.AnalyzerTaskIsRunning && Entrypoint.AutomaticTaskState == TaskState.Running) + { + _logger.LogInformation("Automatic Task is {0} and will be canceled.", Entrypoint.AutomaticTaskState); + Entrypoint.CancelAutomaticTask(); + } _logger.LogInformation("Scheduled Task is starting"); Plugin.Instance!.AnalyzerTaskIsRunning = true; diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosCreditsTask.cs b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosCreditsTask.cs index 89edea1..f58472c 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosCreditsTask.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosCreditsTask.cs @@ -73,6 +73,11 @@ public class DetectIntrosCreditsTask : IScheduledTask { return Task.CompletedTask; } + else if (Plugin.Instance!.AnalyzerTaskIsRunning && Entrypoint.AutomaticTaskState == TaskState.Running) + { + _logger.LogInformation("Automatic Task is {0} and will be canceled.", Entrypoint.AutomaticTaskState); + Entrypoint.CancelAutomaticTask(); + } _logger.LogInformation("Scheduled Task is starting"); Plugin.Instance!.AnalyzerTaskIsRunning = true; diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosTask.cs b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosTask.cs index bbf98ec..c92f800 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosTask.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosTask.cs @@ -73,6 +73,11 @@ public class DetectIntrosTask : IScheduledTask { return Task.CompletedTask; } + else if (Plugin.Instance!.AnalyzerTaskIsRunning && Entrypoint.AutomaticTaskState == TaskState.Running) + { + _logger.LogInformation("Automatic Task is {0} and will be canceled.", Entrypoint.AutomaticTaskState); + Entrypoint.CancelAutomaticTask(); + } _logger.LogInformation("Scheduled Task is starting"); Plugin.Instance!.AnalyzerTaskIsRunning = true; From 75688772b18f84f2c9e4f7fa145987a7546b3d0d Mon Sep 17 00:00:00 2001 From: TwistedUmbrellaX Date: Sun, 14 Apr 2024 10:49:28 -0400 Subject: [PATCH 3/3] Only shared should split progress bar --- ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs | 2 +- .../ScheduledTasks/BaseItemAnalyzerTask.cs | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs index faf14aa..245cc8e 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs @@ -300,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 diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/BaseItemAnalyzerTask.cs b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/BaseItemAnalyzerTask.cs index f80f0a4..3eabd6d 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/BaseItemAnalyzerTask.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/BaseItemAnalyzerTask.cs @@ -146,13 +146,20 @@ public class BaseItemAnalyzerTask EdlManager.UpdateEDLFiles(episodes); } - if (_analysisMode == AnalysisMode.Introduction) + if (_logger is ILogger) { - progress.Report(((totalProcessed * 100) / totalQueued) / 2); + if (_analysisMode == AnalysisMode.Introduction) + { + progress.Report(((totalProcessed * 100) / totalQueued) / 2); + } + else + { + progress.Report((((totalProcessed * 100) / totalQueued) / 2) + 50); + } } else { - progress.Report((((totalProcessed * 100) / totalQueued) / 2) + 50); + progress.Report((totalProcessed * 100) / totalQueued); } });