From 19660cb1b25f19d30213f241e1219c7487a3a8b9 Mon Sep 17 00:00:00 2001 From: ConfusedPolarBear <33811686+ConfusedPolarBear@users.noreply.github.com> Date: Mon, 30 May 2022 02:23:36 -0500 Subject: [PATCH] Add initial troubleshooting code --- .../Configuration/configPage.html | 290 +++++++++++++++++- .../Controllers/TroubleshooterController.cs | 120 ++++++++ .../Data/QueuedEpisode.cs | 5 + .../Data/TroubleshooterEpisode.cs | 30 ++ .../Entrypoint.cs | 1 + 5 files changed, 429 insertions(+), 17 deletions(-) create mode 100644 ConfusedPolarBear.Plugin.IntroSkipper/Controllers/TroubleshooterController.cs create mode 100644 ConfusedPolarBear.Plugin.IntroSkipper/Data/TroubleshooterEpisode.cs diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html index e44a5de..7b88f32 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html @@ -1,11 +1,14 @@ + Template + -
+
@@ -17,7 +20,8 @@
If checked, will store the fingerprints for all subsequently scanned files to disk. - Caching fingerprints avoids having to re-run fpcalc on each file, at the expense of disk usage. + Caching fingerprints avoids having to re-run fpcalc on each file, at the expense of disk + usage.
@@ -44,16 +48,153 @@
+ +
+

Troubleshooter

+

Compare the audio fingerprint of two episodes.

+ + + +
+ + + +
+ + +
+
+ + + +
- + + + diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/TroubleshooterController.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/TroubleshooterController.cs new file mode 100644 index 0000000..492691e --- /dev/null +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/TroubleshooterController.cs @@ -0,0 +1,120 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Globalization; +using System.Net.Mime; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace ConfusedPolarBear.Plugin.IntroSkipper.Controllers; + +/// +/// Intro skipper troubleshooting controller. Allows browsing fingerprints on a per episode basis. +/// +[Authorize] +[ApiController] +[Produces(MediaTypeNames.Application.Json)] +[Route("Intros")] +public class TroubleshooterController : ControllerBase +{ + /// + /// Initializes a new instance of the class. + /// + public TroubleshooterController() + { + } + + /// + /// Returns all show names and seasons. + /// + /// Dictionary of show names to a list of season names. + [HttpGet("Shows")] + public ActionResult>> GetShowSeasons() + { + var showSeasons = new Dictionary>(); + + // Loop through all episodes in the analysis queue + foreach (var episodes in Plugin.Instance!.AnalysisQueue) + { + foreach (var episode in episodes.Value) + { + // Add each season's name to the series hashset + var series = episode.SeriesName; + + if (!showSeasons.ContainsKey(series)) + { + showSeasons[series] = new HashSet(); + } + + showSeasons[series].Add(GetSeasonName(episode)); + } + } + + return showSeasons; + } + + /// + /// Returns the names and unique identifiers of all episodes in the provided season. + /// + /// Show name. + /// Season name. + /// List of episode titles. + [HttpGet("Show/{Series}/{Season}")] + public ActionResult> GetSeasonEpisodes( + [FromRoute] string series, + [FromRoute] string season) + { + var episodes = new List(); + + foreach (var queuedEpisodes in Plugin.Instance!.AnalysisQueue) + { + var first = queuedEpisodes.Value[0]; + var firstSeasonName = GetSeasonName(first); + + // Assert that the queued episode series and season are equal to what was requested + if ( + !string.Equals(first.SeriesName, series, StringComparison.OrdinalIgnoreCase) || + !string.Equals(firstSeasonName, season, StringComparison.OrdinalIgnoreCase)) + { + continue; + } + + foreach (var queuedEpisode in queuedEpisodes.Value) + { + episodes.Add(new TroubleshooterEpisode(queuedEpisode.EpisodeId, queuedEpisode.Name)); + } + } + + return episodes; + } + + /// + /// Fingerprint the provided episode and returns the uncompressed fingerprint data points. + /// + /// Episode id. + /// Read only collection of fingerprint points. + [HttpGet("Fingerprint/{Id}")] + public ActionResult> GetEpisodeFingerprint([FromRoute] Guid id) + { + var queue = Plugin.Instance!.AnalysisQueue; + + // Search through all queued episodes to find the requested id + foreach (var season in queue) + { + foreach (var needle in season.Value) + { + if (needle.EpisodeId == id) + { + return FPCalc.Fingerprint(needle); + } + } + } + + return NotFound(); + } + + private string GetSeasonName(QueuedEpisode episode) + { + return "Season " + episode.SeasonNumber.ToString(CultureInfo.InvariantCulture); + } +} diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Data/QueuedEpisode.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Data/QueuedEpisode.cs index ba4c460..915d33f 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Data/QueuedEpisode.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Data/QueuedEpisode.cs @@ -27,6 +27,11 @@ public class QueuedEpisode /// public string Path { get; set; } = string.Empty; + /// + /// Gets or sets the name of the episode. + /// + public string Name { get; set; } = string.Empty; + /// /// Gets or sets the seconds of media file to fingerprint. /// diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Data/TroubleshooterEpisode.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Data/TroubleshooterEpisode.cs new file mode 100644 index 0000000..17e9d61 --- /dev/null +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Data/TroubleshooterEpisode.cs @@ -0,0 +1,30 @@ +using System; + +namespace ConfusedPolarBear.Plugin.IntroSkipper; + +/// +/// Episode name and internal ID as returned by the troubleshooter. +/// +public class TroubleshooterEpisode +{ + /// + /// Initializes a new instance of the class. + /// + /// Episode id. + /// Episode name. + public TroubleshooterEpisode(Guid id, string name) + { + Id = id; + Name = name; + } + + /// + /// Gets the id. + /// + public Guid Id { get; private set; } + + /// + /// Gets the name. + /// + public string Name { get; private set; } = string.Empty; +} diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs index bf8c2de..952cc46 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs @@ -160,6 +160,7 @@ public class Entrypoint : IServerEntryPoint SeriesName = episode.SeriesName, SeasonNumber = episode.AiredSeasonNumber ?? 0, EpisodeId = episode.Id, + Name = episode.Name, Path = episode.Path, FingerprintDuration = Convert.ToInt32(duration) });