Enable StyleCop analyzers
This commit is contained in:
parent
547a2c705b
commit
96333f5f9e
@ -16,6 +16,7 @@
|
|||||||
<PackageReference Include="Jellyfin.Controller" Version="10.*-*" />
|
<PackageReference Include="Jellyfin.Controller" Version="10.*-*" />
|
||||||
<PackageReference Include="Jellyfin.Model" Version="10.*-*" />
|
<PackageReference Include="Jellyfin.Model" Version="10.*-*" />
|
||||||
<PackageReference Include="SerilogAnalyzer" Version="0.15.0" PrivateAssets="All" />
|
<PackageReference Include="SerilogAnalyzer" Version="0.15.0" PrivateAssets="All" />
|
||||||
|
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.376" PrivateAssets="All" />
|
||||||
<PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" Version="1.1.31" PrivateAssets="All" />
|
<PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" Version="1.1.31" PrivateAssets="All" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -8,21 +8,6 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class TimeRange : IComparable
|
public class TimeRange : IComparable
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the time range start (in seconds).
|
|
||||||
/// </summary>
|
|
||||||
public double Start { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the time range end (in seconds).
|
|
||||||
/// </summary>
|
|
||||||
public double End { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the duration of this time range (in seconds).
|
|
||||||
/// </summary>
|
|
||||||
public double Duration => End - Start;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="TimeRange"/> class.
|
/// Initializes a new instance of the <see cref="TimeRange"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -53,6 +38,81 @@ public class TimeRange : IComparable
|
|||||||
End = original.End;
|
End = original.End;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the time range start (in seconds).
|
||||||
|
/// </summary>
|
||||||
|
public double Start { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the time range end (in seconds).
|
||||||
|
/// </summary>
|
||||||
|
public double End { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the duration of this time range (in seconds).
|
||||||
|
/// </summary>
|
||||||
|
public double Duration => End - Start;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Comparison operator.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="left">Left TimeRange.</param>
|
||||||
|
/// <param name="right">Right TimeRange.</param>
|
||||||
|
public static bool operator ==(TimeRange left, TimeRange right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Comparison operator.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="left">Left TimeRange.</param>
|
||||||
|
/// <param name="right">Right TimeRange.</param>
|
||||||
|
public static bool operator !=(TimeRange left, TimeRange right)
|
||||||
|
{
|
||||||
|
return !left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Comparison operator.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="left">Left TimeRange.</param>
|
||||||
|
/// <param name="right">Right TimeRange.</param>
|
||||||
|
public static bool operator <=(TimeRange left, TimeRange right)
|
||||||
|
{
|
||||||
|
return left.CompareTo(right) <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Comparison operator.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="left">Left TimeRange.</param>
|
||||||
|
/// <param name="right">Right TimeRange.</param>
|
||||||
|
public static bool operator <(TimeRange left, TimeRange right)
|
||||||
|
{
|
||||||
|
return left.CompareTo(right) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Comparison operator.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="left">Left TimeRange.</param>
|
||||||
|
/// <param name="right">Right TimeRange.</param>
|
||||||
|
public static bool operator >=(TimeRange left, TimeRange right)
|
||||||
|
{
|
||||||
|
return left.CompareTo(right) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Comparison operator.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="left">Left TimeRange.</param>
|
||||||
|
/// <param name="right">Right TimeRange.</param>
|
||||||
|
public static bool operator >(TimeRange left, TimeRange right)
|
||||||
|
{
|
||||||
|
return left.CompareTo(right) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Compares this TimeRange to another TimeRange.
|
/// Compares this TimeRange to another TimeRange.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -84,42 +144,6 @@ public class TimeRange : IComparable
|
|||||||
{
|
{
|
||||||
return this.Start.GetHashCode() + this.Duration.GetHashCode();
|
return this.Start.GetHashCode() + this.Duration.GetHashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public static bool operator ==(TimeRange left, TimeRange right)
|
|
||||||
{
|
|
||||||
return left.Equals(right);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public static bool operator !=(TimeRange left, TimeRange right)
|
|
||||||
{
|
|
||||||
return !left.Equals(right);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public static bool operator <=(TimeRange left, TimeRange right)
|
|
||||||
{
|
|
||||||
return left.CompareTo(right) <= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public static bool operator <(TimeRange left, TimeRange right)
|
|
||||||
{
|
|
||||||
return left.CompareTo(right) < 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public static bool operator >=(TimeRange left, TimeRange right)
|
|
||||||
{
|
|
||||||
return left.CompareTo(right) >= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public static bool operator >(TimeRange left, TimeRange right)
|
|
||||||
{
|
|
||||||
return left.CompareTo(right) > 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -197,8 +197,9 @@ public class Entrypoint : IServerEntryPoint
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Dispose.
|
/// Protected dispose.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="dispose">Dispose.</param>
|
||||||
protected virtual void Dispose(bool dispose)
|
protected virtual void Dispose(bool dispose)
|
||||||
{
|
{
|
||||||
if (!dispose)
|
if (!dispose)
|
||||||
|
@ -44,6 +44,37 @@ public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
|||||||
RestoreTimestamps();
|
RestoreTimestamps();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the results of fingerprinting all episodes.
|
||||||
|
/// </summary>
|
||||||
|
public Dictionary<Guid, Intro> Intros { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the mapping of season ids to episodes that have been queued for fingerprinting.
|
||||||
|
/// </summary>
|
||||||
|
public Dictionary<Guid, List<QueuedEpisode>> AnalysisQueue { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the total number of episodes in the queue.
|
||||||
|
/// </summary>
|
||||||
|
public int TotalQueued { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the directory to cache fingerprints in.
|
||||||
|
/// </summary>
|
||||||
|
public string FingerprintCachePath { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override string Name => "Intro Skipper";
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override Guid Id => Guid.Parse("c83d86bb-a1e0-4c35-a113-e2101cf4ee6b");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the plugin instance.
|
||||||
|
/// </summary>
|
||||||
|
public static Plugin? Instance { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Save timestamps to disk.
|
/// Save timestamps to disk.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -90,33 +121,4 @@ public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the results of fingerprinting all episodes.
|
|
||||||
/// </summary>
|
|
||||||
public Dictionary<Guid, Intro> Intros { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the mapping of season ids to episodes that have been queued for fingerprinting.
|
|
||||||
/// </summary>
|
|
||||||
public Dictionary<Guid, List<QueuedEpisode>> AnalysisQueue { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the total number of episodes in the queue.
|
|
||||||
/// </summary>
|
|
||||||
public int TotalQueued { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the directory to cache fingerprints in.
|
|
||||||
/// </summary>
|
|
||||||
public string FingerprintCachePath { get; private set; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override string Name => "Intro Skipper";
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Guid Id => Guid.Parse("c83d86bb-a1e0-4c35-a113-e2101cf4ee6b");
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public static Plugin? Instance { get; private set; }
|
|
||||||
}
|
}
|
||||||
|
@ -13,32 +13,27 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class FingerprinterTask : IScheduledTask
|
public class FingerprinterTask : IScheduledTask
|
||||||
{
|
{
|
||||||
private readonly ILogger<FingerprinterTask> _logger;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Minimum time (in seconds) for a contiguous time range to be considered an introduction.
|
/// Minimum time (in seconds) for a contiguous time range to be considered an introduction.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private const int MINIMUM_INTRO_DURATION = 15;
|
private const int MinimumIntroDuration = 15;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Maximum number of bits (out of 32 total) that can be different between segments before they are considered dissimilar.
|
/// Maximum number of bits (out of 32 total) that can be different between segments before they are considered dissimilar.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private const double MAXIMUM_DIFFERENCES = 3;
|
private const double MaximumDifferences = 3;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Maximum time permitted between timestamps before they are considered non-contiguous.
|
/// Maximum time permitted between timestamps before they are considered non-contiguous.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private const double MAXIMUM_DISTANCE = 3.25;
|
private const double MaximumDistance = 3.25;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Seconds of audio in one number from the fingerprint. Defined by Chromaprint.
|
/// Seconds of audio in one number from the fingerprint. Defined by Chromaprint.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private const double SAMPLES_TO_SECONDS = 0.128;
|
private const double SamplesToSeconds = 0.128;
|
||||||
|
|
||||||
/// <summary>
|
private readonly ILogger<FingerprinterTask> _logger;
|
||||||
/// Gets the last detected intro sequence. Only populated when a unit test is running.
|
|
||||||
/// </summary>
|
|
||||||
public static Intro LastIntro { get; private set; } = new Intro();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="FingerprinterTask"/> class.
|
/// Initializes a new instance of the <see cref="FingerprinterTask"/> class.
|
||||||
@ -49,6 +44,11 @@ public class FingerprinterTask : IScheduledTask
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the last detected intro sequence. Only populated when a unit test is running.
|
||||||
|
/// </summary>
|
||||||
|
public static Intro LastIntro { get; private set; } = new Intro();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the task name.
|
/// Gets the task name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -324,13 +324,13 @@ public class FingerprinterTask : IScheduledTask
|
|||||||
var diff = lhs[lhsPosition] ^ rhs[rhsPosition];
|
var diff = lhs[lhsPosition] ^ rhs[rhsPosition];
|
||||||
|
|
||||||
// If the difference between the samples is small, flag both times as similar.
|
// If the difference between the samples is small, flag both times as similar.
|
||||||
if (CountBits(diff) > MAXIMUM_DIFFERENCES)
|
if (CountBits(diff) > MaximumDifferences)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var lhsTime = lhsPosition * SAMPLES_TO_SECONDS;
|
var lhsTime = lhsPosition * SamplesToSeconds;
|
||||||
var rhsTime = rhsPosition * SAMPLES_TO_SECONDS;
|
var rhsTime = rhsPosition * SamplesToSeconds;
|
||||||
|
|
||||||
lhsTimes.Add(lhsTime);
|
lhsTimes.Add(lhsTime);
|
||||||
rhsTimes.Add(rhsTime);
|
rhsTimes.Add(rhsTime);
|
||||||
@ -341,14 +341,14 @@ public class FingerprinterTask : IScheduledTask
|
|||||||
rhsTimes.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.
|
// 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);
|
var lContiguous = TimeRangeHelpers.FindContiguous(lhsTimes.ToArray(), MaximumDistance);
|
||||||
if (lContiguous is null || lContiguous.Duration < MINIMUM_INTRO_DURATION)
|
if (lContiguous is null || lContiguous.Duration < MinimumIntroDuration)
|
||||||
{
|
{
|
||||||
return (new TimeRange(), new TimeRange());
|
return (new TimeRange(), new TimeRange());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since LHS had a contiguous time range, RHS must have one also.
|
// 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.
|
// Tweak the end timestamps just a bit to ensure as little content as possible is skipped over.
|
||||||
if (lContiguous.Duration >= 90)
|
if (lContiguous.Duration >= 90)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user