54 lines
1.6 KiB
C#
54 lines
1.6 KiB
C#
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using MediaBrowser.Controller.Library;
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
namespace Jellyfin.Plugin.Webhook.Notifiers.ItemAddedNotifier;
|
|
|
|
/// <summary>
|
|
/// Notifier when a library item is added.
|
|
/// </summary>
|
|
public class ItemAddedNotifierEntryPoint : IHostedService
|
|
{
|
|
private readonly IItemAddedManager _itemAddedManager;
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="ItemAddedNotifierEntryPoint"/> class.
|
|
/// </summary>
|
|
/// <param name="itemAddedManager">Instance of the <see cref="IItemAddedManager"/> interface.</param>
|
|
/// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
|
|
public ItemAddedNotifierEntryPoint(
|
|
IItemAddedManager itemAddedManager,
|
|
ILibraryManager libraryManager)
|
|
{
|
|
_itemAddedManager = itemAddedManager;
|
|
_libraryManager = libraryManager;
|
|
}
|
|
|
|
private void ItemAddedHandler(object? sender, ItemChangeEventArgs itemChangeEventArgs)
|
|
{
|
|
// Never notify on virtual items.
|
|
if (itemChangeEventArgs.Item.IsVirtualItem)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_itemAddedManager.AddItem(itemChangeEventArgs.Item);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public Task StartAsync(CancellationToken cancellationToken)
|
|
{
|
|
_libraryManager.ItemAdded += ItemAddedHandler;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public Task StopAsync(CancellationToken cancellationToken)
|
|
{
|
|
_libraryManager.ItemAdded -= ItemAddedHandler;
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|