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 70ae2ec..49727d3 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.
@@ -622,9 +611,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 2051aae..74a81c5 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs @@ -62,7 +62,7 @@ public class Entrypoint : IServerEntryPoint /// Task. public Task RunAsync() { - if (Plugin.Instance!.Configuration.AutomaticAnalysis) + if (Plugin.Instance!.Configuration.AutoDetectIntros || Plugin.Instance!.Configuration.AutoDetectCredits) { _libraryManager.ItemAdded += OnItemAdded; _libraryManager.ItemUpdated += OnItemModified; @@ -196,22 +196,40 @@ public class Entrypoint : IServerEntryPoint 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); 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(); + } +}