add custom providers that can run before refresh chain

pull/702/head
Luke Pulverenti 11 years ago
parent b9aa38b5ab
commit c2e51df31d

@ -14,4 +14,9 @@ namespace MediaBrowser.Controller.Providers
{ {
Task<ItemUpdateType> FetchAsync(TItemType item, IDirectoryService directoryService, CancellationToken cancellationToken); Task<ItemUpdateType> FetchAsync(TItemType item, IDirectoryService directoryService, CancellationToken cancellationToken);
} }
public interface IPreRefreshProvider : ICustomMetadataProvider
{
}
} }

@ -269,6 +269,13 @@ namespace MediaBrowser.Providers.Manager
Providers = providers.Select(i => i.GetType().FullName.GetMD5()).ToList() Providers = providers.Select(i => i.GetType().FullName.GetMD5()).ToList()
}; };
var customProviders = providers.OfType<ICustomMetadataProvider<TItemType>>().ToList();
foreach (var provider in customProviders.Where(i => i is IPreRefreshProvider))
{
await RunCustomProvider(provider, item, options.DirectoryService, refreshResult, cancellationToken).ConfigureAwait(false);
}
var temp = CreateNew(); var temp = CreateNew();
temp.Path = item.Path; temp.Path = item.Path;
@ -342,7 +349,7 @@ namespace MediaBrowser.Providers.Manager
MergeData(temp, item, item.LockedFields, true, true); MergeData(temp, item, item.LockedFields, true, true);
} }
foreach (var provider in providers.OfType<ICustomMetadataProvider<TItemType>>()) foreach (var provider in customProviders.Where(i => !(i is IPreRefreshProvider)))
{ {
await RunCustomProvider(provider, item, options.DirectoryService, refreshResult, cancellationToken).ConfigureAwait(false); await RunCustomProvider(provider, item, options.DirectoryService, refreshResult, cancellationToken).ConfigureAwait(false);
} }
@ -379,6 +386,9 @@ namespace MediaBrowser.Providers.Manager
{ {
TIdType id = null; TIdType id = null;
var unidentifiedCount = 0;
var identifiedCount = 0;
foreach (var provider in providers) foreach (var provider in providers)
{ {
var providerName = provider.GetType().Name; var providerName = provider.GetType().Name;
@ -402,9 +412,12 @@ namespace MediaBrowser.Providers.Manager
MergeData(result.Item, temp, new List<MetadataFields>(), false, false); MergeData(result.Item, temp, new List<MetadataFields>(), false, false);
refreshResult.UpdateType = refreshResult.UpdateType | ItemUpdateType.MetadataDownload; refreshResult.UpdateType = refreshResult.UpdateType | ItemUpdateType.MetadataDownload;
identifiedCount++;
} }
else else
{ {
unidentifiedCount++;
Logger.Debug("{0} returned no metadata for {1}", providerName, item.Path ?? item.Name); Logger.Debug("{0} returned no metadata for {1}", providerName, item.Path ?? item.Name);
} }
} }
@ -414,11 +427,20 @@ namespace MediaBrowser.Providers.Manager
} }
catch (Exception ex) catch (Exception ex)
{ {
unidentifiedCount++;
refreshResult.Status = ProviderRefreshStatus.CompletedWithErrors; refreshResult.Status = ProviderRefreshStatus.CompletedWithErrors;
refreshResult.ErrorMessage = ex.Message; refreshResult.ErrorMessage = ex.Message;
Logger.ErrorException("Error in {0}", ex, provider.Name); Logger.ErrorException("Error in {0}", ex, provider.Name);
} }
} }
var isUnidentified = unidentifiedCount > 0 && identifiedCount == 0;
if (item.IsUnidentified != isUnidentified)
{
item.IsUnidentified = isUnidentified;
refreshResult.UpdateType = refreshResult.UpdateType | ItemUpdateType.MetadataImport;
}
} }
private void MergeNewData(TItemType source, TIdType lookupInfo) private void MergeNewData(TItemType source, TIdType lookupInfo)

Loading…
Cancel
Save