From a98525ddaada663e41ad020243a1f7030ab13844 Mon Sep 17 00:00:00 2001 From: rlauu <46294892+rlauu@users.noreply.github.com> Date: Mon, 18 Mar 2024 19:52:57 +0100 Subject: [PATCH] move plugin cache into jellyfins cache Enhance the organization of the introskipper plugin by relocating its data into Jellyfin's cache directory, aligning it with most plugins. Create a dedicated directory within Jellyfin's cache directory to store introskipper data. Move existing introskipper data files, including intros.xml and credits.xml, to the new cache directory. --- .../Plugin.cs | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs index 8f1c015..867ade4 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs @@ -30,6 +30,9 @@ public class Plugin : BasePlugin, IHasWebPages private ILogger _logger; private string _introPath; private string _creditsPath; + private string _oldintroPath; + private string _oldcreditsPath; + private string _oldFingerprintCachePath; /// /// Initializes a new instance of the class. @@ -58,15 +61,38 @@ public class Plugin : BasePlugin, IHasWebPages FFmpegPath = serverConfiguration.GetEncodingOptions().EncoderAppPathDisplay; - var introsDirectory = Path.Join(applicationPaths.PluginConfigurationsPath, "intros"); - FingerprintCachePath = Path.Join(introsDirectory, "cache"); - _introPath = Path.Join(applicationPaths.PluginConfigurationsPath, "intros", "intros.xml"); - _creditsPath = Path.Join(applicationPaths.PluginConfigurationsPath, "intros", "credits.xml"); + var introsDirectory = Path.Join(applicationPaths.CachePath, "introskipper"); + FingerprintCachePath = Path.Join(introsDirectory, "chromaprints"); + _introPath = Path.Join(applicationPaths.CachePath, "introskipper", "intros.xml"); + _creditsPath = Path.Join(applicationPaths.CachePath, "introskipper", "credits.xml"); + + var oldintrosDirectory = Path.Join(applicationPaths.PluginConfigurationsPath, "intros"); + _oldFingerprintCachePath = Path.Join(oldintrosDirectory, "cache"); + _oldintroPath = Path.Join(applicationPaths.PluginConfigurationsPath, "intros", "intros.xml"); + _oldcreditsPath = Path.Join(applicationPaths.PluginConfigurationsPath, "intros", "credits.xml"); // Create the base & cache directories (if needed). if (!Directory.Exists(FingerprintCachePath)) { Directory.CreateDirectory(FingerprintCachePath); + + // Check if the old cache directory exists + if (Directory.Exists(_oldFingerprintCachePath)) + { + // Move the contents from old directory to new directory + File.Move(_oldintroPath, _introPath); + File.Move(_oldcreditsPath, _creditsPath); + string[] files = Directory.GetFiles(_oldFingerprintCachePath); + foreach (string file in files) + { + string fileName = Path.GetFileName(file); + string destFile = Path.Combine(FingerprintCachePath, fileName); + File.Move(file, destFile); + } + + // Optionally, you may delete the old directory after moving its contents + Directory.Delete(oldintrosDirectory, true); + } } ConfigurationChanged += OnConfigurationChanged;