Rework fingerprint visualizer backend
This commit is contained in:
parent
715eea743f
commit
c72d8bafdf
@ -105,7 +105,7 @@
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<details>
|
||||
<details id="visualizer">
|
||||
<summary>Fingerprint Visualizer</summary>
|
||||
|
||||
<p>
|
||||
@ -178,6 +178,7 @@
|
||||
var shows = {};
|
||||
|
||||
// ui elements
|
||||
var visualizer = document.querySelector("details#visualizer");
|
||||
var canvas = document.querySelector("canvas#troubleshooter");
|
||||
var selectShow = document.querySelector("select#troubleshooterShow");
|
||||
var selectSeason = document.querySelector("select#troubleshooterSeason");
|
||||
@ -188,8 +189,14 @@
|
||||
var btnEraseTimestamps = document.querySelector("button#btnEraseTimestamps");
|
||||
var windowHashInterval = 0;
|
||||
|
||||
// config page loaded, populate show names
|
||||
async function onLoad() {
|
||||
// when the fingerprint visualizer opens, populate show names
|
||||
async function visualizerToggled() {
|
||||
if (!visualizer.open) {
|
||||
return;
|
||||
}
|
||||
|
||||
Dashboard.showLoadingMsg();
|
||||
|
||||
shows = await getJson("Intros/Shows");
|
||||
|
||||
var sorted = [];
|
||||
@ -201,6 +208,8 @@
|
||||
}
|
||||
|
||||
selectShow.value = "";
|
||||
|
||||
Dashboard.hideLoadingMsg();
|
||||
}
|
||||
|
||||
// show changed, populate seasons
|
||||
@ -480,6 +489,7 @@
|
||||
return false;
|
||||
});
|
||||
|
||||
visualizer.addEventListener("toggle", visualizerToggled);
|
||||
txtOffset.addEventListener("change", renderTroubleshooter);
|
||||
selectShow.addEventListener("change", showChanged);
|
||||
selectSeason.addEventListener("change", seasonChanged);
|
||||
@ -540,9 +550,6 @@
|
||||
timeContainer.style.left = "25px";
|
||||
timeContainer.style.top = (-1 * rect.height + y).toString() + "px";
|
||||
});
|
||||
|
||||
// TODO: fix
|
||||
setTimeout(onLoad, 250);
|
||||
</script>
|
||||
|
||||
<script>
|
||||
|
@ -5,6 +5,7 @@ using System.Globalization;
|
||||
using System.Net.Mime;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ConfusedPolarBear.Plugin.IntroSkipper.Controllers;
|
||||
|
||||
@ -17,11 +18,15 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper.Controllers;
|
||||
[Route("Intros")]
|
||||
public class VisualizationController : ControllerBase
|
||||
{
|
||||
private readonly ILogger<VisualizationController> _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="VisualizationController"/> class.
|
||||
/// </summary>
|
||||
public VisualizationController()
|
||||
/// <param name="logger">Logger.</param>
|
||||
public VisualizationController(ILogger<VisualizationController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -31,23 +36,36 @@ public class VisualizationController : ControllerBase
|
||||
[HttpGet("Shows")]
|
||||
public ActionResult<Dictionary<string, HashSet<string>>> GetShowSeasons()
|
||||
{
|
||||
_logger.LogDebug("Returning season names by series");
|
||||
|
||||
var showSeasons = new Dictionary<string, HashSet<string>>();
|
||||
|
||||
// Loop through all episodes in the analysis queue
|
||||
foreach (var episodes in Plugin.Instance!.AnalysisQueue)
|
||||
// Loop through all seasons in the analysis queue
|
||||
foreach (var kvp in Plugin.Instance!.AnalysisQueue)
|
||||
{
|
||||
foreach (var episode in episodes.Value)
|
||||
// Check that this season contains at least one episode.
|
||||
var episodes = kvp.Value;
|
||||
if (episodes is null || episodes.Count == 0)
|
||||
{
|
||||
// Add each season's name to the series hashset
|
||||
var series = episode.SeriesName;
|
||||
|
||||
if (!showSeasons.ContainsKey(series))
|
||||
{
|
||||
showSeasons[series] = new HashSet<string>();
|
||||
}
|
||||
|
||||
showSeasons[series].Add(GetSeasonName(episode));
|
||||
_logger.LogDebug("Skipping season {Id} (null or empty)", kvp.Key);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Peek at the top episode from this season and store the series name and season number.
|
||||
var first = episodes[0];
|
||||
var series = first.SeriesName;
|
||||
var season = GetSeasonName(first);
|
||||
|
||||
// Validate the series and season before attempting to store it.
|
||||
if (string.IsNullOrWhiteSpace(series) || string.IsNullOrWhiteSpace(season))
|
||||
{
|
||||
_logger.LogDebug("Skipping season {Id} (no name or number)", kvp.Key);
|
||||
continue;
|
||||
}
|
||||
|
||||
// TryAdd is used when adding the HashSet since it is a no-op if one was already created for this series.
|
||||
showSeasons.TryAdd(series, new HashSet<string>());
|
||||
showSeasons[series].Add(season);
|
||||
}
|
||||
|
||||
return showSeasons;
|
||||
|
Loading…
x
Reference in New Issue
Block a user