From 73287b79a555c9289d2488c835e68f46271c7598 Mon Sep 17 00:00:00 2001 From: Kilian von Pflugk Date: Sat, 12 Oct 2024 16:13:37 +0200 Subject: [PATCH] migrate own repo url (#345) --- .../Plugin.cs | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs index 7a88220..7050830 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs @@ -16,6 +16,7 @@ using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Plugins; using MediaBrowser.Model.Serialization; +using MediaBrowser.Model.Updates; using Microsoft.Extensions.Logging; namespace ConfusedPolarBear.Plugin.IntroSkipper; @@ -85,6 +86,8 @@ public class Plugin : BasePlugin, IHasWebPages XmlSerializationHelper.MigrateXML(_introPath); XmlSerializationHelper.MigrateXML(_creditsPath); + MigrateRepoUrl(serverConfiguration); + // TODO: remove when https://github.com/jellyfin/jellyfin-meta/discussions/30 is complete try { @@ -405,6 +408,52 @@ public class Plugin : BasePlugin, IHasWebPages SaveTimestamps(AnalysisMode.Credits); } + private void MigrateRepoUrl(IServerConfigurationManager serverConfiguration) + { + try + { + List oldRepos = + [ + "https://raw.githubusercontent.com/intro-skipper/intro-skipper/master/manifest.json", + "https://raw.githubusercontent.com/jumoog/intro-skipper/master/manifest.json" + ]; + // Access the current server configuration + var config = serverConfiguration.Configuration; + + // Get the list of current plugin repositories + var pluginRepositories = config.PluginRepositories?.ToList() ?? []; + + // check if old plugins exits + if (pluginRepositories.Exists(repo => repo != null && repo.Url != null && oldRepos.Contains(repo.Url))) + { + // remove all old plugins + pluginRepositories.RemoveAll(repo => repo != null && repo.Url != null && oldRepos.Contains(repo.Url)); + + // Add repository only if it does not exit + if (!pluginRepositories.Exists(repo => repo.Url == "https://manifest.intro-skipper.workers.dev/manifest.json")) + { + // Add the new repository to the list + pluginRepositories.Add(new RepositoryInfo + { + Name = "intro skipper (automatically migrated by plugin)", + Url = "https://manifest.intro-skipper.workers.dev/manifest.json", + Enabled = true, + }); + } + + // Update the configuration with the new repository list + config.PluginRepositories = [.. pluginRepositories]; + + // Save the updated configuration + serverConfiguration.SaveConfiguration(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Error occurred while migrating repo URL"); + } + } + /// /// Inject the skip button script into the web interface. ///