90 lines
2.6 KiB
C#
Raw Normal View History

2022-05-01 00:33:22 -05:00
using System;
2022-06-12 16:57:15 -05:00
using System.IO;
2022-05-01 00:33:22 -05:00
using System.Threading.Tasks;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Plugins;
using Microsoft.Extensions.Logging;
namespace ConfusedPolarBear.Plugin.IntroSkipper;
/// <summary>
/// Server entrypoint.
/// </summary>
public class Entrypoint : IServerEntryPoint
{
private readonly IUserManager _userManager;
private readonly IUserViewManager _userViewManager;
private readonly ILibraryManager _libraryManager;
private readonly ILogger<Entrypoint> _logger;
2022-06-22 22:03:34 -05:00
private readonly ILoggerFactory _loggerFactory;
2022-05-01 00:33:22 -05:00
/// <summary>
/// Initializes a new instance of the <see cref="Entrypoint"/> class.
2022-05-01 00:33:22 -05:00
/// </summary>
/// <param name="userManager">User manager.</param>
/// <param name="userViewManager">User view manager.</param>
/// <param name="libraryManager">Library manager.</param>
/// <param name="logger">Logger.</param>
2022-06-22 22:03:34 -05:00
/// <param name="loggerFactory">Logger factory.</param>
2022-05-01 00:33:22 -05:00
public Entrypoint(
IUserManager userManager,
IUserViewManager userViewManager,
ILibraryManager libraryManager,
2022-06-22 22:03:34 -05:00
ILogger<Entrypoint> logger,
ILoggerFactory loggerFactory)
2022-05-01 00:33:22 -05:00
{
_userManager = userManager;
_userViewManager = userViewManager;
_libraryManager = libraryManager;
_logger = logger;
2022-06-22 22:03:34 -05:00
_loggerFactory = loggerFactory;
2022-05-01 00:33:22 -05:00
}
/// <summary>
/// Registers event handler.
/// </summary>
/// <returns>Task.</returns>
2022-05-01 00:33:22 -05:00
public Task RunAsync()
{
2022-08-28 22:35:43 -05:00
FFmpegWrapper.Logger = _logger;
2022-05-01 00:33:22 -05:00
2022-06-22 22:03:34 -05:00
// TODO: when a new item is added to the server, immediately analyze the season it belongs to
// instead of waiting for the next task interval. The task start should be debounced by a few seconds.
2022-05-01 00:33:22 -05:00
try
{
// Enqueue all episodes at startup to ensure any FFmpeg errors appear as early as possible
2022-06-22 22:03:34 -05:00
_logger.LogInformation("Running startup enqueue");
var queueManager = new QueueManager(_loggerFactory.CreateLogger<QueueManager>(), _libraryManager);
queueManager.GetMediaItems();
}
catch (Exception ex)
{
_logger.LogError("Unable to run startup enqueue: {Exception}", ex);
2022-05-01 00:33:22 -05:00
}
return Task.CompletedTask;
}
/// <summary>
/// Dispose.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
2022-05-09 22:56:03 -05:00
/// Protected dispose.
2022-05-01 00:33:22 -05:00
/// </summary>
2022-05-09 22:56:03 -05:00
/// <param name="dispose">Dispose.</param>
2022-05-01 00:33:22 -05:00
protected virtual void Dispose(bool dispose)
{
if (!dispose)
{
return;
}
}
}