From f20ccaed42b5283ac29623202b6112e76188e9cf Mon Sep 17 00:00:00 2001 From: Kilian von Pflugk Date: Sun, 24 Nov 2024 17:53:07 +0100 Subject: [PATCH] handle library selection by jellyfin --- .../Configuration/PluginConfiguration.cs | 23 ++++---- IntroSkipper/Configuration/configPage.html | 56 ++++++------------- IntroSkipper/Helper/LegacyMigrations.cs | 47 +++++++++++++++- IntroSkipper/Manager/QueueManager.cs | 21 +------ IntroSkipper/Plugin.cs | 2 +- .../ScheduledTasks/BaseItemAnalyzerTask.cs | 4 +- 6 files changed, 80 insertions(+), 73 deletions(-) diff --git a/IntroSkipper/Configuration/PluginConfiguration.cs b/IntroSkipper/Configuration/PluginConfiguration.cs index 3bcf221..bf610d5 100644 --- a/IntroSkipper/Configuration/PluginConfiguration.cs +++ b/IntroSkipper/Configuration/PluginConfiguration.cs @@ -1,7 +1,6 @@ // Copyright (C) 2024 Intro-Skipper contributors // SPDX-License-Identifier: GPL-3.0-only. -using System.Collections.Generic; using System.Diagnostics; using IntroSkipper.Data; using MediaBrowser.Model.Plugins; @@ -22,16 +21,6 @@ public class PluginConfiguration : BasePluginConfiguration // ===== Analysis settings ===== - /// - /// Gets or sets the comma separated list of library names to analyze. - /// - public string SelectedLibraries { get; set; } = string.Empty; - - /// - /// Gets or sets a value indicating whether all libraries should be analyzed. - /// - public bool SelectAllLibraries { get; set; } = true; - /// /// Gets or sets a value indicating whether movies should be analyzed. /// @@ -299,4 +288,16 @@ public class PluginConfiguration : BasePluginConfiguration /// Gets or sets a value indicating whether the ManifestUrl is self-managed, e.g. for mainland China. /// public bool OverrideManifestUrl { get; set; } + + // ===== Deprecated ===== + + /// + /// Gets or sets the comma separated list of library names to analyze. + /// + public string SelectedLibraries { get; set; } = string.Empty; + + /// + /// Gets or sets a value indicating whether all libraries should be analyzed. + /// + public bool SelectAllLibraries { get; set; } = true; } diff --git a/IntroSkipper/Configuration/configPage.html b/IntroSkipper/Configuration/configPage.html index 36b41ca..7bd4c3f 100644 --- a/IntroSkipper/Configuration/configPage.html +++ b/IntroSkipper/Configuration/configPage.html @@ -73,22 +73,6 @@ -
- - -
-
-

Limit analysis to the following libraries

-
-
- - -
-
-
Modify Segment Parameters @@ -763,7 +747,6 @@ var configurationFields = [ // analysis "MaxParallelism", - "SelectedLibraries", "ClientList", "AnalysisPercent", "AnalysisLengthLimit", @@ -793,7 +776,23 @@ "AutoSkipNotificationText", ]; - var booleanConfigurationFields = ["AutoDetectIntros", "AnalyzeMovies", "AnalyzeSeasonZero", "SelectAllLibraries", "UpdateMediaSegments", "RebuildMediaSegments", "ScanIntroduction", "ScanCredits", "ScanRecap", "ScanPreview", "CacheFingerprints", "PluginSkip", "AutoSkip", "SkipFirstEpisode", "PersistSkipButton", "SkipButtonEnabled"]; + var booleanConfigurationFields = [ + "AutoDetectIntros", + "AnalyzeMovies", + "AnalyzeSeasonZero", + "UpdateMediaSegments", + "RebuildMediaSegments", + "ScanIntroduction", + "ScanCredits", + "ScanRecap", + "ScanPreview", + "CacheFingerprints", + "PluginSkip", + "AutoSkip", + "SkipFirstEpisode", + "PersistSkipButton", + "SkipButtonEnabled" + ]; // visualizer elements var analyzerActionsSection = document.querySelector("div#analyzerActionsSection"); @@ -831,8 +830,6 @@ var skipButtonVisible = document.getElementById("SkipButtonEnabled"); var skipButtonVisibleLabel = document.getElementById("SkipButtonVisibleLabel"); var skipButtonSettings = document.getElementById("SkipButtonSettings"); - var selectAllLibraries = document.querySelector("input#SelectAllLibraries"); - var librariesContainer = document.querySelector("div.folderAccessListContainer"); var skipFirstEpisode = document.getElementById("divSkipFirstEpisode"); var secondsOfIntroStartToPlay = document.getElementById("divSecondsOfIntroStartToPlay"); var autoSkipClientList = document.querySelector("div.AutoSkipClientListContainer"); @@ -864,16 +861,6 @@ autoSkip.addEventListener("change", autoSkipChanged); - function selectAllLibrariesChanged() { - if (selectAllLibraries.checked) { - librariesContainer.style.display = "none"; - } else { - librariesContainer.style.display = "unset"; - } - } - - selectAllLibraries.addEventListener("change", selectAllLibrariesChanged); - function updateList(textField, container) { textField.value = Array.from(container.querySelectorAll('input[type="checkbox"]:checked')) .map((checkbox) => checkbox.nextElementSibling.textContent) @@ -912,13 +899,6 @@ generateCheckboxList(types, "autoSkipTypeCheckboxes", "TypeList"); } - async function populateLibraries() { - const response = await getJson("Library/VirtualFolders"); - const tvLibraries = response.filter((item) => item.CollectionType === undefined || item.CollectionType === "tvshows" || item.CollectionType === "movies"); - const libraryNames = tvLibraries.map((lib) => lib.Name || "Unnamed Library"); - generateCheckboxList(libraryNames, "libraryCheckboxes", "SelectedLibraries"); - } - var persistSkip = document.getElementById("PersistSkipButton"); var showAdjustment = document.querySelector("div#divShowPromptAdjustment"); var hideAdjustment = document.querySelector("div#divHidePromptAdjustment"); @@ -1444,8 +1424,6 @@ document.getElementById("warningMessage").style.display = "none"; } - populateLibraries(); - selectAllLibrariesChanged(); autoSkipChanged(); persistSkipChanged(); generateAutoSkipTypeList(); diff --git a/IntroSkipper/Helper/LegacyMigrations.cs b/IntroSkipper/Helper/LegacyMigrations.cs index 321b928..7f19000 100644 --- a/IntroSkipper/Helper/LegacyMigrations.cs +++ b/IntroSkipper/Helper/LegacyMigrations.cs @@ -10,6 +10,8 @@ using IntroSkipper.Data; using IntroSkipper.Db; using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Library; +using MediaBrowser.Model.Entities; using MediaBrowser.Model.Updates; using Microsoft.Extensions.Logging; @@ -21,7 +23,8 @@ internal static class LegacyMigrations Plugin plugin, IServerConfigurationManager serverConfiguration, ILogger logger, - IApplicationPaths applicationPaths) + IApplicationPaths applicationPaths, + ILibraryManager libraryManager) { var pluginDirName = "introskipper"; var introPath = Path.Join(applicationPaths.DataPath, pluginDirName, "intros.xml"); @@ -32,6 +35,7 @@ internal static class LegacyMigrations MigrateConfig(plugin, applicationPaths.PluginConfigurationsPath, logger); MigrateRepoUrl(plugin, serverConfiguration, logger); + MigrateSettingsToJellyfin(plugin, logger, libraryManager); InjectSkipButton(plugin, applicationPaths.WebPath, logger); RestoreTimestamps(plugin.DbPath, introPath, creditsPath); } @@ -215,4 +219,45 @@ internal static class LegacyMigrations File.Delete(introPath); File.Delete(creditsPath); } + + private static void MigrateSettingsToJellyfin(Plugin plugin, ILogger logger, ILibraryManager libraryManager) + { + try + { + if (!plugin.Configuration.SelectAllLibraries) + { + logger.LogInformation("Migration of your old library settings to Jellyfin"); + List selectedLibraries = [.. plugin.Configuration.SelectedLibraries.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)]; + foreach (var folder in libraryManager.GetVirtualFolders()) + { + if (!selectedLibraries.Contains(folder.Name) && folder.CollectionType is CollectionTypeOptions.tvshows or CollectionTypeOptions.movies or CollectionTypeOptions.mixed) + { + // only add if not already disabled + if (!folder.LibraryOptions.DisabledMediaSegmentProviders.Contains(plugin.Name)) + { + // ppend in case there other disabled media segment providers + folder.LibraryOptions.DisabledMediaSegmentProviders = [.. folder.LibraryOptions.DisabledMediaSegmentProviders, plugin.Name]; + logger.LogInformation("Disable Media Segment Provider <{Name}> for Library <{Name}>", plugin.Name, folder.Name); + } + } + } + + // reset to default + plugin.Configuration.SelectAllLibraries = true; + plugin.Configuration.SelectedLibraries = string.Empty; + plugin.SaveConfiguration(); + } + } + catch (Exception ex) + { + logger.LogWarning("The migration of your old library settings to Jellyfin has failed: {Exception}", ex); + } + finally + { + // reset to default + plugin.Configuration.SelectAllLibraries = true; + plugin.Configuration.SelectedLibraries = string.Empty; + plugin.SaveConfiguration(); + } + } } diff --git a/IntroSkipper/Manager/QueueManager.cs b/IntroSkipper/Manager/QueueManager.cs index 028587f..67ea90d 100644 --- a/IntroSkipper/Manager/QueueManager.cs +++ b/IntroSkipper/Manager/QueueManager.cs @@ -30,8 +30,6 @@ namespace IntroSkipper.Manager private readonly ILogger _logger = logger; private readonly Dictionary> _queuedEpisodes = []; private double _analysisPercent; - private List _selectedLibraries = []; - private bool _selectAllLibraries; private bool _analyzeMovies; /// @@ -48,9 +46,9 @@ namespace IntroSkipper.Manager foreach (var folder in _libraryManager.GetVirtualFolders()) { // If libraries have been selected for analysis, ensure this library was selected. - if (!_selectAllLibraries && !_selectedLibraries.Contains(folder.Name)) + if (folder.LibraryOptions.DisabledMediaSegmentProviders.Contains(Plugin.Instance.Name)) { - _logger.LogDebug("Not analyzing library \"{Name}\": not selected by user", folder.Name); + _logger.LogDebug("Not analyzing library \"{Name}\": Intro Skipper is disabled in library settings. To enable, check library configuration > Media Segment Providers", folder.Name); continue; } @@ -93,23 +91,8 @@ namespace IntroSkipper.Manager // Store the analysis percent _analysisPercent = Convert.ToDouble(config.AnalysisPercent) / 100; - _selectAllLibraries = config.SelectAllLibraries; - _analyzeMovies = config.AnalyzeMovies; - if (!_selectAllLibraries) - { - // Get the list of library names which have been selected for analysis, ignoring whitespace and empty entries. - _selectedLibraries = [.. config.SelectedLibraries.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)]; - - // If any libraries have been selected for analysis, log their names. - _logger.LogInformation("Limiting analysis to the following libraries: {Selected}", _selectedLibraries); - } - else - { - _logger.LogDebug("Not limiting analysis by library name"); - } - // If analysis settings have been changed from the default, log the modified settings. if (config.AnalysisLengthLimit != 10 || config.AnalysisPercent != 25 || config.MinimumIntroDuration != 15) { diff --git a/IntroSkipper/Plugin.cs b/IntroSkipper/Plugin.cs index 61b3981..d5c05e7 100644 --- a/IntroSkipper/Plugin.cs +++ b/IntroSkipper/Plugin.cs @@ -79,7 +79,7 @@ public class Plugin : BasePlugin, IHasWebPages try { - LegacyMigrations.MigrateAll(this, serverConfiguration, logger, applicationPaths); + LegacyMigrations.MigrateAll(this, serverConfiguration, logger, applicationPaths, _libraryManager); } catch (Exception ex) { diff --git a/IntroSkipper/ScheduledTasks/BaseItemAnalyzerTask.cs b/IntroSkipper/ScheduledTasks/BaseItemAnalyzerTask.cs index 393aaa0..44b81af 100644 --- a/IntroSkipper/ScheduledTasks/BaseItemAnalyzerTask.cs +++ b/IntroSkipper/ScheduledTasks/BaseItemAnalyzerTask.cs @@ -79,8 +79,8 @@ public class BaseItemAnalyzerTask( int totalQueued = queue.Sum(kvp => kvp.Value.Count) * modes.Count; if (totalQueued == 0) { - throw new FingerprintException( - "No libraries selected for analysis. Please visit the plugin settings to configure."); + _logger.LogInformation("No libraries selected for analysis. To enable, check library configuration > Media Segment Providers."); + return; } int totalProcessed = 0;