@ -154,7 +154,8 @@ namespace MediaBrowser.Providers.Manager
id . IsAutomated = refreshOptions . IsAutomated ;
var result = await RefreshWithProviders ( metadataResult , id , refreshOptions , providers , ImageProvider , cancellationToken ) . ConfigureAwait ( false ) ;
var hasMetadataSavers = ProviderManager . GetMetadataSavers ( item , libraryOptions ) . Any ( ) ;
var result = await RefreshWithProviders ( metadataResult , id , refreshOptions , providers , ImageProvider , hasMetadataSavers , cancellationToken ) . ConfigureAwait ( false ) ;
updateType | = result . UpdateType ;
if ( result . Failures > 0 )
@ -639,6 +640,7 @@ namespace MediaBrowser.Providers.Manager
MetadataRefreshOptions options ,
ICollection < IMetadataProvider > providers ,
ItemImageProvider imageService ,
bool isSavingMetadata ,
CancellationToken cancellationToken )
{
var refreshResult = new RefreshResult
@ -669,69 +671,74 @@ namespace MediaBrowser.Providers.Manager
temp . Item . Id = item . Id ;
var foundImageTypes = new List < ImageType > ( ) ;
foreach ( var provider in providers . OfType < ILocalMetadataProvider < TItemType > > ( ) )
{
var providerName = provider . GetType ( ) . Name ;
Logger . LogDebug ( "Running {Provider} for {Item}" , providerName , logName ) ;
var itemInfo = new ItemInfo ( item ) ;
try
// Do not execute local providers if we are identifying or replacing with local metadata saving enabled
if ( options . SearchResult is null & & ! ( isSavingMetadata & & options . ReplaceAllMetadata ) )
{
foreach ( var provider in providers . OfType < ILocalMetadataProvider < TItemType > > ( ) )
{
var localItem = await provider . GetMetadata ( itemInfo , options . DirectoryService , cancellationToken ) . ConfigureAwait ( false ) ;
var providerName = provider . GetType ( ) . Name ;
Logger . LogDebug ( "Running {Provider} for {Item}" , providerName , logName ) ;
var itemInfo = new ItemInfo ( item ) ;
if ( localItem . HasMetadata )
try
{
foreach ( var remoteImage in localItem . RemoteImages )
var localItem = await provider . GetMetadata ( itemInfo , options . DirectoryService , cancellationToken ) . ConfigureAwait ( false ) ;
if ( localItem . HasMetadata )
{
try
foreach ( var remoteImage in localItem . RemoteImages )
{
if ( item . ImageInfos . Any ( x = > x . Type = = remoteImage . Type )
& & ! options . IsReplacingImage ( remoteImage . Type ) )
try
{
continue ;
}
if ( item . ImageInfos . Any ( x = > x . Type = = remoteImage . Type )
& & ! options . IsReplacingImage ( remoteImage . Type ) )
{
continue ;
}
await ProviderManager . SaveImage ( item , remoteImage . Url , remoteImage . Type , null , cancellationToken ) . ConfigureAwait ( false ) ;
refreshResult . UpdateType | = ItemUpdateType . ImageUpdate ;
await ProviderManager . SaveImage ( item , remoteImage . Url , remoteImage . Type , null , cancellationToken ) . ConfigureAwait ( false ) ;
refreshResult . UpdateType | = ItemUpdateType . ImageUpdate ;
// remember imagetype that has just been downloaded
foundImageTypes . Add ( remoteImage . Type ) ;
// remember imagetype that has just been downloaded
foundImageTypes . Add ( remoteImage . Type ) ;
}
catch ( HttpRequestException ex )
{
Logger . LogError ( ex , "Could not save {ImageType} image: {Url}" , Enum . GetName ( remoteImage . Type ) , remoteImage . Url ) ;
}
}
catch ( HttpRequestException ex )
if ( foundImageTypes . Count > 0 )
{
Logger . LogError ( ex , "Could not save {ImageType} image: {Url}" , Enum . GetName ( remoteImage . Type ) , remoteImage . Url ) ;
imageService. UpdateReplaceImages ( options , foundImageTypes ) ;
}
}
if ( foundImageTypes . Count > 0 )
{
imageService . UpdateReplaceImages ( options , foundImageTypes ) ;
}
if ( imageService . MergeImages ( item , localItem . Images , options ) )
{
refreshResult . UpdateType | = ItemUpdateType . ImageUpdate ;
}
if ( imageService . MergeImages ( item , localItem . Images , options ) )
{
refreshResult . UpdateType | = ItemUpdateType . ImageUpdate ;
}
MergeData ( localItem , temp , Array . Empty < MetadataField > ( ) , false , true ) ;
refreshResult . UpdateType | = ItemUpdateType . MetadataImport ;
MergeData ( localItem , temp , Array . Empty < MetadataField > ( ) , false , true ) ;
refreshResult . UpdateType | = ItemUpdateType . MetadataImport ;
break ;
}
break ;
Logger . LogDebug ( "{Provider} returned no metadata for {Item}" , providerName , logName ) ;
}
catch ( OperationCanceledException )
{
throw ;
}
catch ( Exception ex )
{
Logger . LogError ( ex , "Error in {Provider}" , provider . Name ) ;
Logger . LogDebug ( "{Provider} returned no metadata for {Item}" , providerName , logName ) ;
}
catch ( OperationCanceledException )
{
throw ;
}
catch ( Exception ex )
{
Logger . LogError ( ex , "Error in {Provider}" , provider . Name ) ;
// If a local provider fails, consider that a failure
refreshResult . ErrorMessage = ex . Message ;
// If a local provider fails, consider that a failure
refreshResult . ErrorMessage = ex . Message ;
}
}
}