call metadata savers after items are updated

This commit is contained in:
Luke Pulverenti 2013-06-09 13:37:16 -04:00
parent 7aa969e2b9
commit fad1ac8e9f
6 changed files with 57 additions and 18 deletions

View File

@ -145,13 +145,16 @@ namespace MediaBrowser.Controller.Library
/// <param name="itemComparers">The item comparers.</param>
/// <param name="prescanTasks">The prescan tasks.</param>
/// <param name="postscanTasks">The postscan tasks.</param>
/// <param name="savers">The savers.</param>
/// <param name="?">The ?.</param>
void AddParts(IEnumerable<IResolverIgnoreRule> rules,
IEnumerable<IVirtualFolderCreator> pluginFolders,
IEnumerable<IItemResolver> resolvers,
IEnumerable<IIntroProvider> introProviders,
IEnumerable<IBaseItemComparer> itemComparers,
IEnumerable<ILibraryPrescanTask> prescanTasks,
IEnumerable<ILibraryPostScanTask> postscanTasks);
IEnumerable<ILibraryPostScanTask> postscanTasks,
IEnumerable<IMetadataSaver> savers);
/// <summary>
/// Sorts the specified items.

View File

@ -76,6 +76,7 @@
<Compile Include="Music\LastfmHelper.cs" />
<Compile Include="Music\MusicArtistProviderFromJson.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Savers\MovieXmlSaver.cs" />
<Compile Include="TV\EpisodeImageFromMediaLocationProvider.cs" />
<Compile Include="TV\EpisodeProviderFromXml.cs" />
<Compile Include="TV\EpisodeXmlParser.cs" />

View File

@ -5,7 +5,7 @@ using MediaBrowser.Model.Entities;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Server.Implementations.Savers
namespace MediaBrowser.Providers.Savers
{
/// <summary>
/// Saves movie.xml for movies, trailers and music videos

View File

@ -73,6 +73,12 @@ namespace MediaBrowser.Server.Implementations.Library
/// <value>The comparers.</value>
private IEnumerable<IBaseItemComparer> Comparers { get; set; }
/// <summary>
/// Gets or sets the savers.
/// </summary>
/// <value>The savers.</value>
private IEnumerable<IMetadataSaver> Savers { get; set; }
/// <summary>
/// Gets the active item repository
/// </summary>
@ -191,13 +197,15 @@ namespace MediaBrowser.Server.Implementations.Library
/// <param name="itemComparers">The item comparers.</param>
/// <param name="prescanTasks">The prescan tasks.</param>
/// <param name="postscanTasks">The postscan tasks.</param>
/// <param name="savers">The savers.</param>
public void AddParts(IEnumerable<IResolverIgnoreRule> rules,
IEnumerable<IVirtualFolderCreator> pluginFolders,
IEnumerable<IItemResolver> resolvers,
IEnumerable<IIntroProvider> introProviders,
IEnumerable<IBaseItemComparer> itemComparers,
IEnumerable<ILibraryPrescanTask> prescanTasks,
IEnumerable<ILibraryPostScanTask> postscanTasks)
IEnumerable<ILibraryPostScanTask> postscanTasks,
IEnumerable<IMetadataSaver> savers)
{
EntityResolutionIgnoreRules = rules;
PluginFolderCreators = pluginFolders;
@ -206,6 +214,7 @@ namespace MediaBrowser.Server.Implementations.Library
Comparers = itemComparers;
PrescanTasks = prescanTasks;
PostscanTasks = postscanTasks;
Savers = savers;
}
/// <summary>
@ -1259,7 +1268,7 @@ namespace MediaBrowser.Server.Implementations.Library
}
catch (Exception ex)
{
_logger.ErrorException("Error in ItemUpdated event handler", ex);
_logger.ErrorException("Error in ItemAdded event handler", ex);
}
}
}
@ -1282,19 +1291,9 @@ namespace MediaBrowser.Server.Implementations.Library
UpdateItemInLibraryCache(item);
}
if (ItemUpdated != null)
foreach (var item in list)
{
foreach (var item in list)
{
try
{
ItemUpdated(this, new ItemChangeEventArgs { Item = item });
}
catch (Exception ex)
{
_logger.ErrorException("Error in ItemUpdated event handler", ex);
}
}
await OnItemUpdated(item, CancellationToken.None).ConfigureAwait(false);
}
}
@ -1366,5 +1365,41 @@ namespace MediaBrowser.Server.Implementations.Library
return children;
}
/// <summary>
/// Called when [item updated].
/// </summary>
/// <param name="item">The item.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
private async Task OnItemUpdated(BaseItem item, CancellationToken cancellationToken)
{
if (ConfigurationManager.Configuration.SaveLocalMeta)
{
foreach (var saver in Savers.Where(i => i.Supports(item)))
{
try
{
await saver.Save(item, cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{
_logger.ErrorException("Error in metadata saver", ex);
}
}
}
if (ItemUpdated != null)
{
try
{
ItemUpdated(this, new ItemChangeEventArgs { Item = item });
}
catch (Exception ex)
{
_logger.ErrorException("Error in ItemUpdated event handler", ex);
}
}
}
}
}

View File

@ -143,7 +143,6 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Providers\ProviderManager.cs" />
<Compile Include="Reflection\TypeMapper.cs" />
<Compile Include="Savers\MovieXmlSaver.cs" />
<Compile Include="ScheduledTasks\ArtistValidationTask.cs" />
<Compile Include="ScheduledTasks\PeopleValidationTask.cs" />
<Compile Include="ScheduledTasks\ChapterImagesTask.cs" />

View File

@ -397,7 +397,8 @@ namespace MediaBrowser.ServerApplication
GetExports<IIntroProvider>(),
GetExports<IBaseItemComparer>(),
GetExports<ILibraryPrescanTask>(),
GetExports<ILibraryPostScanTask>());
GetExports<ILibraryPostScanTask>(),
GetExports<IMetadataSaver>());
ProviderManager.AddMetadataProviders(GetExports<BaseMetadataProvider>().ToArray());
}