Skip to content

Commit

Permalink
Clean up the copy pasta explosion
Browse files Browse the repository at this point in the history
  • Loading branch information
AbandonedCart committed Apr 13, 2024
1 parent 0a9394b commit 177604e
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions ConfusedPolarBear.Plugin.IntroSkipper/AutoSkipCredits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
namespace ConfusedPolarBear.Plugin.IntroSkipper;

/// <summary>
/// Automatically skip past introduction sequences.
/// Commands clients to seek to the end of the intro as soon as they start playing it.
/// Automatically skip past credit sequences.
/// Commands clients to seek to the end of the credits as soon as they start playing it.
/// </summary>
public class AutoSkipCredits : IServerEntryPoint
{
Expand Down Expand Up @@ -45,7 +45,7 @@ public class AutoSkipCredits : IServerEntryPoint
}

/// <summary>
/// If introduction auto skipping is enabled, set it up.
/// If credits auto skipping is enabled, set it up.
/// </summary>
/// <returns>Task.</returns>
public Task RunAsync()
Expand Down Expand Up @@ -136,27 +136,27 @@ private void PlaybackTimer_Elapsed(object? sender, ElapsedEventArgs e)
}
}

// Assert that a credit was detected for this item.
if (!Plugin.Instance!.Credits.TryGetValue(itemId, out var intro) || !intro.Valid)
// Assert that credits were detected for this item.
if (!Plugin.Instance!.Credits.TryGetValue(itemId, out var credit) || !credit.Valid)
{
continue;
}

// Seek is unreliable if called at the very start of an episode.
var adjustedStart = Math.Max(5, intro.IntroStart);
var adjustedStart = Math.Max(5, credit.IntroStart);

_logger.LogTrace(
"Playback position is {Position}, intro runs from {Start} to {End}",
"Playback position is {Position}, credits run from {Start} to {End}",
position,
adjustedStart,
intro.IntroEnd);
credit.IntroEnd);

if (position < adjustedStart || position > intro.IntroEnd)
if (position < adjustedStart || position > credit.IntroEnd)
{
continue;
}

// Notify the user that an introduction is being skipped for them.
// Notify the user that credits are being skipped for them.
var notificationText = Plugin.Instance!.Configuration.AutoSkipCreditsNotificationText;
if (!string.IsNullOrWhiteSpace(notificationText))
{
Expand All @@ -174,7 +174,7 @@ private void PlaybackTimer_Elapsed(object? sender, ElapsedEventArgs e)

_logger.LogDebug("Sending seek command to {Session}", deviceId);

var introEnd = (long)intro.IntroEnd;
var creditEnd = (long)credit.IntroEnd;

_sessionManager.SendPlaystateCommand(
session.Id,
Expand All @@ -183,7 +183,7 @@ private void PlaybackTimer_Elapsed(object? sender, ElapsedEventArgs e)
{
Command = PlaystateCommand.Seek,
ControllingUserId = session.UserId.ToString("N"),
SeekPositionTicks = introEnd * TimeSpan.TicksPerSecond,
SeekPositionTicks = creditEnd * TimeSpan.TicksPerSecond,
},
CancellationToken.None);

Expand Down

0 comments on commit 177604e

Please sign in to comment.