Remove all existing backdrops when replacing all images

This commit is contained in:
Shadowghost 2024-06-09 23:17:57 +02:00
parent 0c560a313a
commit bd8b0c4c03
2 changed files with 23 additions and 20 deletions

View File

@ -158,8 +158,8 @@ namespace MediaBrowser.Providers.Manager
} }
} }
// only delete existing multi-images if new ones were added // Only delete existing multi-images if new ones were added or replacing
if (oldBackdropImages.Length > 0 && oldBackdropImages.Length < item.GetImages(ImageType.Backdrop).Count()) if (oldBackdropImages.Length > 0 && (refreshOptions.ReplaceAllImages || oldBackdropImages.Length < item.GetImages(ImageType.Backdrop).Count()))
{ {
PruneImages(item, oldBackdropImages); PruneImages(item, oldBackdropImages);
} }
@ -422,14 +422,11 @@ namespace MediaBrowser.Providers.Manager
{ {
var changed = item.ValidateImages(); var changed = item.ValidateImages();
var foundImageTypes = new List<ImageType>(); var foundImageTypes = new List<ImageType>();
for (var i = 0; i < _singularImages.Length; i++) for (var i = 0; i < _singularImages.Length; i++)
{ {
var type = _singularImages[i]; var type = _singularImages[i];
var image = GetFirstLocalImageInfoByType(images, type); var image = GetFirstLocalImageInfoByType(images, type);
if (image is not null)
// Only use local images if we are not replacing and saving
if (image is not null && !(item.IsSaveLocalMetadataEnabled() && refreshOptions.ReplaceAllImages))
{ {
var currentImage = item.GetImageInfo(type, 0); var currentImage = item.GetImageInfo(type, 0);
// if image file is stored with media, don't replace that later // if image file is stored with media, don't replace that later

View File

@ -92,10 +92,6 @@ namespace MediaBrowser.Providers.Manager
} }
} }
var localImagesFailed = false;
var allImageProviders = ProviderManager.GetImageProviders(item, refreshOptions).ToList();
if (refreshOptions.RemoveOldMetadata && refreshOptions.ReplaceAllImages) if (refreshOptions.RemoveOldMetadata && refreshOptions.ReplaceAllImages)
{ {
if (ImageProvider.RemoveImages(item)) if (ImageProvider.RemoveImages(item))
@ -104,19 +100,29 @@ namespace MediaBrowser.Providers.Manager
} }
} }
// Start by validating images var localImagesFailed = false;
try var allImageProviders = ProviderManager.GetImageProviders(item, refreshOptions).ToList();
// Only validate already registered images if we are replacing and saving locally
if (item.IsSaveLocalMetadataEnabled() && refreshOptions.ReplaceAllImages)
{ {
// Always validate images and check for new locally stored ones. item.ValidateImages();
if (ImageProvider.ValidateImages(item, allImageProviders.OfType<ILocalImageProvider>(), refreshOptions))
{
updateType |= ItemUpdateType.ImageUpdate;
}
} }
catch (Exception ex) else
{ {
localImagesFailed = true; // Run full image validation and register new local images
Logger.LogError(ex, "Error validating images for {Item}", item.Path ?? item.Name ?? "Unknown name"); try
{
if (ImageProvider.ValidateImages(item, allImageProviders.OfType<ILocalImageProvider>(), refreshOptions))
{
updateType |= ItemUpdateType.ImageUpdate;
}
}
catch (Exception ex)
{
localImagesFailed = true;
Logger.LogError(ex, "Error validating images for {Item}", item.Path ?? item.Name ?? "Unknown name");
}
} }
var metadataResult = new MetadataResult<TItemType> var metadataResult = new MetadataResult<TItemType>