2014-06-29 23:04:50 -04:00
|
|
|
|
using MediaBrowser.Common.Configuration;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Controller.Plugins;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
2018-12-13 08:18:25 -05:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2014-06-29 23:04:50 -04:00
|
|
|
|
using MediaBrowser.XbmcMetadata.Configuration;
|
2014-09-26 22:28:13 -04:00
|
|
|
|
using MediaBrowser.XbmcMetadata.Savers;
|
2014-06-29 23:04:50 -04:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2014-09-26 22:28:13 -04:00
|
|
|
|
if (e.SaveReason == UserDataSaveReason.PlaybackFinished || e.SaveReason == UserDataSaveReason.TogglePlayed || e.SaveReason == UserDataSaveReason.UpdateUserRating)
|
2014-06-29 23:04:50 -04:00
|
|
|
|
{
|
2014-09-26 22:28:13 -04:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(_config.GetNfoConfiguration().UserId))
|
2014-06-29 23:04:50 -04:00
|
|
|
|
{
|
2018-09-12 13:26:21 -04:00
|
|
|
|
SaveMetadataForItem(e.Item, ItemUpdateType.MetadataDownload);
|
2014-06-29 23:04:50 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
_userDataManager.UserDataSaved -= _userDataManager_UserDataSaved;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-03 14:39:37 -04:00
|
|
|
|
private void SaveMetadataForItem(BaseItem item, ItemUpdateType updateReason)
|
2014-06-29 23:04:50 -04:00
|
|
|
|
{
|
2018-09-12 13:26:21 -04:00
|
|
|
|
if (!item.IsFileProtocol)
|
2014-06-29 23:04:50 -04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-25 14:39:13 -04:00
|
|
|
|
if (!item.SupportsLocalMetadata)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!item.IsSaveLocalMetadataEnabled())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 23:04:50 -04:00
|
|
|
|
try
|
|
|
|
|
{
|
2017-10-03 14:39:37 -04:00
|
|
|
|
_providerManager.SaveMetadata(item, updateReason, new[] { BaseNfoSaver.SaverName });
|
2014-06-29 23:04:50 -04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2018-12-20 07:11:26 -05:00
|
|
|
|
_logger.LogError(ex, "Error saving metadata for {path}", item.Path ?? item.Name);
|
2014-06-29 23:04:50 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|