diff --git a/Jellyfin.Plugin.TubeArchivistMetadata/Configuration/PluginConfiguration.cs b/Jellyfin.Plugin.TubeArchivistMetadata/Configuration/PluginConfiguration.cs index cd460b0..f133b36 100644 --- a/Jellyfin.Plugin.TubeArchivistMetadata/Configuration/PluginConfiguration.cs +++ b/Jellyfin.Plugin.TubeArchivistMetadata/Configuration/PluginConfiguration.cs @@ -56,22 +56,14 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.Configuration set { - // Only refresh if value actually changed AND plugin is initialized - if (_collectionTitle != value && !string.IsNullOrEmpty(_collectionTitle)) - { - _collectionTitle = value; - _logger?.LogInformation("Collection title changed to: {CollectionTitle}", value); + _collectionTitle = value; - // Only refresh if plugin is fully initialized - if (Plugin.Instance?.LibraryManager != null) - { - Plugin.Instance?.RefreshTubeArchivistCollectionId(); - } - } - else + // Refresh cache if plugin is initialized and value is not empty + if (!string.IsNullOrEmpty(value) && Plugin.Instance?.LibraryManager != null) { - // Initial set, no refresh needed - _collectionTitle = value; + _logger?.LogInformation("Collection title set to: {CollectionTitle}, refreshing cache", value); + // Pass the new value directly instead of reading from Configuration + Plugin.Instance?.RefreshTubeArchivistCollectionId(value); } } } diff --git a/Jellyfin.Plugin.TubeArchivistMetadata/Plugin.cs b/Jellyfin.Plugin.TubeArchivistMetadata/Plugin.cs index b175959..10acb64 100644 --- a/Jellyfin.Plugin.TubeArchivistMetadata/Plugin.cs +++ b/Jellyfin.Plugin.TubeArchivistMetadata/Plugin.cs @@ -175,15 +175,13 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata TaskScheduler.Default); } - /// - /// Caches the TubeArchivist collection ID for efficient lookups. - /// This is called once during initialization to avoid repeated searches. - /// - private void CacheTubeArchivistCollectionId() + private void CacheTubeArchivistCollectionId(string? collectionTitle = null) { try { - if (string.IsNullOrEmpty(Configuration.CollectionTitle)) + string titleToSearch = collectionTitle ?? Configuration.CollectionTitle; + + if (string.IsNullOrEmpty(titleToSearch)) { Logger.LogWarning("TubeArchivist collection title not configured"); _tubeArchivistCollectionId = null; @@ -198,7 +196,7 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata }); var tubeArchivistCollection = collections.FirstOrDefault(c => - c.Name.Equals(Configuration.CollectionTitle, StringComparison.OrdinalIgnoreCase)); + c.Name.Equals(titleToSearch, StringComparison.OrdinalIgnoreCase)); if (tubeArchivistCollection != null) { @@ -207,7 +205,7 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata } else { - Logger.LogWarning("Could not find TubeArchivist collection with name: {CollectionName}", Configuration.CollectionTitle); + Logger.LogWarning("Could not find TubeArchivist collection with name: {CollectionName}", titleToSearch); _tubeArchivistCollectionId = null; } } @@ -222,10 +220,11 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata /// Refreshes the cached TubeArchivist collection ID. /// Called when the collection title changes in configuration. /// - public void RefreshTubeArchivistCollectionId() + /// Optional collection title to use. If null, reads from Configuration. + public void RefreshTubeArchivistCollectionId(string? collectionTitle = null) { Logger.LogInformation("Refreshing TubeArchivist collection cache due to configuration change"); - CacheTubeArchivistCollectionId(); + CacheTubeArchivistCollectionId(collectionTitle ?? Configuration.CollectionTitle); } ///