92 lines
2.7 KiB
C#
92 lines
2.7 KiB
C#
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using MediaBrowser.Controller.Library;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace ConfusedPolarBear.Plugin.IntroSkipper;
|
|
|
|
/// <summary>
|
|
/// Server entrypoint.
|
|
/// </summary>
|
|
public class Entrypoint : IHostedService
|
|
{
|
|
private readonly IUserManager _userManager;
|
|
private readonly IUserViewManager _userViewManager;
|
|
private readonly ILibraryManager _libraryManager;
|
|
private readonly ILogger<Entrypoint> _logger;
|
|
private readonly ILoggerFactory _loggerFactory;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="Entrypoint"/> class.
|
|
/// </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>
|
|
/// <param name="loggerFactory">Logger factory.</param>
|
|
public Entrypoint(
|
|
IUserManager userManager,
|
|
IUserViewManager userViewManager,
|
|
ILibraryManager libraryManager,
|
|
ILogger<Entrypoint> logger,
|
|
ILoggerFactory loggerFactory)
|
|
{
|
|
_userManager = userManager;
|
|
_userViewManager = userViewManager;
|
|
_libraryManager = libraryManager;
|
|
_logger = logger;
|
|
_loggerFactory = loggerFactory;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Dispose.
|
|
/// </summary>
|
|
public void Dispose()
|
|
{
|
|
Dispose(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Protected dispose.
|
|
/// </summary>
|
|
/// <param name="dispose">Dispose.</param>
|
|
protected virtual void Dispose(bool dispose)
|
|
{
|
|
if (!dispose)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public Task StartAsync(CancellationToken cancellationToken)
|
|
{
|
|
FFmpegWrapper.Logger = _logger;
|
|
|
|
// 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.
|
|
|
|
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<QueueManager>(), _libraryManager);
|
|
queueManager?.GetMediaItems();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError("Unable to run startup enqueue: {Exception}", ex);
|
|
}
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public Task StopAsync(CancellationToken cancellationToken)
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|