diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Providers/SegmentProvider.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Providers/SegmentProvider.cs
index 74b4805..8e28345 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/Providers/SegmentProvider.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/Providers/SegmentProvider.cs
@@ -5,6 +5,8 @@ using System.Threading.Tasks;
using Jellyfin.Data.Enums;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Entities.Movies;
+using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Model;
using MediaBrowser.Model.MediaSegments;
@@ -15,54 +17,55 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper.Providers
///
public class SegmentProvider : IMediaSegmentProvider
{
- private static long RemainingTicks => TimeSpan.FromSeconds(Plugin.Instance?.Configuration.RemainingSecondsOfIntro ?? 2).Ticks;
-
///
public string Name => Plugin.Instance!.Name;
///
public Task> GetMediaSegments(MediaSegmentGenerationRequest request, CancellationToken cancellationToken)
{
- var segments = new List();
+ ArgumentNullException.ThrowIfNull(request);
- if (Plugin.Instance!.Intros.TryGetValue(request.ItemId, out var introValue))
+ var segments = new List();
+ var remainingTicks = TimeSpan.FromSeconds(Plugin.Instance?.Configuration.RemainingSecondsOfIntro ?? 2).Ticks;
+
+ if (Plugin.Instance!.Intros.TryGetValue(request.ItemId, out var introValue) && introValue.Valid)
{
segments.Add(new MediaSegmentDto
{
StartTicks = TimeSpan.FromSeconds(introValue.Start).Ticks,
- EndTicks = TimeSpan.FromSeconds(introValue.End).Ticks - RemainingTicks,
+ EndTicks = TimeSpan.FromSeconds(introValue.End).Ticks - remainingTicks,
ItemId = request.ItemId,
Type = MediaSegmentType.Intro
});
}
- if (Plugin.Instance!.Credits.TryGetValue(request.ItemId, out var creditValue))
+ if (Plugin.Instance!.Credits.TryGetValue(request.ItemId, out var creditValue) && creditValue.Valid)
{
- var outroSegment = new MediaSegmentDto
- {
- StartTicks = TimeSpan.FromSeconds(creditValue.Start).Ticks,
- ItemId = request.ItemId,
- Type = MediaSegmentType.Outro
- };
-
var creditEndTicks = TimeSpan.FromSeconds(creditValue.End).Ticks;
- if (Plugin.Instance.GetItem(request.ItemId) is IHasMediaSources item && creditEndTicks >= item.RunTimeTicks - TimeSpan.TicksPerSecond)
+ if (Plugin.Instance.GetItem(request.ItemId) is not null and var item &&
+ item.RunTimeTicks - TimeSpan.TicksPerSecond < creditEndTicks)
{
- outroSegment.EndTicks = item.RunTimeTicks ?? creditEndTicks;
+ creditEndTicks = item.RunTimeTicks ?? creditEndTicks;
}
else
{
- outroSegment.EndTicks = creditEndTicks - RemainingTicks;
+ creditEndTicks -= remainingTicks;
}
- segments.Add(outroSegment);
+ segments.Add(new MediaSegmentDto
+ {
+ StartTicks = TimeSpan.FromSeconds(creditValue.Start).Ticks,
+ EndTicks = creditEndTicks,
+ ItemId = request.ItemId,
+ Type = MediaSegmentType.Outro
+ });
}
return Task.FromResult>(segments);
}
///
- public ValueTask Supports(BaseItem item) => ValueTask.FromResult(item is IHasMediaSources);
+ public ValueTask Supports(BaseItem item) => ValueTask.FromResult(item is Episode or Movie);
}
}