From c3c986152d0c3a50b6ebca39cd0bf0c890552c49 Mon Sep 17 00:00:00 2001
From: ConfusedPolarBear <33811686+ConfusedPolarBear@users.noreply.github.com>
Date: Sun, 25 Sep 2022 17:07:11 -0500
Subject: [PATCH] Cleanup
---
.../ScheduledTasks/AnalyzeEpisodesTask.cs | 60 ++++---------------
1 file changed, 13 insertions(+), 47 deletions(-)
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/AnalyzeEpisodesTask.cs b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/AnalyzeEpisodesTask.cs
index e8460b0..375b1f5 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/AnalyzeEpisodesTask.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/AnalyzeEpisodesTask.cs
@@ -16,7 +16,8 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper;
public class AnalyzeEpisodesTask : IScheduledTask
{
///
- /// Seconds of audio in one fingerprint point. This value is defined by the Chromaprint library and should not be changed.
+ /// Seconds of audio in one fingerprint point.
+ /// This value is defined by the Chromaprint library and should not be changed.
///
private const double SamplesToSeconds = 0.128;
@@ -49,7 +50,9 @@ public class AnalyzeEpisodesTask : IScheduledTask
///
/// Logger factory.
/// Library manager.
- public AnalyzeEpisodesTask(ILoggerFactory loggerFactory, ILibraryManager libraryManager) : this(loggerFactory)
+ public AnalyzeEpisodesTask(
+ ILoggerFactory loggerFactory,
+ ILibraryManager libraryManager) : this(loggerFactory)
{
_libraryManager = libraryManager;
}
@@ -127,8 +130,6 @@ public class AnalyzeEpisodesTask : IScheduledTask
MaxDegreeOfParallelism = Plugin.Instance!.Configuration.MaxParallelism
};
- var taskStart = DateTime.Now;
-
minimumIntroDuration = Plugin.Instance!.Configuration.MinimumIntroDuration;
// TODO: if the queue is modified while the task is running, the task will fail.
@@ -137,8 +138,9 @@ public class AnalyzeEpisodesTask : IScheduledTask
// Analyze all episodes in the queue using the degrees of parallelism the user specified.
Parallel.ForEach(queue, options, (season) =>
{
- var workerStart = DateTime.Now;
- var first = season.Value[0];
+
+ var episodes = season.Value.AsReadOnly();
+ var first = episodes[0];
var writeEdl = false;
try
@@ -148,8 +150,6 @@ public class AnalyzeEpisodesTask : IScheduledTask
return;
}
- var episodes = new ReadOnlyCollection(season.Value);
-
// Increment totalProcessed by the number of episodes in this season that were actually analyzed
// (instead of just using the number of episodes in the current season).
var analyzed = AnalyzeSeason(episodes, cancellationToken);
@@ -175,7 +175,7 @@ public class AnalyzeEpisodesTask : IScheduledTask
if (writeEdl && Plugin.Instance!.Configuration.EdlAction != EdlAction.None)
{
- EdlManager.UpdateEDLFiles(season.Value.AsReadOnly());
+ EdlManager.UpdateEDLFiles(episodes);
}
progress.Report((totalProcessed * 100) / Plugin.Instance!.TotalQueued);
@@ -338,10 +338,7 @@ public class AnalyzeEpisodesTask : IScheduledTask
{
Plugin.Instance!.Intros[intro.Key] = intro.Value;
}
- }
- lock (_introsLock)
- {
Plugin.Instance!.SaveTimestamps();
}
@@ -362,8 +359,6 @@ public class AnalyzeEpisodesTask : IScheduledTask
Guid rhsId,
uint[] rhsPoints)
{
- var start = DateTime.Now;
-
// Creates an inverted fingerprint point index for both episodes.
// For every point which is a 100% match, search for an introduction at that point.
var (lhsRanges, rhsRanges) = SearchInvertedIndex(lhsId, lhsPoints, rhsId, rhsPoints);
@@ -463,41 +458,12 @@ public class AnalyzeEpisodesTask : IScheduledTask
// Use all discovered shifts to compare the episodes.
foreach (var shift in indexShifts)
{
- var (lhsIndexContiguous, rhsIndexContiguous) = ShiftEpisodes(lhsPoints, rhsPoints, shift, shift);
- lhsRanges.AddRange(lhsIndexContiguous);
- rhsRanges.AddRange(rhsIndexContiguous);
- }
-
- return (lhsRanges, rhsRanges);
- }
-
- ///
- /// Shifts a pair of episodes through the range of provided shift amounts and returns discovered contiguous time ranges.
- ///
- /// First episode fingerprint.
- /// Second episode fingerprint.
- /// Lower end of the shift range.
- /// Upper end of the shift range.
- private static (List Lhs, List Rhs) ShiftEpisodes(
- uint[] lhs,
- uint[] rhs,
- int lower,
- int upper)
- {
- var lhsRanges = new List();
- var rhsRanges = new List();
-
- for (int amount = lower; amount <= upper; amount++)
- {
- var (lRange, rRange) = FindContiguous(lhs, rhs, amount);
-
- if (lRange.End == 0 && rRange.End == 0)
+ var (lhsIndexContiguous, rhsIndexContiguous) = FindContiguous(lhsPoints, rhsPoints, shift);
+ if (lhsIndexContiguous.End > 0 && rhsIndexContiguous.End > 0)
{
- continue;
+ lhsRanges.Add(lhsIndexContiguous);
+ rhsRanges.Add(rhsIndexContiguous);
}
-
- lhsRanges.Add(lRange);
- rhsRanges.Add(rRange);
}
return (lhsRanges, rhsRanges);