From ae16603aeedddf1d586660ce0540d1fe753b7aef Mon Sep 17 00:00:00 2001
From: ConfusedPolarBear <33811686+ConfusedPolarBear@users.noreply.github.com>
Date: Fri, 25 Nov 2022 00:40:02 -0600
Subject: [PATCH] Support returning credit timestamps
---
.../Controllers/SkipIntroController.cs | 27 ++++++++++++++-----
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/SkipIntroController.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/SkipIntroController.cs
index b4631b7..85b9804 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/SkipIntroController.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/SkipIntroController.cs
@@ -26,14 +26,17 @@ public SkipIntroController()
/// Returns the timestamps of the introduction in a television episode. Responses are in API version 1 format.
///
/// ID of the episode. Required.
+ /// Timestamps to return. Optional. Defaults to Introduction for backwards compatibility.
/// Episode contains an intro.
/// Failed to find an intro in the provided episode.
/// Detected intro.
[HttpGet("Episode/{id}/IntroTimestamps")]
[HttpGet("Episode/{id}/IntroTimestamps/v1")]
- public ActionResult GetIntroTimestamps([FromRoute] Guid id)
+ public ActionResult GetIntroTimestamps(
+ [FromRoute] Guid id,
+ [FromQuery] AnalysisMode mode = AnalysisMode.Introduction)
{
- var intro = GetIntro(id);
+ var intro = GetIntro(id, mode);
if (intro is null || !intro.Valid)
{
@@ -49,13 +52,25 @@ public ActionResult GetIntroTimestamps([FromRoute] Guid id)
return intro;
}
- /// Lookup and return the intro timestamps for the provided item.
+ /// Lookup and return the skippable timestamps for the provided item.
/// Unique identifier of this episode.
+ /// Mode.
/// Intro object if the provided item has an intro, null otherwise.
- private Intro? GetIntro(Guid id)
+ private Intro? GetIntro(Guid id, AnalysisMode mode)
{
- // Returns a copy to avoid mutating the original Intro object stored in the dictionary.
- return Plugin.Instance!.Intros.TryGetValue(id, out var intro) ? new Intro(intro) : null;
+ try
+ {
+ var timestamp = mode == AnalysisMode.Introduction ?
+ Plugin.Instance!.Intros[id] :
+ Plugin.Instance!.Credits[id];
+
+ // A copy is returned to avoid mutating the original Intro object stored in the dictionary.
+ return new(timestamp);
+ }
+ catch (KeyNotFoundException)
+ {
+ return null;
+ }
}
///