Merge pull request #10976 from barronpm/ihostedservice
Replace IServerEntryPoint with IHostedServicepull/10988/head
commit
5ad7e4b749
@ -1,35 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Plugins;
|
||||
|
||||
namespace Emby.Server.Implementations.IO
|
||||
{
|
||||
/// <summary>
|
||||
/// <see cref="IServerEntryPoint" /> which is responsible for starting the library monitor.
|
||||
/// </summary>
|
||||
public sealed class LibraryMonitorStartup : IServerEntryPoint
|
||||
{
|
||||
private readonly ILibraryMonitor _monitor;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LibraryMonitorStartup"/> class.
|
||||
/// </summary>
|
||||
/// <param name="monitor">The library monitor.</param>
|
||||
public LibraryMonitorStartup(ILibraryMonitor monitor)
|
||||
{
|
||||
_monitor = monitor;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task RunAsync()
|
||||
{
|
||||
_monitor.Start();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Controller.Plugins
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an entry point for a module in the application. This interface is scanned for automatically and
|
||||
/// provides a hook to initialize the module at application start.
|
||||
/// The entry point can additionally be flagged as a pre-startup task by implementing the
|
||||
/// <see cref="IRunBeforeStartup"/> interface.
|
||||
/// </summary>
|
||||
public interface IServerEntryPoint : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Run the initialization for this module. This method is invoked at application start.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
||||
Task RunAsync();
|
||||
}
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Plugins;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.XbmcMetadata.Configuration;
|
||||
using MediaBrowser.XbmcMetadata.Savers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace MediaBrowser.XbmcMetadata
|
||||
{
|
||||
public sealed class EntryPoint : IServerEntryPoint
|
||||
{
|
||||
private readonly IUserDataManager _userDataManager;
|
||||
private readonly ILogger<EntryPoint> _logger;
|
||||
private readonly IProviderManager _providerManager;
|
||||
private readonly IConfigurationManager _config;
|
||||
|
||||
public EntryPoint(
|
||||
IUserDataManager userDataManager,
|
||||
ILogger<EntryPoint> logger,
|
||||
IProviderManager providerManager,
|
||||
IConfigurationManager config)
|
||||
{
|
||||
_userDataManager = userDataManager;
|
||||
_logger = logger;
|
||||
_providerManager = providerManager;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task RunAsync()
|
||||
{
|
||||
_userDataManager.UserDataSaved += OnUserDataSaved;
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private void OnUserDataSaved(object? sender, UserDataSaveEventArgs e)
|
||||
{
|
||||
if (e.SaveReason == UserDataSaveReason.PlaybackFinished || e.SaveReason == UserDataSaveReason.TogglePlayed || e.SaveReason == UserDataSaveReason.UpdateUserRating)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(_config.GetNfoConfiguration().UserId))
|
||||
{
|
||||
_ = SaveMetadataForItemAsync(e.Item, ItemUpdateType.MetadataDownload);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
_userDataManager.UserDataSaved -= OnUserDataSaved;
|
||||
}
|
||||
|
||||
private async Task SaveMetadataForItemAsync(BaseItem item, ItemUpdateType updateReason)
|
||||
{
|
||||
if (!item.IsFileProtocol || !item.SupportsLocalMetadata)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await _providerManager.SaveMetadataAsync(item, updateReason, new[] { BaseNfoSaver.SaverName }).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error saving metadata for {Path}", item.Path ?? item.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.XbmcMetadata.Configuration;
|
||||
using MediaBrowser.XbmcMetadata.Savers;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace MediaBrowser.XbmcMetadata;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="IHostedService"/> responsible for updating NFO files' user data.
|
||||
/// </summary>
|
||||
public sealed class NfoUserDataSaver : IHostedService
|
||||
{
|
||||
private readonly ILogger<NfoUserDataSaver> _logger;
|
||||
private readonly IConfigurationManager _config;
|
||||
private readonly IUserDataManager _userDataManager;
|
||||
private readonly IProviderManager _providerManager;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="NfoUserDataSaver"/> class.
|
||||
/// </summary>
|
||||
/// <param name="logger">The <see cref="ILogger"/>.</param>
|
||||
/// <param name="config">The <see cref="IConfigurationManager"/>.</param>
|
||||
/// <param name="userDataManager">The <see cref="IUserDataManager"/>.</param>
|
||||
/// <param name="providerManager">The <see cref="IProviderManager"/>.</param>
|
||||
public NfoUserDataSaver(
|
||||
ILogger<NfoUserDataSaver> logger,
|
||||
IConfigurationManager config,
|
||||
IUserDataManager userDataManager,
|
||||
IProviderManager providerManager)
|
||||
{
|
||||
_logger = logger;
|
||||
_config = config;
|
||||
_userDataManager = userDataManager;
|
||||
_providerManager = providerManager;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_userDataManager.UserDataSaved += OnUserDataSaved;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_userDataManager.UserDataSaved -= OnUserDataSaved;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async void OnUserDataSaved(object? sender, UserDataSaveEventArgs e)
|
||||
{
|
||||
if (e.SaveReason is not (UserDataSaveReason.PlaybackFinished
|
||||
or UserDataSaveReason.TogglePlayed or UserDataSaveReason.UpdateUserRating))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(_config.GetNfoConfiguration().UserId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var item = e.Item;
|
||||
if (!item.IsFileProtocol || !item.SupportsLocalMetadata)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await _providerManager.SaveMetadataAsync(item, ItemUpdateType.MetadataDownload, [BaseNfoSaver.SaverName])
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error saving metadata for {Path}", item.Path ?? item.Name);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Controller.Plugins;
|
||||
|
||||
namespace Jellyfin.LiveTv.EmbyTV
|
||||
{
|
||||
public sealed class EntryPoint : IServerEntryPoint
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public Task RunAsync()
|
||||
{
|
||||
return EmbyTV.Current.Start();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Controller.LiveTv;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Jellyfin.LiveTv.EmbyTV;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="IHostedService"/> responsible for initializing Live TV.
|
||||
/// </summary>
|
||||
public sealed class LiveTvHost : IHostedService
|
||||
{
|
||||
private readonly EmbyTV _service;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LiveTvHost"/> class.
|
||||
/// </summary>
|
||||
/// <param name="services">The available <see cref="ILiveTvService"/>s.</param>
|
||||
public LiveTvHost(IEnumerable<ILiveTvService> services)
|
||||
{
|
||||
_service = services.OfType<EmbyTV>().First();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task StartAsync(CancellationToken cancellationToken) => _service.Start();
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||
}
|
Loading…
Reference in new issue