simplify check for credits reaching end
This commit is contained in:
parent
b02403da84
commit
4b725aaaad
@ -37,8 +37,7 @@ namespace IntroSkipper.Manager
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var existingSegments = await _mediaSegmentManager.GetSegmentsAsync(episode.EpisodeId, null).ConfigureAwait(false);
|
var existingSegments = await _mediaSegmentManager.GetSegmentsAsync(episode.EpisodeId, null).ConfigureAwait(false);
|
||||||
var deleteTasks = existingSegments.Select(s => _mediaSegmentManager.DeleteSegmentAsync(s.Id));
|
await Task.WhenAll(existingSegments.Select(s => _mediaSegmentManager.DeleteSegmentAsync(s.Id))).ConfigureAwait(false);
|
||||||
await Task.WhenAll(deleteTasks).ConfigureAwait(false);
|
|
||||||
|
|
||||||
var newSegments = await _segmentProvider.GetMediaSegments(new MediaSegmentGenerationRequest { ItemId = episode.EpisodeId }, cancellationToken).ConfigureAwait(false);
|
var newSegments = await _segmentProvider.GetMediaSegments(new MediaSegmentGenerationRequest { ItemId = episode.EpisodeId }, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
@ -48,8 +47,7 @@ namespace IntroSkipper.Manager
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var createTasks = newSegments.Select(s => _mediaSegmentManager.CreateSegmentAsync(s, _name));
|
await Task.WhenAll(newSegments.Select(s => _mediaSegmentManager.CreateSegmentAsync(s, _name))).ConfigureAwait(false);
|
||||||
await Task.WhenAll(createTasks).ConfigureAwait(false);
|
|
||||||
|
|
||||||
_logger.LogDebug("Updated {SegmentCount} segments for episode {EpisodeId}", newSegments.Count, episode.EpisodeId);
|
_logger.LogDebug("Updated {SegmentCount} segments for episode {EpisodeId}", newSegments.Count, episode.EpisodeId);
|
||||||
}
|
}
|
||||||
|
@ -23,40 +23,30 @@ namespace IntroSkipper.Providers
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public Task<IReadOnlyList<MediaSegmentDto>> GetMediaSegments(MediaSegmentGenerationRequest request, CancellationToken cancellationToken)
|
public Task<IReadOnlyList<MediaSegmentDto>> GetMediaSegments(MediaSegmentGenerationRequest request, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(request);
|
|
||||||
|
|
||||||
var segments = new List<MediaSegmentDto>();
|
var segments = new List<MediaSegmentDto>();
|
||||||
var remainingTicks = TimeSpan.FromSeconds(Plugin.Instance?.Configuration.RemainingSecondsOfIntro ?? 2).Ticks;
|
var remainingTicks = (Plugin.Instance?.Configuration.RemainingSecondsOfIntro ?? 2) * TimeSpan.TicksPerSecond;
|
||||||
|
|
||||||
if (Plugin.Instance!.Intros.TryGetValue(request.ItemId, out var introValue) && introValue.Valid)
|
if (Plugin.Instance!.Intros.TryGetValue(request.ItemId, out var introValue))
|
||||||
{
|
{
|
||||||
segments.Add(new MediaSegmentDto
|
segments.Add(new MediaSegmentDto
|
||||||
{
|
{
|
||||||
StartTicks = TimeSpan.FromSeconds(introValue.Start).Ticks,
|
StartTicks = (long)(introValue.Start * TimeSpan.TicksPerSecond),
|
||||||
EndTicks = TimeSpan.FromSeconds(introValue.End).Ticks - remainingTicks,
|
EndTicks = (long)(introValue.End * TimeSpan.TicksPerSecond) - remainingTicks,
|
||||||
ItemId = request.ItemId,
|
ItemId = request.ItemId,
|
||||||
Type = MediaSegmentType.Intro
|
Type = MediaSegmentType.Intro
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Plugin.Instance!.Credits.TryGetValue(request.ItemId, out var creditValue) && creditValue.Valid)
|
if (Plugin.Instance!.Credits.TryGetValue(request.ItemId, out var creditValue))
|
||||||
{
|
{
|
||||||
var creditEndTicks = TimeSpan.FromSeconds(creditValue.End).Ticks;
|
var creditEndTicks = (long)(creditValue.End * TimeSpan.TicksPerSecond);
|
||||||
|
var runTimeTicks = Plugin.Instance.GetItem(request.ItemId)?.RunTimeTicks ?? long.MaxValue;
|
||||||
if (Plugin.Instance.GetItem(request.ItemId) is not null and var item &&
|
|
||||||
item.RunTimeTicks - TimeSpan.TicksPerSecond < creditEndTicks)
|
|
||||||
{
|
|
||||||
creditEndTicks = item.RunTimeTicks ?? creditEndTicks;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
creditEndTicks -= remainingTicks;
|
|
||||||
}
|
|
||||||
|
|
||||||
segments.Add(new MediaSegmentDto
|
segments.Add(new MediaSegmentDto
|
||||||
{
|
{
|
||||||
StartTicks = TimeSpan.FromSeconds(creditValue.Start).Ticks,
|
StartTicks = (long)(creditValue.Start * TimeSpan.TicksPerSecond),
|
||||||
EndTicks = creditEndTicks,
|
EndTicks = runTimeTicks > creditEndTicks + TimeSpan.TicksPerSecond
|
||||||
|
? creditEndTicks - remainingTicks
|
||||||
|
: runTimeTicks,
|
||||||
ItemId = request.ItemId,
|
ItemId = request.ItemId,
|
||||||
Type = MediaSegmentType.Outro
|
Type = MediaSegmentType.Outro
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user