From a1a10874d353a7084a0ec08138dcada7069d0fd2 Mon Sep 17 00:00:00 2001 From: ConfusedPolarBear <33811686+ConfusedPolarBear@users.noreply.github.com> Date: Sun, 3 Jul 2022 01:59:16 -0500 Subject: [PATCH] Allow customizing minimum intro duration Closes #51 --- .../Configuration/PluginConfiguration.cs | 5 +++ .../Configuration/configPage.html | 31 ++++++++++++++----- .../QueueManager.cs | 7 +++-- .../ScheduledTasks/FingerprinterTask.cs | 16 +++++----- 4 files changed, 42 insertions(+), 17 deletions(-) diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/PluginConfiguration.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/PluginConfiguration.cs index d1854c7..cd5007e 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/PluginConfiguration.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/PluginConfiguration.cs @@ -36,6 +36,11 @@ public class PluginConfiguration : BasePluginConfiguration /// public int AnalysisLengthLimit { get; set; } = 10; + /// + /// Gets or sets the minimum length of similar audio that will be considered an introduction. + /// + public int MinimumIntroDuration { get; set; } = 15; + // ===== Playback settings ===== /// diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html index 3531b2d..c0639a4 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html @@ -64,17 +64,32 @@ -

- The amount of each episode's audio that will be analyzed is determined by these two - settings. The minimum of (episode duration * percent, maximum runtime) is the amount of - audio that will be analyzed.
+

+ + +
+ Similar sounding audio which is shorter than this duration will not be considered an + introduction. +
+
- If these settings are changed after analyzing your media, the cached fingerprints and - introduction timestamps for each season you want to analyze with the modified settings +

+ The amount of each episode's audio that will be analyzed is determined using both + the percentage of audio and maximum runtime of audio to analyze. The minimum of + (episode duration * percent, maximum runtime) is the amount of audio that will + be analyzed.
+ + If the audio percentage or maximum runtime settings are changed after analyzing your + media, the cached fingerprints and introduction timestamps for each season you want to + analyze with the modified settings will have to be deleted.

- Increasing these settings will cause episode analysis to take much longer. + + Increasing either of these settings will cause episode analysis to take much longer. + @@ -480,6 +495,7 @@ document.querySelector('#AnalysisPercent').value = config.AnalysisPercent; document.querySelector('#AnalysisLengthLimit').value = config.AnalysisLengthLimit; + document.querySelector('#MinimumDuration').value = config.MinimumIntroDuration; document.querySelector('#CacheFingerprints').checked = config.CacheFingerprints; document.querySelector('#ShowPromptAdjustment').value = config.ShowPromptAdjustment; @@ -498,6 +514,7 @@ config.AnalysisPercent = document.querySelector('#AnalysisPercent').value; config.AnalysisLengthLimit = document.querySelector('#AnalysisLengthLimit').value; + config.MinimumIntroDuration = document.querySelector('#MinimumDuration').value; config.CacheFingerprints = document.querySelector('#CacheFingerprints').checked; config.ShowPromptAdjustment = document.querySelector("#ShowPromptAdjustment").value; diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/QueueManager.cs b/ConfusedPolarBear.Plugin.IntroSkipper/QueueManager.cs index 5946a62..c8f371c 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/QueueManager.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/QueueManager.cs @@ -48,12 +48,13 @@ public class QueueManager var config = Plugin.Instance!.Configuration; analysisPercent = Convert.ToDouble(config.AnalysisPercent) / 100; - if (config.AnalysisLengthLimit != 10 || config.AnalysisPercent != 25) + if (config.AnalysisLengthLimit != 10 || config.AnalysisPercent != 25 || config.MinimumIntroDuration != 15) { _logger.LogDebug( - "Introduction scan is limited to the first {Percent}% or the first {Minutes} minutes of each episode (whichever is smaller)", + "Analysis settings have been changed to: {Percent}%/{Minutes}m and a minimum of {Minimum}s", config.AnalysisPercent, - config.AnalysisLengthLimit); + config.AnalysisLengthLimit, + config.MinimumIntroDuration); } // For all TV show libraries, enqueue all contained items. diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/FingerprinterTask.cs b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/FingerprinterTask.cs index 0520f20..20e5e2f 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/FingerprinterTask.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/FingerprinterTask.cs @@ -15,11 +15,6 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper; ///
public class FingerprinterTask : IScheduledTask { - /// - /// Minimum time (in seconds) for a contiguous time range to be considered an introduction. - /// - private const int MinimumIntroDuration = 15; - /// /// Maximum number of bits (out of 32 total) that can be different between segments before they are considered dissimilar. /// 6 bits means the audio must be at least 81% similar (1 - 6 / 32). @@ -68,6 +63,11 @@ public class FingerprinterTask : IScheduledTask /// private Dictionary> _fingerprintCache; + /// + /// Minimum duration of similar audio that will be considered an introduction. + /// + private static int minimumIntroDuration = 15; + /// /// Initializes a new instance of the class. /// @@ -143,6 +143,8 @@ public class FingerprinterTask : IScheduledTask MaxDegreeOfParallelism = Plugin.Instance!.Configuration.MaxParallelism }; + minimumIntroDuration = Plugin.Instance!.Configuration.MinimumIntroDuration; + Parallel.ForEach(queue, options, (season) => { var first = season.Value[0]; @@ -533,7 +535,7 @@ public class FingerprinterTask : IScheduledTask // Now that both fingerprints have been compared at this shift, see if there's a contiguous time range. var lContiguous = TimeRangeHelpers.FindContiguous(lhsTimes.ToArray(), MaximumDistance); - if (lContiguous is null || lContiguous.Duration < MinimumIntroDuration) + if (lContiguous is null || lContiguous.Duration < minimumIntroDuration) { return (new TimeRange(), new TimeRange()); } @@ -599,7 +601,7 @@ public class FingerprinterTask : IScheduledTask var id = episode.EpisodeId; var duration = GetIntroDuration(id); - if (duration < MinimumIntroDuration) + if (duration < minimumIntroDuration) { continue; }