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="itemComparers">The item comparers.</param>
/// <param name="prescanTasks">The prescan tasks.</param> /// <param name="prescanTasks">The prescan tasks.</param>
/// <param name="postscanTasks">The postscan tasks.</param> /// <param name="postscanTasks">The postscan tasks.</param>
/// <param name="savers">The savers.</param>
/// <param name="?">The ?.</param>
void AddParts(IEnumerable<IResolverIgnoreRule> rules, void AddParts(IEnumerable<IResolverIgnoreRule> rules,
IEnumerable<IVirtualFolderCreator> pluginFolders, IEnumerable<IVirtualFolderCreator> pluginFolders,
IEnumerable<IItemResolver> resolvers, IEnumerable<IItemResolver> resolvers,
IEnumerable<IIntroProvider> introProviders, IEnumerable<IIntroProvider> introProviders,
IEnumerable<IBaseItemComparer> itemComparers, IEnumerable<IBaseItemComparer> itemComparers,
IEnumerable<ILibraryPrescanTask> prescanTasks, IEnumerable<ILibraryPrescanTask> prescanTasks,
IEnumerable<ILibraryPostScanTask> postscanTasks); IEnumerable<ILibraryPostScanTask> postscanTasks,
IEnumerable<IMetadataSaver> savers);
/// <summary> /// <summary>
/// Sorts the specified items. /// Sorts the specified items.

View File

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

View File

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

View File

@ -73,6 +73,12 @@ namespace MediaBrowser.Server.Implementations.Library
/// <value>The comparers.</value> /// <value>The comparers.</value>
private IEnumerable<IBaseItemComparer> Comparers { get; set; } private IEnumerable<IBaseItemComparer> Comparers { get; set; }
/// <summary>
/// Gets or sets the savers.
/// </summary>
/// <value>The savers.</value>
private IEnumerable<IMetadataSaver> Savers { get; set; }
/// <summary> /// <summary>
/// Gets the active item repository /// Gets the active item repository
/// </summary> /// </summary>
@ -191,13 +197,15 @@ namespace MediaBrowser.Server.Implementations.Library
/// <param name="itemComparers">The item comparers.</param> /// <param name="itemComparers">The item comparers.</param>
/// <param name="prescanTasks">The prescan tasks.</param> /// <param name="prescanTasks">The prescan tasks.</param>
/// <param name="postscanTasks">The postscan tasks.</param> /// <param name="postscanTasks">The postscan tasks.</param>
/// <param name="savers">The savers.</param>
public void AddParts(IEnumerable<IResolverIgnoreRule> rules, public void AddParts(IEnumerable<IResolverIgnoreRule> rules,
IEnumerable<IVirtualFolderCreator> pluginFolders, IEnumerable<IVirtualFolderCreator> pluginFolders,
IEnumerable<IItemResolver> resolvers, IEnumerable<IItemResolver> resolvers,
IEnumerable<IIntroProvider> introProviders, IEnumerable<IIntroProvider> introProviders,
IEnumerable<IBaseItemComparer> itemComparers, IEnumerable<IBaseItemComparer> itemComparers,
IEnumerable<ILibraryPrescanTask> prescanTasks, IEnumerable<ILibraryPrescanTask> prescanTasks,
IEnumerable<ILibraryPostScanTask> postscanTasks) IEnumerable<ILibraryPostScanTask> postscanTasks,
IEnumerable<IMetadataSaver> savers)
{ {
EntityResolutionIgnoreRules = rules; EntityResolutionIgnoreRules = rules;
PluginFolderCreators = pluginFolders; PluginFolderCreators = pluginFolders;
@ -206,6 +214,7 @@ namespace MediaBrowser.Server.Implementations.Library
Comparers = itemComparers; Comparers = itemComparers;
PrescanTasks = prescanTasks; PrescanTasks = prescanTasks;
PostscanTasks = postscanTasks; PostscanTasks = postscanTasks;
Savers = savers;
} }
/// <summary> /// <summary>
@ -1259,7 +1268,7 @@ namespace MediaBrowser.Server.Implementations.Library
} }
catch (Exception ex) 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); UpdateItemInLibraryCache(item);
} }
if (ItemUpdated != null)
{
foreach (var item in list) foreach (var item in list)
{ {
try await OnItemUpdated(item, CancellationToken.None).ConfigureAwait(false);
{
ItemUpdated(this, new ItemChangeEventArgs { Item = item });
}
catch (Exception ex)
{
_logger.ErrorException("Error in ItemUpdated event handler", ex);
}
}
} }
} }
@ -1366,5 +1365,41 @@ namespace MediaBrowser.Server.Implementations.Library
return children; 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="Properties\AssemblyInfo.cs" />
<Compile Include="Providers\ProviderManager.cs" /> <Compile Include="Providers\ProviderManager.cs" />
<Compile Include="Reflection\TypeMapper.cs" /> <Compile Include="Reflection\TypeMapper.cs" />
<Compile Include="Savers\MovieXmlSaver.cs" />
<Compile Include="ScheduledTasks\ArtistValidationTask.cs" /> <Compile Include="ScheduledTasks\ArtistValidationTask.cs" />
<Compile Include="ScheduledTasks\PeopleValidationTask.cs" /> <Compile Include="ScheduledTasks\PeopleValidationTask.cs" />
<Compile Include="ScheduledTasks\ChapterImagesTask.cs" /> <Compile Include="ScheduledTasks\ChapterImagesTask.cs" />

View File

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