109 lines
3.0 KiB
C#
Raw Normal View History

2022-05-01 00:33:22 -05:00
using System;
2024-04-20 12:58:29 +02:00
using System.Globalization;
2022-08-25 22:11:39 -05:00
using System.Text.Json.Serialization;
2022-05-01 00:33:22 -05:00
2024-08-31 18:56:48 +02:00
namespace ConfusedPolarBear.Plugin.IntroSkipper.Data;
2022-05-01 00:33:22 -05:00
/// <summary>
/// Result of fingerprinting and analyzing two episodes in a season.
/// All times are measured in seconds relative to the beginning of the media file.
/// </summary>
public class Intro
{
2022-05-13 01:13:13 -05:00
/// <summary>
/// Initializes a new instance of the <see cref="Intro"/> class.
/// </summary>
/// <param name="episode">Episode.</param>
2022-05-16 23:08:20 -05:00
/// <param name="intro">Introduction time range.</param>
public Intro(Guid episode, TimeRange intro)
2022-05-13 01:13:13 -05:00
{
EpisodeId = episode;
2022-05-16 23:08:20 -05:00
IntroStart = intro.Start;
IntroEnd = intro.End;
}
/// <summary>
/// Initializes a new instance of the <see cref="Intro"/> class.
/// </summary>
/// <param name="episode">Episode.</param>
public Intro(Guid episode)
{
EpisodeId = episode;
IntroStart = 0;
IntroEnd = 0;
2022-05-13 01:13:13 -05:00
}
/// <summary>
/// Initializes a new instance of the <see cref="Intro"/> class.
/// </summary>
/// <param name="intro">intro.</param>
public Intro(Intro intro)
{
EpisodeId = intro.EpisodeId;
IntroStart = intro.IntroStart;
IntroEnd = intro.IntroEnd;
}
/// <summary>
2022-05-13 01:13:13 -05:00
/// Initializes a new instance of the <see cref="Intro"/> class.
/// </summary>
public Intro()
{
}
2022-05-01 01:24:57 -05:00
/// <summary>
/// Gets or sets the Episode ID.
2022-05-01 01:24:57 -05:00
/// </summary>
public Guid EpisodeId { get; set; }
2022-05-01 00:33:22 -05:00
/// <summary>
2022-05-13 01:13:13 -05:00
/// Gets a value indicating whether this introduction is valid or not.
/// Invalid results must not be returned through the API.
2022-05-01 00:33:22 -05:00
/// </summary>
2022-05-13 01:13:13 -05:00
public bool Valid => IntroEnd > 0;
2022-05-01 00:33:22 -05:00
2022-08-25 22:11:39 -05:00
/// <summary>
/// Gets the duration of this intro.
/// </summary>
[JsonIgnore]
public double Duration => IntroEnd - IntroStart;
2022-05-01 00:33:22 -05:00
/// <summary>
/// Gets or sets the introduction sequence start time.
2022-05-01 00:33:22 -05:00
/// </summary>
public double IntroStart { get; set; }
/// <summary>
/// Gets or sets the introduction sequence end time.
2022-05-01 00:33:22 -05:00
/// </summary>
public double IntroEnd { get; set; }
/// <summary>
/// Gets or sets the recommended time to display the skip intro prompt.
2022-05-01 00:33:22 -05:00
/// </summary>
public double ShowSkipPromptAt { get; set; }
/// <summary>
/// Gets or sets the recommended time to hide the skip intro prompt.
2022-05-01 00:33:22 -05:00
/// </summary>
public double HideSkipPromptAt { get; set; }
/// <summary>
/// Convert this Intro object to a Kodi compatible EDL entry.
/// </summary>
/// <param name="action">User specified configuration EDL action.</param>
/// <returns>String.</returns>
public string ToEdl(EdlAction action)
{
if (action == EdlAction.None)
{
throw new ArgumentException("Cannot serialize an EdlAction of None");
}
var start = Math.Round(IntroStart, 2);
var end = Math.Round(IntroEnd, 2);
2024-04-20 12:58:29 +02:00
return string.Format(CultureInfo.InvariantCulture, "{0} {1} {2}", start, end, (int)action);
}
2022-05-01 00:33:22 -05:00
}