From 46355d19d47fe07baec86d67b16d022c2e7dd1e4 Mon Sep 17 00:00:00 2001
From: ConfusedPolarBear <33811686+ConfusedPolarBear@users.noreply.github.com>
Date: Sun, 3 Jul 2022 02:47:48 -0500
Subject: [PATCH] Cleanup
---
ConfusedPolarBear.Plugin.IntroSkipper/AutoSkip.cs | 2 +-
.../Controllers/SkipIntroController.cs | 7 +------
.../QueueManager.cs | 12 ++++--------
.../ScheduledTasks/FingerprinterTask.cs | 8 +++++++-
4 files changed, 13 insertions(+), 16 deletions(-)
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/AutoSkip.cs b/ConfusedPolarBear.Plugin.IntroSkipper/AutoSkip.cs
index c204344..3846bb9 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/AutoSkip.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/AutoSkip.cs
@@ -127,7 +127,7 @@ public class AutoSkip : IServerEntryPoint
// Don't send the seek command more than once in the same session.
lock (_sentSeekCommandLock)
{
- if (_sentSeekCommand[deviceId])
+ if (_sentSeekCommand.TryGetValue(deviceId, out var sent) && sent)
{
_logger.LogTrace("Already sent seek command for session {Session}", deviceId);
continue;
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/SkipIntroController.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/SkipIntroController.cs
index 90a713e..4733c5e 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/SkipIntroController.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/SkipIntroController.cs
@@ -52,12 +52,7 @@ public class SkipIntroController : ControllerBase
/// Intro object if the provided item has an intro, null otherwise.
private Intro? GetIntro(Guid id)
{
- if (!Plugin.Instance!.Intros.ContainsKey(id))
- {
- return null;
- }
-
- return Plugin.Instance!.Intros[id];
+ return Plugin.Instance!.Intros.TryGetValue(id, out var intro) ? intro : null;
}
///
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/QueueManager.cs b/ConfusedPolarBear.Plugin.IntroSkipper/QueueManager.cs
index c7c9d6b..0dae391 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/QueueManager.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/QueueManager.cs
@@ -147,14 +147,6 @@ public class QueueManager
return;
}
- var queue = Plugin.Instance.AnalysisQueue;
-
- // Allocate a new list for each new season
- if (!queue.ContainsKey(episode.SeasonId))
- {
- Plugin.Instance.AnalysisQueue[episode.SeasonId] = new List();
- }
-
// Only fingerprint up to 25% of the episode and at most 10 minutes.
var duration = TimeSpan.FromTicks(episode.RunTimeTicks ?? 0).TotalSeconds;
if (duration >= 5 * 60)
@@ -164,6 +156,10 @@ public class QueueManager
duration = Math.Min(duration, 10 * 60);
+ // Allocate a new list for each new season
+ Plugin.Instance!.AnalysisQueue.TryAdd(episode.SeasonId, new List());
+
+ // Queue the episode for analysis
Plugin.Instance.AnalysisQueue[episode.SeasonId].Add(new QueuedEpisode()
{
SeriesName = episode.SeriesName,
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/FingerprinterTask.cs b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/FingerprinterTask.cs
index ff79c54..a162394 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/FingerprinterTask.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/FingerprinterTask.cs
@@ -724,11 +724,17 @@ public class FingerprinterTask : IScheduledTask
// Analyze the episode again, ignoring whatever is returned for the known good episode.
foreach (var lhsFingerprint in goodFingerprints)
{
+ if (!_fingerprintCache.TryGetValue(episode.EpisodeId, out var fp))
+ {
+ _logger.LogTrace("Unable to get cached fingerprint for {Id}, skipping", episode.EpisodeId);
+ continue;
+ }
+
var (_, newRhs) = FingerprintEpisodes(
maxEpisode.EpisodeId,
lhsFingerprint,
episode.EpisodeId,
- _fingerprintCache[episode.EpisodeId]);
+ fp);
// Ensure that the new intro duration is within the targeted bucket and longer than what was found previously.
var newDuration = Math.Round(newRhs.IntroEnd - newRhs.IntroStart, 2);