53 lines
1.5 KiB
C#
Raw Normal View History

2022-05-01 00:33:22 -05:00
using System;
using System.Net.Mime;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace ConfusedPolarBear.Plugin.IntroSkipper.Controllers;
/// <summary>
/// Skip intro controller.
/// </summary>
[Authorize]
[ApiController]
[Produces(MediaTypeNames.Application.Json)]
public class SkipIntroController : ControllerBase
{
/// <summary>
/// Constructor.
/// </summary>
public SkipIntroController()
{
}
/// <summary>
/// Returns the timestamps of the introduction in a television episode.
/// </summary>
2022-05-01 01:24:57 -05:00
/// <param name="id">ID of the episode. Required.</param>
2022-05-01 00:33:22 -05:00
/// <response code="200">Episode contains an intro.</response>
/// <response code="404">Failed to find an intro in the provided episode.</response>
[HttpGet("Episode/{id}/IntroTimestamps")]
2022-05-01 01:24:57 -05:00
public ActionResult<Intro> GetIntroTimestamps([FromRoute] Guid id)
2022-05-01 00:33:22 -05:00
{
2022-05-01 01:24:57 -05:00
if (!Plugin.Instance!.Intros.ContainsKey(id))
2022-05-01 00:33:22 -05:00
{
return NotFound();
}
2022-05-01 01:24:57 -05:00
var intro = Plugin.Instance!.Intros[id];
2022-05-01 00:33:22 -05:00
// 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;
2022-05-01 00:33:22 -05:00
return intro;
}
}