From 96333f5f9eedbc27df40ff0d58ff6ebdcc13e927 Mon Sep 17 00:00:00 2001
From: ConfusedPolarBear <33811686+ConfusedPolarBear@users.noreply.github.com>
Date: Mon, 9 May 2022 22:56:03 -0500
Subject: [PATCH] Enable StyleCop analyzers
---
...nfusedPolarBear.Plugin.IntroSkipper.csproj | 1 +
.../Data/TimeRange.cs | 126 +++++++++++-------
.../Entrypoint.cs | 3 +-
.../Plugin.cs | 60 +++++----
.../ScheduledTasks/FingerprinterTask.cs | 32 ++---
5 files changed, 125 insertions(+), 97 deletions(-)
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ConfusedPolarBear.Plugin.IntroSkipper.csproj b/ConfusedPolarBear.Plugin.IntroSkipper/ConfusedPolarBear.Plugin.IntroSkipper.csproj
index 7784686..55821fe 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/ConfusedPolarBear.Plugin.IntroSkipper.csproj
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/ConfusedPolarBear.Plugin.IntroSkipper.csproj
@@ -16,6 +16,7 @@
+
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Data/TimeRange.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Data/TimeRange.cs
index 2b33f77..10f3ae1 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/Data/TimeRange.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/Data/TimeRange.cs
@@ -8,21 +8,6 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper;
///
public class TimeRange : IComparable
{
- ///
- /// Gets or sets the time range start (in seconds).
- ///
- public double Start { get; set; }
-
- ///
- /// Gets or sets the time range end (in seconds).
- ///
- public double End { get; set; }
-
- ///
- /// Gets the duration of this time range (in seconds).
- ///
- public double Duration => End - Start;
-
///
/// Initializes a new instance of the class.
///
@@ -53,6 +38,81 @@ public class TimeRange : IComparable
End = original.End;
}
+ ///
+ /// Gets or sets the time range start (in seconds).
+ ///
+ public double Start { get; set; }
+
+ ///
+ /// Gets or sets the time range end (in seconds).
+ ///
+ public double End { get; set; }
+
+ ///
+ /// Gets the duration of this time range (in seconds).
+ ///
+ public double Duration => End - Start;
+
+ ///
+ /// Comparison operator.
+ ///
+ /// Left TimeRange.
+ /// Right TimeRange.
+ public static bool operator ==(TimeRange left, TimeRange right)
+ {
+ return left.Equals(right);
+ }
+
+ ///
+ /// Comparison operator.
+ ///
+ /// Left TimeRange.
+ /// Right TimeRange.
+ public static bool operator !=(TimeRange left, TimeRange right)
+ {
+ return !left.Equals(right);
+ }
+
+ ///
+ /// Comparison operator.
+ ///
+ /// Left TimeRange.
+ /// Right TimeRange.
+ public static bool operator <=(TimeRange left, TimeRange right)
+ {
+ return left.CompareTo(right) <= 0;
+ }
+
+ ///
+ /// Comparison operator.
+ ///
+ /// Left TimeRange.
+ /// Right TimeRange.
+ public static bool operator <(TimeRange left, TimeRange right)
+ {
+ return left.CompareTo(right) < 0;
+ }
+
+ ///
+ /// Comparison operator.
+ ///
+ /// Left TimeRange.
+ /// Right TimeRange.
+ public static bool operator >=(TimeRange left, TimeRange right)
+ {
+ return left.CompareTo(right) >= 0;
+ }
+
+ ///
+ /// Comparison operator.
+ ///
+ /// Left TimeRange.
+ /// Right TimeRange.
+ public static bool operator >(TimeRange left, TimeRange right)
+ {
+ return left.CompareTo(right) > 0;
+ }
+
///
/// Compares this TimeRange to another TimeRange.
///
@@ -84,42 +144,6 @@ public class TimeRange : IComparable
{
return this.Start.GetHashCode() + this.Duration.GetHashCode();
}
-
- ///
- public static bool operator ==(TimeRange left, TimeRange right)
- {
- return left.Equals(right);
- }
-
- ///
- public static bool operator !=(TimeRange left, TimeRange right)
- {
- return !left.Equals(right);
- }
-
- ///
- public static bool operator <=(TimeRange left, TimeRange right)
- {
- return left.CompareTo(right) <= 0;
- }
-
- ///
- public static bool operator <(TimeRange left, TimeRange right)
- {
- return left.CompareTo(right) < 0;
- }
-
- ///
- public static bool operator >=(TimeRange left, TimeRange right)
- {
- return left.CompareTo(right) >= 0;
- }
-
- ///
- public static bool operator >(TimeRange left, TimeRange right)
- {
- return left.CompareTo(right) > 0;
- }
}
///
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs
index c33ae0b..8399b58 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs
@@ -197,8 +197,9 @@ public class Entrypoint : IServerEntryPoint
}
///
- /// Dispose.
+ /// Protected dispose.
///
+ /// Dispose.
protected virtual void Dispose(bool dispose)
{
if (!dispose)
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs
index de7e26e..6dde104 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs
@@ -44,6 +44,37 @@ public class Plugin : BasePlugin, IHasWebPages
RestoreTimestamps();
}
+ ///
+ /// Gets the results of fingerprinting all episodes.
+ ///
+ public Dictionary Intros { get; }
+
+ ///
+ /// Gets the mapping of season ids to episodes that have been queued for fingerprinting.
+ ///
+ public Dictionary> AnalysisQueue { get; }
+
+ ///
+ /// Gets or sets the total number of episodes in the queue.
+ ///
+ public int TotalQueued { get; set; }
+
+ ///
+ /// Gets the directory to cache fingerprints in.
+ ///
+ public string FingerprintCachePath { get; private set; }
+
+ ///
+ public override string Name => "Intro Skipper";
+
+ ///
+ public override Guid Id => Guid.Parse("c83d86bb-a1e0-4c35-a113-e2101cf4ee6b");
+
+ ///
+ /// Gets the plugin instance.
+ ///
+ public static Plugin? Instance { get; private set; }
+
///
/// Save timestamps to disk.
///
@@ -90,33 +121,4 @@ public class Plugin : BasePlugin, IHasWebPages
}
};
}
-
- ///
- /// Gets the results of fingerprinting all episodes.
- ///
- public Dictionary Intros { get; }
-
- ///
- /// Gets the mapping of season ids to episodes that have been queued for fingerprinting.
- ///
- public Dictionary> AnalysisQueue { get; }
-
- ///
- /// Gets or sets the total number of episodes in the queue.
- ///
- public int TotalQueued { get; set; }
-
- ///
- /// Gets the directory to cache fingerprints in.
- ///
- public string FingerprintCachePath { get; private set; }
-
- ///
- public override string Name => "Intro Skipper";
-
- ///
- public override Guid Id => Guid.Parse("c83d86bb-a1e0-4c35-a113-e2101cf4ee6b");
-
- ///
- public static Plugin? Instance { get; private set; }
}
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/FingerprinterTask.cs b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/FingerprinterTask.cs
index 5686175..9fde572 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/FingerprinterTask.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/FingerprinterTask.cs
@@ -13,32 +13,27 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper;
///
public class FingerprinterTask : IScheduledTask
{
- private readonly ILogger _logger;
-
///
/// Minimum time (in seconds) for a contiguous time range to be considered an introduction.
///
- private const int MINIMUM_INTRO_DURATION = 15;
+ private const int MinimumIntroDuration = 15;
///
/// Maximum number of bits (out of 32 total) that can be different between segments before they are considered dissimilar.
///
- private const double MAXIMUM_DIFFERENCES = 3;
+ private const double MaximumDifferences = 3;
///
/// Maximum time permitted between timestamps before they are considered non-contiguous.
///
- private const double MAXIMUM_DISTANCE = 3.25;
+ private const double MaximumDistance = 3.25;
///
/// Seconds of audio in one number from the fingerprint. Defined by Chromaprint.
///
- private const double SAMPLES_TO_SECONDS = 0.128;
+ private const double SamplesToSeconds = 0.128;
- ///
- /// Gets the last detected intro sequence. Only populated when a unit test is running.
- ///
- public static Intro LastIntro { get; private set; } = new Intro();
+ private readonly ILogger _logger;
///
/// Initializes a new instance of the class.
@@ -49,6 +44,11 @@ public class FingerprinterTask : IScheduledTask
_logger = logger;
}
+ ///
+ /// Gets the last detected intro sequence. Only populated when a unit test is running.
+ ///
+ public static Intro LastIntro { get; private set; } = new Intro();
+
///
/// Gets the task name.
///
@@ -324,13 +324,13 @@ public class FingerprinterTask : IScheduledTask
var diff = lhs[lhsPosition] ^ rhs[rhsPosition];
// If the difference between the samples is small, flag both times as similar.
- if (CountBits(diff) > MAXIMUM_DIFFERENCES)
+ if (CountBits(diff) > MaximumDifferences)
{
continue;
}
- var lhsTime = lhsPosition * SAMPLES_TO_SECONDS;
- var rhsTime = rhsPosition * SAMPLES_TO_SECONDS;
+ var lhsTime = lhsPosition * SamplesToSeconds;
+ var rhsTime = rhsPosition * SamplesToSeconds;
lhsTimes.Add(lhsTime);
rhsTimes.Add(rhsTime);
@@ -341,14 +341,14 @@ public class FingerprinterTask : IScheduledTask
rhsTimes.Add(double.MaxValue);
// Now that both fingerprints have been compared at this shift, see if there's a contiguous time range.
- var lContiguous = TimeRangeHelpers.FindContiguous(lhsTimes.ToArray(), MAXIMUM_DISTANCE);
- if (lContiguous is null || lContiguous.Duration < MINIMUM_INTRO_DURATION)
+ var lContiguous = TimeRangeHelpers.FindContiguous(lhsTimes.ToArray(), MaximumDistance);
+ if (lContiguous is null || lContiguous.Duration < MinimumIntroDuration)
{
return (new TimeRange(), new TimeRange());
}
// Since LHS had a contiguous time range, RHS must have one also.
- var rContiguous = TimeRangeHelpers.FindContiguous(rhsTimes.ToArray(), MAXIMUM_DISTANCE)!;
+ var rContiguous = TimeRangeHelpers.FindContiguous(rhsTimes.ToArray(), MaximumDistance)!;
// Tweak the end timestamps just a bit to ensure as little content as possible is skipped over.
if (lContiguous.Duration >= 90)