You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.6 KiB
80 lines
2.6 KiB
using System;
|
|
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 class EntryPoint : IServerEntryPoint
|
|
{
|
|
private readonly IUserDataManager _userDataManager;
|
|
private readonly ILogger _logger;
|
|
private readonly ILibraryManager _libraryManager;
|
|
private readonly IProviderManager _providerManager;
|
|
private readonly IConfigurationManager _config;
|
|
|
|
public EntryPoint(IUserDataManager userDataManager, ILibraryManager libraryManager, ILogger logger, IProviderManager providerManager, IConfigurationManager config)
|
|
{
|
|
_userDataManager = userDataManager;
|
|
_libraryManager = libraryManager;
|
|
_logger = logger;
|
|
_providerManager = providerManager;
|
|
_config = config;
|
|
}
|
|
|
|
public void Run()
|
|
{
|
|
_userDataManager.UserDataSaved += _userDataManager_UserDataSaved;
|
|
}
|
|
|
|
void _userDataManager_UserDataSaved(object sender, UserDataSaveEventArgs e)
|
|
{
|
|
if (e.SaveReason == UserDataSaveReason.PlaybackFinished || e.SaveReason == UserDataSaveReason.TogglePlayed || e.SaveReason == UserDataSaveReason.UpdateUserRating)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(_config.GetNfoConfiguration().UserId))
|
|
{
|
|
SaveMetadataForItem(e.Item, ItemUpdateType.MetadataDownload);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_userDataManager.UserDataSaved -= _userDataManager_UserDataSaved;
|
|
}
|
|
|
|
private void SaveMetadataForItem(BaseItem item, ItemUpdateType updateReason)
|
|
{
|
|
if (!item.IsFileProtocol)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!item.SupportsLocalMetadata)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!item.IsSaveLocalMetadataEnabled())
|
|
{
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
_providerManager.SaveMetadata(item, updateReason, new[] { BaseNfoSaver.SaverName });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error saving metadata for {path}", item.Path ?? item.Name);
|
|
}
|
|
}
|
|
}
|
|
}
|