Clean up the copy pasta explosion

This commit is contained in:
TwistedUmbrellaX 2024-04-13 12:35:43 -04:00
parent 0a9394b244
commit 177604e391

View File

@ -14,8 +14,8 @@ using Microsoft.Extensions.Logging;
namespace ConfusedPolarBear.Plugin.IntroSkipper; namespace ConfusedPolarBear.Plugin.IntroSkipper;
/// <summary> /// <summary>
/// Automatically skip past introduction sequences. /// Automatically skip past credit sequences.
/// Commands clients to seek to the end of the intro as soon as they start playing it. /// Commands clients to seek to the end of the credits as soon as they start playing it.
/// </summary> /// </summary>
public class AutoSkipCredits : IServerEntryPoint public class AutoSkipCredits : IServerEntryPoint
{ {
@ -45,7 +45,7 @@ public class AutoSkipCredits : IServerEntryPoint
} }
/// <summary> /// <summary>
/// If introduction auto skipping is enabled, set it up. /// If credits auto skipping is enabled, set it up.
/// </summary> /// </summary>
/// <returns>Task.</returns> /// <returns>Task.</returns>
public Task RunAsync() public Task RunAsync()
@ -136,27 +136,27 @@ public class AutoSkipCredits : IServerEntryPoint
} }
} }
// Assert that a credit was detected for this item. // Assert that credits were detected for this item.
if (!Plugin.Instance!.Credits.TryGetValue(itemId, out var intro) || !intro.Valid) if (!Plugin.Instance!.Credits.TryGetValue(itemId, out var credit) || !credit.Valid)
{ {
continue; continue;
} }
// Seek is unreliable if called at the very start of an episode. // 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( _logger.LogTrace(
"Playback position is {Position}, intro runs from {Start} to {End}", "Playback position is {Position}, credits run from {Start} to {End}",
position, position,
adjustedStart, adjustedStart,
intro.IntroEnd); credit.IntroEnd);
if (position < adjustedStart || position > intro.IntroEnd) if (position < adjustedStart || position > credit.IntroEnd)
{ {
continue; 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; var notificationText = Plugin.Instance!.Configuration.AutoSkipCreditsNotificationText;
if (!string.IsNullOrWhiteSpace(notificationText)) if (!string.IsNullOrWhiteSpace(notificationText))
{ {
@ -174,7 +174,7 @@ public class AutoSkipCredits : IServerEntryPoint
_logger.LogDebug("Sending seek command to {Session}", deviceId); _logger.LogDebug("Sending seek command to {Session}", deviceId);
var introEnd = (long)intro.IntroEnd; var creditEnd = (long)credit.IntroEnd;
_sessionManager.SendPlaystateCommand( _sessionManager.SendPlaystateCommand(
session.Id, session.Id,
@ -183,7 +183,7 @@ public class AutoSkipCredits : IServerEntryPoint
{ {
Command = PlaystateCommand.Seek, Command = PlaystateCommand.Seek,
ControllingUserId = session.UserId.ToString("N"), ControllingUserId = session.UserId.ToString("N"),
SeekPositionTicks = introEnd * TimeSpan.TicksPerSecond, SeekPositionTicks = creditEnd * TimeSpan.TicksPerSecond,
}, },
CancellationToken.None); CancellationToken.None);