From ef95f3ec25d0ac0de948efcf520ea92740240587 Mon Sep 17 00:00:00 2001 From: rlauuzo <46294892+rlauuzo@users.noreply.github.com> Date: Wed, 10 Apr 2024 15:13:37 +0200 Subject: [PATCH] Update Entrypoint.cs (#107) * Update Entrypoint.cs * Update Entrypoint.cs --- .../Entrypoint.cs | 63 ++++++++++--------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs index a25f555..66a4d48 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs @@ -15,7 +15,7 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper; /// /// Server entrypoint. /// -public class Entrypoint : IHostedService +public class Entrypoint : IHostedService, IDisposable { private readonly IUserManager _userManager; private readonly IUserViewManager _userViewManager; @@ -57,6 +57,36 @@ public class Entrypoint : IHostedService Timeout.InfiniteTimeSpan); } + /// + public Task StartAsync(CancellationToken cancellationToken) + { + _libraryManager.ItemAdded += OnItemAdded; + _libraryManager.ItemUpdated += OnItemModified; + _taskManager.TaskCompleted += OnLibraryRefresh; + + FFmpegWrapper.Logger = _logger; + + try + { + // Enqueue all episodes at startup to ensure any FFmpeg errors appear as early as possible + _logger.LogInformation("Running startup enqueue"); + var queueManager = new QueueManager(_loggerFactory.CreateLogger(), _libraryManager); + queueManager?.GetMediaItems(); + } + catch (Exception ex) + { + _logger.LogError("Unable to run startup enqueue: {Exception}", ex); + } + + return Task.CompletedTask; + } + + /// + public Task StopAsync(CancellationToken cancellationToken) + { + return Task.CompletedTask; + } + // Disclose source for inspiration // Implementation based on the principles of jellyfin-plugin-media-analyzer: // https://github.com/endrl/jellyfin-plugin-media-analyzer @@ -242,6 +272,7 @@ public class Entrypoint : IHostedService public void Dispose() { Dispose(true); + GC.SuppressFinalize(this); } /// @@ -261,34 +292,4 @@ public class Entrypoint : IHostedService return; } } - - /// - public Task StartAsync(CancellationToken cancellationToken) - { - _libraryManager.ItemAdded += OnItemAdded; - _libraryManager.ItemUpdated += OnItemModified; - _taskManager.TaskCompleted += OnLibraryRefresh; - - FFmpegWrapper.Logger = _logger; - - try - { - // Enqueue all episodes at startup to ensure any FFmpeg errors appear as early as possible - _logger.LogInformation("Running startup enqueue"); - var queueManager = new QueueManager(_loggerFactory.CreateLogger(), _libraryManager); - queueManager?.GetMediaItems(); - } - catch (Exception ex) - { - _logger.LogError("Unable to run startup enqueue: {Exception}", ex); - } - - return Task.CompletedTask; - } - - /// - public Task StopAsync(CancellationToken cancellationToken) - { - return Task.CompletedTask; - } }