diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs index ba28838..de18c71 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs @@ -12,6 +12,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; @@ -118,6 +119,8 @@ public class Plugin : BasePlugin, IHasWebPages ConfigurationChanged += OnConfigurationChanged; + MigrateRepoUrl(serverConfiguration); + // TODO: remove when https://github.com/jellyfin/jellyfin-meta/discussions/30 is complete try { @@ -395,6 +398,52 @@ public class Plugin : BasePlugin, IHasWebPages AutoSkipCreditsChanged?.Invoke(this, EventArgs.Empty); } + 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. ///