From 0841f1ba40a988875a22bb72b5e3b03b2ec64f81 Mon Sep 17 00:00:00 2001 From: Kilian von Pflugk Date: Sat, 5 Oct 2024 18:38:42 +0200 Subject: [PATCH] InjectSkipButton: try to read webVersion from jellyfin-web (#323) * InjectSkipButton: try to read webVersion from jellyfin-web * use correct regex * use break * compare against jellyfin version not the plugin version * append Revision * output if version match * sound more urgent and tragic --- .../Plugin.cs | 52 +++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs index 87b5ca4..55d457d 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Text.RegularExpressions; using ConfusedPolarBear.Plugin.IntroSkipper.Configuration; using ConfusedPolarBear.Plugin.IntroSkipper.Data; +using MediaBrowser.Common; using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Plugins; using MediaBrowser.Controller.Configuration; @@ -28,6 +29,7 @@ public class Plugin : BasePlugin, IHasWebPages private readonly object _introsLock = new(); private readonly ILibraryManager _libraryManager; private readonly IItemRepository _itemRepository; + private readonly IApplicationHost _applicationHost; private readonly ILogger _logger; private readonly string _introPath; private readonly string _creditsPath; @@ -36,6 +38,7 @@ public class Plugin : BasePlugin, IHasWebPages /// /// Initializes a new instance of the class. /// + /// Application host. /// Instance of the interface. /// Instance of the interface. /// Server configuration manager. @@ -43,6 +46,7 @@ public class Plugin : BasePlugin, IHasWebPages /// Item repository. /// Logger. public Plugin( + IApplicationHost applicationHost, IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer, IServerConfigurationManager serverConfiguration, @@ -53,6 +57,7 @@ public class Plugin : BasePlugin, IHasWebPages { Instance = this; + _applicationHost = applicationHost; _libraryManager = libraryManager; _itemRepository = itemRepository; _logger = logger; @@ -400,9 +405,50 @@ public class Plugin : BasePlugin, IHasWebPages /// Full path to index.html. private void InjectSkipButton(string webPath) { - // search for controllers/playback/video/index.html - string searchPattern = "playback-video-index-html.*.chunk.js"; + string searchPattern = "dashboard-dashboard.*.chunk.js"; string[] filePaths = Directory.GetFiles(webPath, searchPattern, SearchOption.TopDirectoryOnly); + string pattern = @"buildVersion""\)\.innerText=""(?\d+\.\d+\.\d+)"",.*?webVersion""\)\.innerText=""(?\d+\.\d+\.\d+)"; + string buildVersionString = "unknow"; + string webVersionString = "unknow"; + // Create a Regex object + Regex regex = new Regex(pattern); + + // should be only one file but this safer + foreach (var file in filePaths) + { + string dashBoardText = File.ReadAllText(file); + // Perform the match + Match match = regex.Match(dashBoardText); + // search for buildVersion and webVersion + if (match.Success) + { + buildVersionString = match.Groups["buildVersion"].Value; + webVersionString = match.Groups["webVersion"].Value; + _logger.LogInformation("Found jellyfin-web <{WebVersion}>", webVersionString); + break; + } + } + + if (webVersionString != "unknow") + { + // append Revision + webVersionString += ".0"; + if (Version.TryParse(webVersionString, out var webversion)) + { + if (_applicationHost.ApplicationVersion != webversion) + { + _logger.LogWarning("The jellyfin-web <{WebVersion}> NOT compatible with Jellyfin <{JellyfinVersion}>", webVersionString, _applicationHost.ApplicationVersion); + } + else + { + _logger.LogInformation("The jellyfin-web <{WebVersion}> compatible with Jellyfin <{JellyfinVersion}>", webVersionString, _applicationHost.ApplicationVersion); + } + } + } + + // search for controllers/playback/video/index.html + searchPattern = "playback-video-index-html.*.chunk.js"; + filePaths = Directory.GetFiles(webPath, searchPattern, SearchOption.TopDirectoryOnly); // should be only one file but this safer foreach (var file in filePaths) @@ -435,7 +481,7 @@ public class Plugin : BasePlugin, IHasWebPages } // remove old version if necessary - string pattern = @"