|
|
|
@ -13,19 +13,19 @@ using MediaBrowser.Controller.Configuration;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Controller.Plugins;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
using MediaBrowser.Controller.Session;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Session;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
namespace Emby.Server.Implementations.EntryPoints;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A <see cref="IServerEntryPoint"/> that notifies users when libraries are updated.
|
|
|
|
|
/// A <see cref="IHostedService"/> responsible for notifying users when libraries are updated.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class LibraryChangedNotifier : IServerEntryPoint
|
|
|
|
|
public sealed class LibraryChangedNotifier : IHostedService, IDisposable
|
|
|
|
|
{
|
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
|
private readonly IServerConfigurationManager _configurationManager;
|
|
|
|
@ -70,7 +70,7 @@ public sealed class LibraryChangedNotifier : IServerEntryPoint
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public Task RunAsync()
|
|
|
|
|
public Task StartAsync(CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
_libraryManager.ItemAdded += OnLibraryItemAdded;
|
|
|
|
|
_libraryManager.ItemUpdated += OnLibraryItemUpdated;
|
|
|
|
@ -83,6 +83,20 @@ public sealed class LibraryChangedNotifier : IServerEntryPoint
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
_libraryManager.ItemAdded -= OnLibraryItemAdded;
|
|
|
|
|
_libraryManager.ItemUpdated -= OnLibraryItemUpdated;
|
|
|
|
|
_libraryManager.ItemRemoved -= OnLibraryItemRemoved;
|
|
|
|
|
|
|
|
|
|
_providerManager.RefreshCompleted -= OnProviderRefreshCompleted;
|
|
|
|
|
_providerManager.RefreshStarted -= OnProviderRefreshStarted;
|
|
|
|
|
_providerManager.RefreshProgress -= OnProviderRefreshProgress;
|
|
|
|
|
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnProviderRefreshProgress(object? sender, GenericEventArgs<Tuple<BaseItem, double>> e)
|
|
|
|
|
{
|
|
|
|
|
var item = e.Argument.Item1;
|
|
|
|
@ -137,9 +151,7 @@ public sealed class LibraryChangedNotifier : IServerEntryPoint
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnProviderRefreshStarted(object? sender, GenericEventArgs<BaseItem> e)
|
|
|
|
|
{
|
|
|
|
|
OnProviderRefreshProgress(sender, new GenericEventArgs<Tuple<BaseItem, double>>(new Tuple<BaseItem, double>(e.Argument, 0)));
|
|
|
|
|
}
|
|
|
|
|
=> OnProviderRefreshProgress(sender, new GenericEventArgs<Tuple<BaseItem, double>>(new Tuple<BaseItem, double>(e.Argument, 0)));
|
|
|
|
|
|
|
|
|
|
private void OnProviderRefreshCompleted(object? sender, GenericEventArgs<BaseItem> e)
|
|
|
|
|
{
|
|
|
|
@ -342,7 +354,7 @@ public sealed class LibraryChangedNotifier : IServerEntryPoint
|
|
|
|
|
return item.SourceType == SourceType.Library;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<string> GetTopParentIds(List<BaseItem> items, List<Folder> allUserRootChildren)
|
|
|
|
|
private static IEnumerable<string> GetTopParentIds(List<BaseItem> items, List<Folder> allUserRootChildren)
|
|
|
|
|
{
|
|
|
|
|
var list = new List<string>();
|
|
|
|
|
|
|
|
|
@ -363,7 +375,7 @@ public sealed class LibraryChangedNotifier : IServerEntryPoint
|
|
|
|
|
return list.Distinct(StringComparer.Ordinal);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<T> TranslatePhysicalItemToUserLibrary<T>(T item, User user, bool includeIfNotFound = false)
|
|
|
|
|
private T[] TranslatePhysicalItemToUserLibrary<T>(T item, User user, bool includeIfNotFound = false)
|
|
|
|
|
where T : BaseItem
|
|
|
|
|
{
|
|
|
|
|
// If the physical root changed, return the user root
|
|
|
|
@ -384,18 +396,7 @@ public sealed class LibraryChangedNotifier : IServerEntryPoint
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
_libraryManager.ItemAdded -= OnLibraryItemAdded;
|
|
|
|
|
_libraryManager.ItemUpdated -= OnLibraryItemUpdated;
|
|
|
|
|
_libraryManager.ItemRemoved -= OnLibraryItemRemoved;
|
|
|
|
|
|
|
|
|
|
_providerManager.RefreshCompleted -= OnProviderRefreshCompleted;
|
|
|
|
|
_providerManager.RefreshStarted -= OnProviderRefreshStarted;
|
|
|
|
|
_providerManager.RefreshProgress -= OnProviderRefreshProgress;
|
|
|
|
|
|
|
|
|
|
if (_libraryUpdateTimer is not null)
|
|
|
|
|
{
|
|
|
|
|
_libraryUpdateTimer.Dispose();
|
|
|
|
|
_libraryUpdateTimer = null;
|
|
|
|
|
}
|
|
|
|
|
_libraryUpdateTimer?.Dispose();
|
|
|
|
|
_libraryUpdateTimer = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|