From bd8b0c4c03fa21952f0ec84d7e0022b0767acc40 Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Sun, 9 Jun 2024 23:17:57 +0200 Subject: [PATCH] Remove all existing backdrops when replacing all images --- .../Manager/ItemImageProvider.cs | 9 ++--- .../Manager/MetadataService.cs | 34 +++++++++++-------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/MediaBrowser.Providers/Manager/ItemImageProvider.cs b/MediaBrowser.Providers/Manager/ItemImageProvider.cs index bee420d95..7db37c973 100644 --- a/MediaBrowser.Providers/Manager/ItemImageProvider.cs +++ b/MediaBrowser.Providers/Manager/ItemImageProvider.cs @@ -158,8 +158,8 @@ namespace MediaBrowser.Providers.Manager } } - // only delete existing multi-images if new ones were added - if (oldBackdropImages.Length > 0 && oldBackdropImages.Length < item.GetImages(ImageType.Backdrop).Count()) + // Only delete existing multi-images if new ones were added or replacing + if (oldBackdropImages.Length > 0 && (refreshOptions.ReplaceAllImages || oldBackdropImages.Length < item.GetImages(ImageType.Backdrop).Count())) { PruneImages(item, oldBackdropImages); } @@ -422,14 +422,11 @@ namespace MediaBrowser.Providers.Manager { var changed = item.ValidateImages(); var foundImageTypes = new List(); - for (var i = 0; i < _singularImages.Length; i++) { var type = _singularImages[i]; var image = GetFirstLocalImageInfoByType(images, type); - - // Only use local images if we are not replacing and saving - if (image is not null && !(item.IsSaveLocalMetadataEnabled() && refreshOptions.ReplaceAllImages)) + if (image is not null) { var currentImage = item.GetImageInfo(type, 0); // if image file is stored with media, don't replace that later diff --git a/MediaBrowser.Providers/Manager/MetadataService.cs b/MediaBrowser.Providers/Manager/MetadataService.cs index 61a4d7586..9691b098f 100644 --- a/MediaBrowser.Providers/Manager/MetadataService.cs +++ b/MediaBrowser.Providers/Manager/MetadataService.cs @@ -92,10 +92,6 @@ namespace MediaBrowser.Providers.Manager } } - var localImagesFailed = false; - - var allImageProviders = ProviderManager.GetImageProviders(item, refreshOptions).ToList(); - if (refreshOptions.RemoveOldMetadata && refreshOptions.ReplaceAllImages) { if (ImageProvider.RemoveImages(item)) @@ -104,19 +100,29 @@ namespace MediaBrowser.Providers.Manager } } - // Start by validating images - try + var localImagesFailed = false; + 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. - if (ImageProvider.ValidateImages(item, allImageProviders.OfType(), refreshOptions)) - { - updateType |= ItemUpdateType.ImageUpdate; - } + item.ValidateImages(); } - catch (Exception ex) + else { - localImagesFailed = true; - Logger.LogError(ex, "Error validating images for {Item}", item.Path ?? item.Name ?? "Unknown name"); + // Run full image validation and register new local images + try + { + if (ImageProvider.ValidateImages(item, allImageProviders.OfType(), 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