diff --git a/Shokofin/Configuration/MediaFolderConfigurationService.cs b/Shokofin/Configuration/MediaFolderConfigurationService.cs index 1f8a41d6..bf6a7d46 100644 --- a/Shokofin/Configuration/MediaFolderConfigurationService.cs +++ b/Shokofin/Configuration/MediaFolderConfigurationService.cs @@ -312,7 +312,7 @@ private async Task GenerateAllConfigurations(List allVirtualF foreach (var mediaFolderPath in virtualFolder.Locations) { if (LibraryManager.FindByPath(mediaFolderPath, true) is not Folder secondFolder) { - Logger.LogTrace("Unable to find database entry for {Path}", mediaFolderPath); + Logger.LogTrace("Unable to find database entry for {Path} (Library={LibraryId})", mediaFolderPath, libraryId); continue; } @@ -353,6 +353,15 @@ private async Task GenerateAllConfigurations(List allVirtualF edits.remove.Add(location); } } + + var mediaFoldersToRemove = config.MediaFolders + .Where(c => !filteredVirtualFolders.Any(v => Guid.Parse(v.ItemId) == c.LibraryId)) + .ToList(); + Logger.LogDebug("Found {Count} out of {TotalCount} media folders to remove.", mediaFoldersToRemove.Count, config.MediaFolders.Count); + foreach (var mediaFolder in mediaFoldersToRemove) { + Logger.LogTrace("Removing config for media folder at path {Path} (Library={LibraryId})", mediaFolder.MediaFolderPath, mediaFolder.LibraryId); + config.MediaFolders.Remove(mediaFolder); + } } private async Task CreateConfigurationForPath(Guid libraryId, Folder mediaFolder, MediaFolderConfiguration? libraryConfig)