using System; using System.Net.Mime; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace ConfusedPolarBear.Plugin.IntroSkipper.Controllers; /// /// Skip intro controller. /// [Authorize] [ApiController] [Produces(MediaTypeNames.Application.Json)] public class SkipIntroController : ControllerBase { /// /// Constructor. /// public SkipIntroController() { } /// /// Returns the timestamps of the introduction in a television episode. /// /// ID of the episode. Required. /// Episode contains an intro. /// Failed to find an intro in the provided episode. [HttpGet("Episode/{id}/IntroTimestamps")] public ActionResult GetIntroTimestamps([FromRoute] Guid id) { if (!Plugin.Instance!.Intros.ContainsKey(id)) { return NotFound(); } var intro = Plugin.Instance!.Intros[id]; // Check that the episode was analyzed successfully. if (!intro.Valid) { return NotFound(); } // Populate the prompt show/hide times. var config = Plugin.Instance!.Configuration; intro.ShowSkipPromptAt = Math.Max(0, intro.IntroStart - config.ShowPromptAdjustment); intro.HideSkipPromptAt = intro.IntroStart + config.HidePromptAdjustment; return intro; } }