diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/AutoSkip.cs b/ConfusedPolarBear.Plugin.IntroSkipper/AutoSkip.cs index ab441e9..adf5334 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/AutoSkip.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/AutoSkip.cs @@ -1,10 +1,10 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading; using System.Threading.Tasks; using System.Timers; using ConfusedPolarBear.Plugin.IntroSkipper.Configuration; -using ConfusedPolarBear.Plugin.IntroSkipper.Data; using MediaBrowser.Common.Extensions; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Session; @@ -21,32 +21,25 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper; /// Automatically skip past introduction sequences. /// Commands clients to seek to the end of the intro as soon as they start playing it. /// -public class AutoSkip : IHostedService, IDisposable +/// +/// Initializes a new instance of the class. +/// +/// User data manager. +/// Session manager. +/// Logger. +public class AutoSkip( + IUserDataManager userDataManager, + ISessionManager sessionManager, + ILogger logger) : IHostedService, IDisposable { private readonly object _sentSeekCommandLock = new(); - private ILogger _logger; - private IUserDataManager _userDataManager; - private ISessionManager _sessionManager; + private ILogger _logger = logger; + private IUserDataManager _userDataManager = userDataManager; + private ISessionManager _sessionManager = sessionManager; private Timer _playbackTimer = new(1000); - private Dictionary _sentSeekCommand; - - /// - /// Initializes a new instance of the class. - /// - /// User data manager. - /// Session manager. - /// Logger. - public AutoSkip( - IUserDataManager userDataManager, - ISessionManager sessionManager, - ILogger logger) - { - _userDataManager = userDataManager; - _sessionManager = sessionManager; - _logger = logger; - _sentSeekCommand = new Dictionary(); - } + private Dictionary _sentSeekCommand = []; + private HashSet _clientList = []; private void AutoSkipChanged(object? sender, BasePluginConfiguration e) { @@ -54,6 +47,7 @@ public class AutoSkip : IHostedService, IDisposable var newState = configuration.AutoSkip; _logger.LogDebug("Setting playback timer enabled to {NewState}", newState); _playbackTimer.Enabled = newState; + _clientList = [.. configuration.ClientList.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)]; } private void UserDataManager_UserDataSaved(object? sender, UserDataSaveEventArgs e) @@ -111,19 +105,8 @@ public class AutoSkip : IHostedService, IDisposable private void PlaybackTimer_Elapsed(object? sender, ElapsedEventArgs e) { - foreach (var session in _sessionManager.Sessions) + foreach (var session in _sessionManager.Sessions.Where(s => _clientList.Contains(s.Client, StringComparer.OrdinalIgnoreCase))) { - if (WarningManager.HasFlag(PluginWarning.UnableToAddSkipButton)) - { - _logger.LogTrace("using autoskip to skip the intro because the injection of the skip button failed"); - } - - // only need for official Android TV App and jellyfin-kodi - else if (session.Client != "Android TV" && session.Client != "Kodi") - { - continue; - } - var deviceId = session.DeviceId; var itemId = session.NowPlayingItem.Id; var position = session.PlayState.PositionTicks / TimeSpan.TicksPerSecond; diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/AutoSkipCredits.cs b/ConfusedPolarBear.Plugin.IntroSkipper/AutoSkipCredits.cs index f7a7720..a4b1d7d 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/AutoSkipCredits.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/AutoSkipCredits.cs @@ -1,10 +1,10 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading; using System.Threading.Tasks; using System.Timers; using ConfusedPolarBear.Plugin.IntroSkipper.Configuration; -using ConfusedPolarBear.Plugin.IntroSkipper.Data; using MediaBrowser.Common.Extensions; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Session; @@ -21,32 +21,25 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper; /// Automatically skip past credit sequences. /// Commands clients to seek to the end of the credits as soon as they start playing it. /// -public class AutoSkipCredits : IHostedService, IDisposable +/// +/// Initializes a new instance of the class. +/// +/// User data manager. +/// Session manager. +/// Logger. +public class AutoSkipCredits( + IUserDataManager userDataManager, + ISessionManager sessionManager, + ILogger logger) : IHostedService, IDisposable { private readonly object _sentSeekCommandLock = new(); - private ILogger _logger; - private IUserDataManager _userDataManager; - private ISessionManager _sessionManager; + private ILogger _logger = logger; + private IUserDataManager _userDataManager = userDataManager; + private ISessionManager _sessionManager = sessionManager; private Timer _playbackTimer = new(1000); - private Dictionary _sentSeekCommand; - - /// - /// Initializes a new instance of the class. - /// - /// User data manager. - /// Session manager. - /// Logger. - public AutoSkipCredits( - IUserDataManager userDataManager, - ISessionManager sessionManager, - ILogger logger) - { - _userDataManager = userDataManager; - _sessionManager = sessionManager; - _logger = logger; - _sentSeekCommand = new Dictionary(); - } + private Dictionary _sentSeekCommand = []; + private HashSet _clientList = []; private void AutoSkipCreditChanged(object? sender, BasePluginConfiguration e) { @@ -54,6 +47,7 @@ public class AutoSkipCredits : IHostedService, IDisposable var newState = configuration.AutoSkipCredits; _logger.LogDebug("Setting playback timer enabled to {NewState}", newState); _playbackTimer.Enabled = newState; + _clientList = [.. configuration.ClientList.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)]; } private void UserDataManager_UserDataSaved(object? sender, UserDataSaveEventArgs e) @@ -111,19 +105,8 @@ public class AutoSkipCredits : IHostedService, IDisposable private void PlaybackTimer_Elapsed(object? sender, ElapsedEventArgs e) { - foreach (var session in _sessionManager.Sessions) + foreach (var session in _sessionManager.Sessions.Where(s => _clientList.Contains(s.Client, StringComparer.OrdinalIgnoreCase))) { - if (WarningManager.HasFlag(PluginWarning.UnableToAddSkipButton)) - { - _logger.LogTrace("using autoskip to skip the credits because the injection of the skip button failed"); - } - - // only need for official Android TV App and jellyfin-kodi - else if (session.Client != "Android TV" && session.Client != "Kodi") - { - continue; - } - var deviceId = session.DeviceId; var itemId = session.NowPlayingItem.Id; var position = session.PlayState.PositionTicks / TimeSpan.TicksPerSecond; diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/PluginConfiguration.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/PluginConfiguration.cs index cdd6d5e..f6face2 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/PluginConfiguration.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/PluginConfiguration.cs @@ -29,6 +29,11 @@ public class PluginConfiguration : BasePluginConfiguration /// public string SelectedLibraries { get; set; } = string.Empty; + /// + /// Gets or sets the list of client to auto skip for. + /// + public string ClientList { get; set; } = "Android TV, Kodi"; + /// /// Gets or sets a value indicating whether to scan for intros during a scheduled task. /// diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html index 12302e3..1501fbf 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html @@ -398,6 +398,14 @@
+
+ Auto Skip Client List +
+
+ + +
+