From 2f05cb70e549c28eaffc1490dfb97601e6d912c8 Mon Sep 17 00:00:00 2001 From: TwistedUmbrellaX Date: Sat, 30 Mar 2024 18:22:54 -0400 Subject: [PATCH] Add back separate tasks as optional --- .../Configuration/PluginConfiguration.cs | 9 +- .../Configuration/configPage.html | 36 ++---- .../Entrypoint.cs | 30 ++++- .../ScheduledTasks/DetectCreditsTask.cs | 103 ++++++++++++++++++ ...ditsTask.cs => DetectIntrosCreditsTask.cs} | 36 +++--- .../ScheduledTasks/DetectIntrosTask.cs | 102 +++++++++++++++++ 6 files changed, 258 insertions(+), 58 deletions(-) create mode 100644 ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectCreditsTask.cs rename ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/{DetectIntrosAndCreditsTask.cs => DetectIntrosCreditsTask.cs} (74%) create mode 100644 ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosTask.cs diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/PluginConfiguration.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/PluginConfiguration.cs index b574521..5f771d0 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/PluginConfiguration.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/PluginConfiguration.cs @@ -30,17 +30,12 @@ public class PluginConfiguration : BasePluginConfiguration /// /// Gets or sets a value indicating whether to scan for intros during a scheduled task. /// - public bool DetectIntros { get; set; } = true; + public bool AutoDetectIntros { get; set; } = false; /// /// Gets or sets a value indicating whether to scan for credits during a scheduled task. /// - public bool DetectCredits { get; set; } = true; - - /// - /// Gets or sets a value indicating whether to analyze automatically, when new Items are added. - /// - public bool AutomaticAnalysis { get; set; } = false; + public bool AutoDetectCredits { get; set; } = false; /// /// Gets or sets a value indicating whether to analyze season 0. diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html index e3b7c33..e1e8041 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html @@ -29,40 +29,29 @@
- This option enables scheduled introduction detection. Your videos will be scanned for introductions during a scheduled task. + If enabled, introductions will be automatically analyzed for new media
- This option enables scheduled credit detection. Your videos will be scanned for credits during a scheduled task. + If enabled, credits will be automatically analyzed for new media
Note: Selecting neither Intro nor Credit Detection will disable automatic scans. To configure the scheduled task, see scheduled tasks.
-
- - -
- If checked, newly added items will be automatically analyzed. -
-
-
+ max="0" />
Noise tolerance in negative decibels.
@@ -238,7 +227,7 @@ Minimum silence duration + step="0.01" />
Minimum silence duration in seconds before adjusting introduction end time.
@@ -248,7 +237,7 @@
Process Configuration -
+
+ max="16" />
Number of simultaneous processes to use for ffmpeg operations.
@@ -623,9 +612,8 @@ ] var booleanConfigurationFields = [ - "DetectIntros", - "DetectCredits", - "AutomaticAnalysis", + "AutoDetectIntros", + "AutoDetectCredits", "AnalyzeSeasonZero", "RegenerateEdlFiles", "UseChromaprint", diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs index 22dc78a..bbb182a 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs @@ -167,22 +167,40 @@ public class Entrypoint : IHostedService var progress = new Progress(); var cancellationToken = new CancellationToken(false); - if (Plugin.Instance!.Configuration.DetectIntros) + if (Plugin.Instance!.Configuration.AutoDetectIntros && Plugin.Instance!.Configuration.AutoDetectCredits) + { + // This is where we can optimize a single scan + var baseIntroAnalyzer = new BaseItemAnalyzerTask( + AnalysisMode.Introduction, + _loggerFactory.CreateLogger(), + _loggerFactory, + _libraryManager); + + baseIntroAnalyzer.AnalyzeItems(progress, cancellationToken); + + var baseCreditAnalyzer = new BaseItemAnalyzerTask( + AnalysisMode.Credits, + _loggerFactory.CreateLogger(), + _loggerFactory, + _libraryManager); + + baseCreditAnalyzer.AnalyzeItems(progress, cancellationToken); + } + else if (Plugin.Instance!.Configuration.AutoDetectIntros) { var baseIntroAnalyzer = new BaseItemAnalyzerTask( AnalysisMode.Introduction, - _loggerFactory.CreateLogger(), + _loggerFactory.CreateLogger(), _loggerFactory, _libraryManager); baseIntroAnalyzer.AnalyzeItems(progress, cancellationToken); } - - if (Plugin.Instance!.Configuration.DetectCredits) + else if (Plugin.Instance!.Configuration.AutoDetectCredits) { var baseCreditAnalyzer = new BaseItemAnalyzerTask( AnalysisMode.Credits, - _loggerFactory.CreateLogger(), + _loggerFactory.CreateLogger(), _loggerFactory, _libraryManager); @@ -229,7 +247,7 @@ public class Entrypoint : IHostedService /// public Task StartAsync(CancellationToken cancellationToken) { - if (Plugin.Instance!.Configuration.AutomaticAnalysis) + if (Plugin.Instance!.Configuration.AutoDetectIntros || Plugin.Instance!.Configuration.AutoDetectCredits) { _libraryManager.ItemAdded += OnItemAdded; _libraryManager.ItemUpdated += OnItemModified; diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectCreditsTask.cs b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectCreditsTask.cs new file mode 100644 index 0000000..446ee70 --- /dev/null +++ b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectCreditsTask.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Controller.Library; +using MediaBrowser.Model.Tasks; +using Microsoft.Extensions.Logging; + +namespace ConfusedPolarBear.Plugin.IntroSkipper; + +/// +/// Analyze all television episodes for credits. +/// TODO: analyze all media files. +/// +public class DetectCreditsTask : IScheduledTask +{ + private readonly ILogger _logger; + + private readonly ILoggerFactory _loggerFactory; + + private readonly ILibraryManager _libraryManager; + + /// + /// Initializes a new instance of the class. + /// + /// Logger factory. + /// Library manager. + /// Logger. + public DetectCreditsTask( + ILogger logger, + ILoggerFactory loggerFactory, + ILibraryManager libraryManager) + { + _logger = logger; + _loggerFactory = loggerFactory; + _libraryManager = libraryManager; + } + + /// + /// Gets the task name. + /// + public string Name => "Detect Credits"; + + /// + /// Gets the task category. + /// + public string Category => "Intro Skipper"; + + /// + /// Gets the task description. + /// + public string Description => "Analyzes the audio and video of all television episodes to find credits."; + + /// + /// Gets the task key. + /// + public string Key => "CPBIntroSkipperDetectCredits"; + + /// + /// Analyze all episodes in the queue. Only one instance of this task should be run at a time. + /// + /// Task progress. + /// Cancellation token. + /// Task. + public Task ExecuteAsync(IProgress progress, CancellationToken cancellationToken) + { + if (_libraryManager is null) + { + throw new InvalidOperationException("Library manager was null"); + } + + // abort if analyzer is already running + if (Plugin.Instance!.AnalyzerTaskIsRunning) + { + return Task.CompletedTask; + } + else + { + Plugin.Instance!.AnalyzerTaskIsRunning = true; + } + + var baseCreditAnalyzer = new BaseItemAnalyzerTask( + AnalysisMode.Credits, + _loggerFactory.CreateLogger(), + _loggerFactory, + _libraryManager); + + baseCreditAnalyzer.AnalyzeItems(progress, cancellationToken); + + Plugin.Instance!.AnalyzerTaskIsRunning = false; + + return Task.CompletedTask; + } + + /// + /// Get task triggers. + /// + /// Task triggers. + public IEnumerable GetDefaultTriggers() + { + return Array.Empty(); + } +} diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosAndCreditsTask.cs b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosCreditsTask.cs similarity index 74% rename from ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosAndCreditsTask.cs rename to ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosCreditsTask.cs index b01293d..1c80fb4 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosAndCreditsTask.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosCreditsTask.cs @@ -11,18 +11,18 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper; /// /// Analyze all television episodes for introduction sequences. /// -public class DetectIntrosAndCreditsTask : IScheduledTask +public class DetectIntrosCreditsTask : IScheduledTask { private readonly ILoggerFactory _loggerFactory; private readonly ILibraryManager _libraryManager; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Logger factory. /// Library manager. - public DetectIntrosAndCreditsTask( + public DetectIntrosCreditsTask( ILoggerFactory loggerFactory, ILibraryManager libraryManager) { @@ -73,27 +73,21 @@ public class DetectIntrosAndCreditsTask : IScheduledTask Plugin.Instance!.AnalyzerTaskIsRunning = true; } - if (Plugin.Instance!.Configuration.DetectIntros) - { - var baseIntroAnalyzer = new BaseItemAnalyzerTask( - AnalysisMode.Introduction, - _loggerFactory.CreateLogger(), - _loggerFactory, - _libraryManager); + var baseIntroAnalyzer = new BaseItemAnalyzerTask( + AnalysisMode.Introduction, + _loggerFactory.CreateLogger(), + _loggerFactory, + _libraryManager); - baseIntroAnalyzer.AnalyzeItems(progress, cancellationToken); - } + baseIntroAnalyzer.AnalyzeItems(progress, cancellationToken); - if (Plugin.Instance!.Configuration.DetectCredits) - { - var baseCreditAnalyzer = new BaseItemAnalyzerTask( - AnalysisMode.Credits, - _loggerFactory.CreateLogger(), - _loggerFactory, - _libraryManager); + var baseCreditAnalyzer = new BaseItemAnalyzerTask( + AnalysisMode.Credits, + _loggerFactory.CreateLogger(), + _loggerFactory, + _libraryManager); - baseCreditAnalyzer.AnalyzeItems(progress, cancellationToken); - } + baseCreditAnalyzer.AnalyzeItems(progress, cancellationToken); Plugin.Instance!.AnalyzerTaskIsRunning = false; diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosTask.cs b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosTask.cs new file mode 100644 index 0000000..8c30f4f --- /dev/null +++ b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosTask.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Controller.Library; +using MediaBrowser.Model.Tasks; +using Microsoft.Extensions.Logging; + +namespace ConfusedPolarBear.Plugin.IntroSkipper; + +/// +/// Analyze all television episodes for introduction sequences. +/// +public class DetectIntrosTask : IScheduledTask +{ + private readonly ILogger _logger; + + private readonly ILoggerFactory _loggerFactory; + + private readonly ILibraryManager _libraryManager; + + /// + /// Initializes a new instance of the class. + /// + /// Logger factory. + /// Library manager. + /// Logger. + public DetectIntrosTask( + ILogger logger, + ILoggerFactory loggerFactory, + ILibraryManager libraryManager) + { + _logger = logger; + _loggerFactory = loggerFactory; + _libraryManager = libraryManager; + } + + /// + /// Gets the task name. + /// + public string Name => "Detect Introductions"; + + /// + /// Gets the task category. + /// + public string Category => "Intro Skipper"; + + /// + /// Gets the task description. + /// + public string Description => "Analyzes the audio of all television episodes to find introduction sequences."; + + /// + /// Gets the task key. + /// + public string Key => "CPBIntroSkipperDetectIntroductions"; + + /// + /// Analyze all episodes in the queue. Only one instance of this task should be run at a time. + /// + /// Task progress. + /// Cancellation token. + /// Task. + public Task ExecuteAsync(IProgress progress, CancellationToken cancellationToken) + { + if (_libraryManager is null) + { + throw new InvalidOperationException("Library manager was null"); + } + + // abort if analyzer is already running + if (Plugin.Instance!.AnalyzerTaskIsRunning) + { + return Task.CompletedTask; + } + else + { + Plugin.Instance!.AnalyzerTaskIsRunning = true; + } + + var baseIntroAnalyzer = new BaseItemAnalyzerTask( + AnalysisMode.Introduction, + _loggerFactory.CreateLogger(), + _loggerFactory, + _libraryManager); + + baseIntroAnalyzer.AnalyzeItems(progress, cancellationToken); + + Plugin.Instance!.AnalyzerTaskIsRunning = false; + + return Task.CompletedTask; + } + + /// + /// Get task triggers. + /// + /// Task triggers. + public IEnumerable GetDefaultTriggers() + { + return Array.Empty(); + } +}