From 547a2c705b79451242bf64b953de40b67fddc52f Mon Sep 17 00:00:00 2001
From: ConfusedPolarBear <33811686+ConfusedPolarBear@users.noreply.github.com>
Date: Mon, 9 May 2022 22:50:41 -0500
Subject: [PATCH] Reformat code to comply with StyleCop analyzers
---
.../Configuration/PluginConfiguration.cs | 10 +--
.../Controllers/SkipIntroController.cs | 3 +-
.../Data/FingerprintException.cs | 16 ++--
.../Data/Intro.cs | 16 ++--
.../Data/QueuedEpisode.cs | 17 ++--
.../Data/TimeRange.cs | 17 ++--
.../Entrypoint.cs | 62 +++++++++------
.../FPCalc.cs | 27 ++++---
.../Plugin.cs | 8 +-
.../ScheduledTasks/FingerprinterTask.cs | 79 +++++++++++--------
10 files changed, 149 insertions(+), 106 deletions(-)
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/PluginConfiguration.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/PluginConfiguration.cs
index 3996c9c..fb5660f 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/PluginConfiguration.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/PluginConfiguration.cs
@@ -1,7 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-
using MediaBrowser.Model.Plugins;
namespace ConfusedPolarBear.Plugin.IntroSkipper.Configuration;
@@ -19,17 +15,17 @@ public class PluginConfiguration : BasePluginConfiguration
}
///
- /// If the output of fpcalc should be cached to the filesystem.
+ /// Gets or sets a value indicating whether the output of fpcalc should be cached to the filesystem.
///
public bool CacheFingerprints { get; set; }
///
- /// Seconds before the intro starts to show the skip prompt at.
+ /// Gets or sets the seconds before the intro starts to show the skip prompt at.
///
public int ShowPromptAdjustment { get; set; } = 5;
///
- /// Seconds after the intro starts to hide the skip prompt at.
+ /// Gets or sets the seconds after the intro starts to hide the skip prompt at.
///
public int HidePromptAdjustment { get; set; } = 10;
}
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/SkipIntroController.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/SkipIntroController.cs
index e360552..343641a 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/SkipIntroController.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/SkipIntroController.cs
@@ -14,7 +14,7 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper.Controllers;
public class SkipIntroController : ControllerBase
{
///
- /// Constructor.
+ /// Initializes a new instance of the class.
///
public SkipIntroController()
{
@@ -26,6 +26,7 @@ public class SkipIntroController : ControllerBase
/// ID of the episode. Required.
/// Episode contains an intro.
/// Failed to find an intro in the provided episode.
+ /// Detected intro.
[HttpGet("Episode/{id}/IntroTimestamps")]
public ActionResult GetIntroTimestamps([FromRoute] Guid id)
{
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Data/FingerprintException.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Data/FingerprintException.cs
index fb9a0a3..772b03c 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/Data/FingerprintException.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/Data/FingerprintException.cs
@@ -5,25 +5,29 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper;
///
/// Exception raised when an error is encountered analyzing audio.
///
-public class FingerprintException: Exception {
+public class FingerprintException : Exception
+{
///
- /// Constructor.
+ /// Initializes a new instance of the class.
///
public FingerprintException()
{
}
///
- /// Constructor.
+ /// Initializes a new instance of the class.
///
- public FingerprintException(string message): base(message)
+ /// Exception message.
+ public FingerprintException(string message) : base(message)
{
}
///
- /// Constructor.
+ /// Initializes a new instance of the class.
///
- public FingerprintException(string message, Exception inner): base(message, inner)
+ /// Exception message.
+ /// Inner exception.
+ public FingerprintException(string message, Exception inner) : base(message, inner)
{
}
}
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Data/Intro.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Data/Intro.cs
index d3f8bbd..a806b17 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/Data/Intro.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/Data/Intro.cs
@@ -6,34 +6,36 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper;
/// Result of fingerprinting and analyzing two episodes in a season.
/// All times are measured in seconds relative to the beginning of the media file.
///
-public class Intro {
+public class Intro
+{
///
- /// Episode ID.
+ /// Gets or sets the Episode ID.
///
public Guid EpisodeId { get; set; }
///
- /// If this introduction is valid or not. Invalid results should not be returned through the API.
+ /// Gets or sets a value indicating whether this introduction is valid or not.
+ /// Invalid results must not be returned through the API.
///
public bool Valid { get; set; }
///
- /// Introduction sequence start time.
+ /// Gets or sets the introduction sequence start time.
///
public double IntroStart { get; set; }
///
- /// Introduction sequence end time.
+ /// Gets or sets the introduction sequence end time.
///
public double IntroEnd { get; set; }
///
- /// Recommended time to display the skip intro prompt.
+ /// Gets or sets the recommended time to display the skip intro prompt.
///
public double ShowSkipPromptAt { get; set; }
///
- /// Recommended time to hide the skip intro prompt.
+ /// Gets or sets the recommended time to hide the skip intro prompt.
///
public double HideSkipPromptAt { get; set; }
}
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Data/QueuedEpisode.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Data/QueuedEpisode.cs
index 76f8a2f..ba4c460 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/Data/QueuedEpisode.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/Data/QueuedEpisode.cs
@@ -5,29 +5,30 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper;
///
/// Episode queued for analysis.
///
-public class QueuedEpisode {
+public class QueuedEpisode
+{
///
- /// Series name.
+ /// Gets or sets the series name.
///
- public string SeriesName { get; set; } = "";
+ public string SeriesName { get; set; } = string.Empty;
///
- /// Season number.
+ /// Gets or sets the season number.
///
public int SeasonNumber { get; set; }
///
- /// Episode id.
+ /// Gets or sets the episode id.
///
public Guid EpisodeId { get; set; }
///
- /// Full path to episode.
+ /// Gets or sets the full path to episode.
///
- public string Path { get; set; } = "";
+ public string Path { get; set; } = string.Empty;
///
- /// Seconds of media file to fingerprint.
+ /// Gets or sets the seconds of media file to fingerprint.
///
public int FingerprintDuration { get; set; }
}
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Data/TimeRange.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Data/TimeRange.cs
index 968c152..2b33f77 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/Data/TimeRange.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/Data/TimeRange.cs
@@ -9,22 +9,22 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper;
public class TimeRange : IComparable
{
///
- /// Time range start (in seconds).
+ /// Gets or sets the time range start (in seconds).
///
public double Start { get; set; }
///
- /// Time range end (in seconds).
+ /// Gets or sets the time range end (in seconds).
///
public double End { get; set; }
///
- /// Duration of this time range (in seconds).
+ /// Gets the duration of this time range (in seconds).
///
public double Duration => End - Start;
///
- /// Default constructor.
+ /// Initializes a new instance of the class.
///
public TimeRange()
{
@@ -33,8 +33,10 @@ public class TimeRange : IComparable
}
///
- /// Constructor.
+ /// Initializes a new instance of the class.
///
+ /// Time range start.
+ /// Time range end.
public TimeRange(double start, double end)
{
Start = start;
@@ -42,8 +44,9 @@ public class TimeRange : IComparable
}
///
- /// Copy constructor.
+ /// Initializes a new instance of the class.
///
+ /// Original TimeRange.
public TimeRange(TimeRange original)
{
Start = original.Start;
@@ -54,6 +57,7 @@ public class TimeRange : IComparable
/// Compares this TimeRange to another TimeRange.
///
/// Other object to compare against.
+ /// A signed integer that indicates whether this instance precedes, follows, or appears in the same position in the sort order as the obj parameter.
public int CompareTo(object? obj)
{
if (obj is not TimeRange tr)
@@ -128,6 +132,7 @@ public static class TimeRangeHelpers
///
/// Sorted timestamps to search.
/// Maximum distance permitted between contiguous timestamps.
+ /// The longest contiguous time range (if one was found), or null (if none was found).
public static TimeRange? FindContiguous(double[] times, double maximumDistance)
{
if (times.Length == 0)
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs
index 6b775ca..c33ae0b 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
-using System.Collections.Specialized;
using System.Threading.Tasks;
+using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
@@ -9,7 +9,6 @@ using MediaBrowser.Controller.Plugins;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Library;
using Microsoft.Extensions.Logging;
-using Jellyfin.Data.Enums;
namespace ConfusedPolarBear.Plugin.IntroSkipper;
@@ -26,7 +25,7 @@ public class Entrypoint : IServerEntryPoint
private readonly object _queueLock = new object();
///
- /// Constructor.
+ /// Initializes a new instance of the class.
///
/// User manager.
/// User view manager.
@@ -47,12 +46,14 @@ public class Entrypoint : IServerEntryPoint
///
/// Registers event handler.
///
+ /// Task.
public Task RunAsync()
{
FPCalc.Logger = _logger;
// Assert that fpcalc is installed
- if (!FPCalc.CheckFPCalcInstalled()) {
+ if (!FPCalc.CheckFPCalcInstalled())
+ {
_logger.LogError("fpcalc is not installed on this system - episodes will not be analyzed");
return Task.CompletedTask;
}
@@ -61,8 +62,10 @@ public class Entrypoint : IServerEntryPoint
_libraryManager.ItemAdded += ItemAdded;
// For all TV show libraries, enqueue all contained items.
- foreach (var folder in _libraryManager.GetVirtualFolders()) {
- if (folder.CollectionType != CollectionTypeOptions.TvShows) {
+ foreach (var folder in _libraryManager.GetVirtualFolders())
+ {
+ if (folder.CollectionType != CollectionTypeOptions.TvShows)
+ {
continue;
}
@@ -77,25 +80,30 @@ public class Entrypoint : IServerEntryPoint
return Task.CompletedTask;
}
- private void QueueLibraryContents(string rawId) {
+ private void QueueLibraryContents(string rawId)
+ {
// FIXME: do smarterer
- var query = new UserViewQuery() {
+ var query = new UserViewQuery()
+ {
UserId = GetAdministrator(),
};
// Get all items from this library. Since intros may change within a season, sort the items before adding them.
var folder = _userViewManager.GetUserViews(query)[0];
- var items = folder.GetItems(new InternalItemsQuery() {
+ var items = folder.GetItems(new InternalItemsQuery()
+ {
ParentId = Guid.Parse(rawId),
- OrderBy = new [] { ("SortName", SortOrder.Ascending) },
+ OrderBy = new[] { ("SortName", SortOrder.Ascending) },
IncludeItemTypes = new BaseItemKind[] { BaseItemKind.Episode },
Recursive = true,
});
// Queue all episodes on the server for fingerprinting.
- foreach (var item in items.Items) {
- if (item is not Episode episode) {
+ foreach (var item in items.Items)
+ {
+ if (item is not Episode episode)
+ {
_logger.LogError("Item {Name} is not an episode", item.Name);
continue;
}
@@ -111,7 +119,8 @@ public class Entrypoint : IServerEntryPoint
/// ItemChangeEventArgs.
private void ItemAdded(object? sender, ItemChangeEventArgs e)
{
- if (e.Item is not Episode episode) {
+ if (e.Item is not Episode episode)
+ {
return;
}
@@ -120,28 +129,34 @@ public class Entrypoint : IServerEntryPoint
QueueEpisode(episode);
}
- private void QueueEpisode(Episode episode) {
- if (Plugin.Instance is null) {
+ private void QueueEpisode(Episode episode)
+ {
+ if (Plugin.Instance is null)
+ {
throw new InvalidOperationException("plugin instance was null");
}
- lock (_queueLock) {
+ lock (_queueLock)
+ {
var queue = Plugin.Instance.AnalysisQueue;
// Allocate a new list for each new season
- if (!queue.ContainsKey(episode.SeasonId)) {
+ 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) {
+ if (duration >= 5 * 60)
+ {
duration /= 4;
}
duration = Math.Min(duration, 10 * 60);
- Plugin.Instance.AnalysisQueue[episode.SeasonId].Add(new QueuedEpisode() {
+ Plugin.Instance.AnalysisQueue[episode.SeasonId].Add(new QueuedEpisode()
+ {
SeriesName = episode.SeriesName,
SeasonNumber = episode.AiredSeasonNumber ?? 0,
EpisodeId = episode.Id,
@@ -156,9 +171,12 @@ public class Entrypoint : IServerEntryPoint
///
/// FIXME: don't do this.
///
- private Guid GetAdministrator() {
- foreach (var user in _userManager.Users) {
- if (!user.HasPermission(Jellyfin.Data.Enums.PermissionKind.IsAdministrator)) {
+ private Guid GetAdministrator()
+ {
+ foreach (var user in _userManager.Users)
+ {
+ if (!user.HasPermission(Jellyfin.Data.Enums.PermissionKind.IsAdministrator))
+ {
continue;
}
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/FPCalc.cs b/ConfusedPolarBear.Plugin.IntroSkipper/FPCalc.cs
index b69034e..01eb919 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/FPCalc.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/FPCalc.cs
@@ -12,20 +12,22 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper;
///
/// Wrapper for the fpcalc utility.
///
-public static class FPCalc {
+public static class FPCalc
+{
///
- /// Logger.
+ /// Gets or sets the logger.
///
public static ILogger? Logger { get; set; }
///
/// Check that the fpcalc utility is installed.
///
+ /// true if fpcalc is installed, false on any error.
public static bool CheckFPCalcInstalled()
{
try
{
- var version = getOutput("-version", 2000);
+ var version = GetOutput("-version", 2000);
Logger?.LogDebug("fpcalc version: {Version}", version);
return version.StartsWith("fpcalc version", StringComparison.OrdinalIgnoreCase);
}
@@ -39,10 +41,11 @@ public static class FPCalc {
/// Fingerprint a queued episode.
///
/// Queued episode to fingerprint.
+ /// Numerical fingerprint points.
public static ReadOnlyCollection Fingerprint(QueuedEpisode episode)
{
// Try to load this episode from cache before running fpcalc.
- if (loadCachedFingerprint(episode, out ReadOnlyCollection cachedFingerprint))
+ if (LoadCachedFingerprint(episode, out ReadOnlyCollection cachedFingerprint))
{
Logger?.LogDebug("Fingerprint cache hit on {File}", episode.Path);
return cachedFingerprint;
@@ -60,7 +63,7 @@ public static class FPCalc {
* FINGERPRINT=123456789,987654321,123456789,987654321,123456789,987654321
*/
- var raw = getOutput(args);
+ var raw = GetOutput(args);
var lines = raw.Split("\n");
if (lines.Length < 2)
@@ -79,7 +82,7 @@ public static class FPCalc {
}
// Try to cache this fingerprint.
- cacheFingerprint(episode, results);
+ CacheFingerprint(episode, results);
return results.AsReadOnly();
}
@@ -89,7 +92,7 @@ public static class FPCalc {
///
/// Arguments to pass to fpcalc.
/// Timeout (in seconds) to wait for fpcalc to exit.
- private static string getOutput(string args, int timeout = 60 * 1000)
+ private static string GetOutput(string args, int timeout = 60 * 1000)
{
var info = new ProcessStartInfo("fpcalc", args);
info.CreateNoWindow = true;
@@ -110,7 +113,7 @@ public static class FPCalc {
/// Episode to try to load from cache.
/// ReadOnlyCollection to store the fingerprint in.
/// true if the episode was successfully loaded from cache, false on any other error.
- private static bool loadCachedFingerprint(QueuedEpisode episode, out ReadOnlyCollection fingerprint)
+ private static bool LoadCachedFingerprint(QueuedEpisode episode, out ReadOnlyCollection fingerprint)
{
fingerprint = new List().AsReadOnly();
@@ -120,7 +123,7 @@ public static class FPCalc {
return false;
}
- var path = getFingerprintCachePath(episode);
+ var path = GetFingerprintCachePath(episode);
// If this episode isn't cached, bail out.
if (!File.Exists(path))
@@ -148,7 +151,7 @@ public static class FPCalc {
///
/// Episode to store in cache.
/// Fingerprint of the episode to store.
- private static void cacheFingerprint(QueuedEpisode episode, List fingerprint)
+ private static void CacheFingerprint(QueuedEpisode episode, List fingerprint)
{
// Bail out if caching isn't enabled.
if (!(Plugin.Instance?.Configuration.CacheFingerprints ?? false))
@@ -164,14 +167,14 @@ public static class FPCalc {
}
// Cache the episode.
- File.WriteAllLinesAsync(getFingerprintCachePath(episode), lines, Encoding.UTF8).ConfigureAwait(false);
+ File.WriteAllLinesAsync(GetFingerprintCachePath(episode), lines, Encoding.UTF8).ConfigureAwait(false);
}
///
/// Determines the path an episode should be cached at.
///
/// Episode.
- private static string getFingerprintCachePath(QueuedEpisode episode)
+ private static string GetFingerprintCachePath(QueuedEpisode episode)
{
return Path.Join(Plugin.Instance!.FingerprintCachePath, episode.EpisodeId.ToString("N"));
}
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs
index be64532..de7e26e 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs
@@ -92,22 +92,22 @@ public class Plugin : BasePlugin, IHasWebPages
}
///
- /// Results of fingerprinting all episodes.
+ /// Gets the results of fingerprinting all episodes.
///
public Dictionary Intros { get; }
///
- /// Map of season ids to episodes that have been queued for fingerprinting.
+ /// Gets the mapping of season ids to episodes that have been queued for fingerprinting.
///
public Dictionary> AnalysisQueue { get; }
///
- /// Total number of episodes in the queue.
+ /// Gets or sets the total number of episodes in the queue.
///
public int TotalQueued { get; set; }
///
- /// Directory to cache fingerprints in.
+ /// Gets the directory to cache fingerprints in.
///
public string FingerprintCachePath { get; private set; }
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/FingerprinterTask.cs b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/FingerprinterTask.cs
index 80cdea3..5686175 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/FingerprinterTask.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/FingerprinterTask.cs
@@ -11,7 +11,8 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper;
///
/// Fingerprint all queued episodes at the set time.
///
-public class FingerprinterTask : IScheduledTask {
+public class FingerprinterTask : IScheduledTask
+{
private readonly ILogger _logger;
///
@@ -35,35 +36,36 @@ public class FingerprinterTask : IScheduledTask {
private const double SAMPLES_TO_SECONDS = 0.128;
///
- /// Gets or sets the last detected intro sequence. Only populated when a unit test is running.
+ /// Gets the last detected intro sequence. Only populated when a unit test is running.
///
public static Intro LastIntro { get; private set; } = new Intro();
///
- /// Constructor.
+ /// Initializes a new instance of the class.
///
+ /// Logger.
public FingerprinterTask(ILogger logger)
{
_logger = logger;
}
///
- /// Task name.
+ /// Gets the task name.
///
public string Name => "Analyze episodes";
///
- /// Task category.
+ /// Gets the task category.
///
public string Category => "Intro Skipper";
///
- /// Task description.
+ /// Gets the task description.
///
public string Description => "Analyzes the audio of all television episodes to find introduction sequences.";
///
- /// Key.
+ /// Gets the task key.
///
public string Key => "CPBIntroSkipperRunFingerprinter";
@@ -72,12 +74,14 @@ public class FingerprinterTask : IScheduledTask {
///
/// Progress.
/// Cancellation token.
+ /// Task.
public Task ExecuteAsync(IProgress progress, CancellationToken cancellationToken)
{
var queue = Plugin.Instance!.AnalysisQueue;
var totalProcessed = 0;
- foreach (var season in queue) {
+ foreach (var season in queue)
+ {
var first = season.Value[0];
// Don't analyze seasons with <= 1 episode or specials
@@ -94,7 +98,8 @@ public class FingerprinterTask : IScheduledTask {
// Ensure there are an even number of episodes
var episodes = season.Value;
- if (episodes.Count % 2 != 0) {
+ if (episodes.Count % 2 != 0)
+ {
episodes.Add(episodes[episodes.Count - 2]);
}
@@ -109,7 +114,7 @@ public class FingerprinterTask : IScheduledTask {
}
var lhs = episodes[i];
- var rhs = episodes[i+1];
+ var rhs = episodes[i + 1];
// TODO: make configurable
if (!everFoundIntro && failures >= 6)
@@ -190,7 +195,7 @@ public class FingerprinterTask : IScheduledTask {
var limit = Math.Min(lhs.Count, rhs.Count);
// First, test if an intro can be found within the first 5 seconds of the episodes (±5/0.128 = ±40 samples).
- var (lhsContiguous, rhsContiguous) = shiftEpisodes(lhs, rhs, -40, 40);
+ var (lhsContiguous, rhsContiguous) = ShiftEpisodes(lhs, rhs, -40, 40);
lhsRanges.AddRange(lhsContiguous);
rhsRanges.AddRange(rhsContiguous);
@@ -199,7 +204,7 @@ public class FingerprinterTask : IScheduledTask {
{
_logger.LogDebug("using full scan");
- (lhsContiguous, rhsContiguous) = shiftEpisodes(lhs, rhs, -1 * limit, limit);
+ (lhsContiguous, rhsContiguous) = ShiftEpisodes(lhs, rhs, -1 * limit, limit);
lhsRanges.AddRange(lhsContiguous);
rhsRanges.AddRange(rhsContiguous);
}
@@ -219,8 +224,8 @@ public class FingerprinterTask : IScheduledTask {
// TODO: is this the optimal way to indicate that an intro couldn't be found?
// the goal here is to not waste time every task run reprocessing episodes that we know will fail.
- storeIntro(lhsEpisode.EpisodeId, 0, 0);
- storeIntro(rhsEpisode.EpisodeId, 0, 0);
+ StoreIntro(lhsEpisode.EpisodeId, 0, 0);
+ StoreIntro(rhsEpisode.EpisodeId, 0, 0);
return false;
}
@@ -243,8 +248,8 @@ public class FingerprinterTask : IScheduledTask {
rhsIntro.Start = 0;
}
- storeIntro(lhsEpisode.EpisodeId, lhsIntro.Start, lhsIntro.End);
- storeIntro(rhsEpisode.EpisodeId, rhsIntro.Start, rhsIntro.End);
+ StoreIntro(lhsEpisode.EpisodeId, lhsIntro.Start, lhsIntro.End);
+ StoreIntro(rhsEpisode.EpisodeId, rhsIntro.Start, rhsIntro.End);
return true;
}
@@ -256,18 +261,18 @@ public class FingerprinterTask : IScheduledTask {
/// Second episode fingerprint.
/// Lower end of the shift range.
/// Upper end of the shift range.
- private static (List, List) shiftEpisodes(
+ private static (List Lhs, List Rhs) ShiftEpisodes(
ReadOnlyCollection lhs,
ReadOnlyCollection rhs,
int lower,
- int upper
- ) {
+ int upper)
+ {
var lhsRanges = new List();
var rhsRanges = new List();
for (int amount = lower; amount <= upper; amount++)
{
- var (lRange, rRange) = findContiguous(lhs, rhs, amount);
+ var (lRange, rRange) = FindContiguous(lhs, rhs, amount);
if (lRange.End == 0 && rRange.End == 0)
{
@@ -287,18 +292,21 @@ public class FingerprinterTask : IScheduledTask {
/// First fingerprint to compare.
/// Second fingerprint to compare.
/// Amount to shift one fingerprint by.
- private static (TimeRange, TimeRange) findContiguous(
+ private static (TimeRange Lhs, TimeRange Rhs) FindContiguous(
ReadOnlyCollection lhs,
ReadOnlyCollection rhs,
- int shiftAmount
- ) {
+ int shiftAmount)
+ {
var leftOffset = 0;
var rightOffset = 0;
// Calculate the offsets for the left and right hand sides.
- if (shiftAmount < 0) {
+ if (shiftAmount < 0)
+ {
leftOffset -= shiftAmount;
- } else {
+ }
+ else
+ {
rightOffset += shiftAmount;
}
@@ -308,14 +316,15 @@ public class FingerprinterTask : IScheduledTask {
var upperLimit = Math.Min(lhs.Count, rhs.Count) - Math.Abs(shiftAmount);
// XOR all elements in LHS and RHS, using the shift amount from above.
- for (var i = 0; i < upperLimit; i++) {
+ for (var i = 0; i < upperLimit; i++)
+ {
// XOR both samples at the current position.
var lhsPosition = i + leftOffset;
var rhsPosition = i + rightOffset;
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) > MAXIMUM_DIFFERENCES)
{
continue;
}
@@ -328,8 +337,8 @@ public class FingerprinterTask : IScheduledTask {
}
// Ensure the last timestamp is checked
- lhsTimes.Add(Double.MaxValue);
- rhsTimes.Add(Double.MaxValue);
+ lhsTimes.Add(double.MaxValue);
+ 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);
@@ -356,7 +365,7 @@ public class FingerprinterTask : IScheduledTask {
return (lContiguous, rContiguous);
}
- private static void storeIntro(Guid episode, double introStart, double introEnd)
+ private static void StoreIntro(Guid episode, double introStart, double introEnd)
{
var intro = new Intro()
{
@@ -375,12 +384,15 @@ public class FingerprinterTask : IScheduledTask {
Plugin.Instance.Intros[episode] = intro;
}
- private static int countBits(uint number) {
+ private static int CountBits(uint number)
+ {
var count = 0;
- for (var i = 0; i < 32; i++) {
+ for (var i = 0; i < 32; i++)
+ {
var low = (number >> i) & 1;
- if (low == 1) {
+ if (low == 1)
+ {
count++;
}
}
@@ -391,6 +403,7 @@ public class FingerprinterTask : IScheduledTask {
///
/// Get task triggers.
///
+ /// Task triggers.
public IEnumerable GetDefaultTriggers()
{
return new[]