From cc01c7657da6ae2374918834f4870f2ae26091d2 Mon Sep 17 00:00:00 2001 From: ConfusedPolarBear <33811686+ConfusedPolarBear@users.noreply.github.com> Date: Sun, 6 Nov 2022 21:25:23 -0600 Subject: [PATCH] Add warnings to support bundle --- .../TestWarnings.cs | 34 ++++++++++ .../Analyzers/Chromaprint.cs | 3 +- .../Controllers/TroubleshootingController.cs | 4 ++ .../Data/PluginWarning.cs | 64 +++++++++++++++++++ .../FFmpegWrapper.cs | 5 ++ .../Plugin.cs | 2 +- 6 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 ConfusedPolarBear.Plugin.IntroSkipper.Tests/TestWarnings.cs create mode 100644 ConfusedPolarBear.Plugin.IntroSkipper/Data/PluginWarning.cs diff --git a/ConfusedPolarBear.Plugin.IntroSkipper.Tests/TestWarnings.cs b/ConfusedPolarBear.Plugin.IntroSkipper.Tests/TestWarnings.cs new file mode 100644 index 0000000..ac3f246 --- /dev/null +++ b/ConfusedPolarBear.Plugin.IntroSkipper.Tests/TestWarnings.cs @@ -0,0 +1,34 @@ +namespace ConfusedPolarBear.Plugin.IntroSkipper.Tests; + +using Xunit; + +public class TestFlags +{ + [Fact] + public void TestEmptyFlagSerialization() + { + WarningManager.Clear(); + Assert.Equal("None", WarningManager.GetWarnings()); + } + + [Fact] + public void TestSingleFlagSerialization() + { + WarningManager.Clear(); + WarningManager.SetFlag(PluginWarning.UnableToAddSkipButton); + Assert.Equal("UnableToAddSkipButton", WarningManager.GetWarnings()); + } + + [Fact] + public void TestDoubleFlagSerialization() + { + WarningManager.Clear(); + WarningManager.SetFlag(PluginWarning.UnableToAddSkipButton); + WarningManager.SetFlag(PluginWarning.InvalidChromaprintFingerprint); + WarningManager.SetFlag(PluginWarning.InvalidChromaprintFingerprint); + + Assert.Equal( + "UnableToAddSkipButton, InvalidChromaprintFingerprint", + WarningManager.GetWarnings()); + } +} diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Analyzers/Chromaprint.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Analyzers/Chromaprint.cs index 319d678..73a8eb3 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Analyzers/Chromaprint.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Analyzers/Chromaprint.cs @@ -78,7 +78,8 @@ public ReadOnlyCollection AnalyzeMediaFiles( } catch (FingerprintException ex) { - _logger.LogWarning("Caught fingerprint error: {Ex}", ex); + _logger.LogDebug("Caught fingerprint error: {Ex}", ex); + WarningManager.SetFlag(PluginWarning.InvalidChromaprintFingerprint); // Fallback to an empty fingerprint on any error fingerprintCache[episode.EpisodeId] = Array.Empty(); diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/TroubleshootingController.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/TroubleshootingController.cs index 8923daf..7f7d27d 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/TroubleshootingController.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/TroubleshootingController.cs @@ -58,6 +58,10 @@ public ActionResult GetSupportBundle() bundle.Append(" seasons"); bundle.Append('\n'); + bundle.Append("* Warnings: `"); + bundle.Append(WarningManager.GetWarnings()); + bundle.Append("`\n"); + bundle.Append(FFmpegWrapper.GetChromaprintLogs()); return bundle.ToString(); diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Data/PluginWarning.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Data/PluginWarning.cs new file mode 100644 index 0000000..ebced14 --- /dev/null +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Data/PluginWarning.cs @@ -0,0 +1,64 @@ +namespace ConfusedPolarBear.Plugin.IntroSkipper; + +using System; + +/// +/// Support bundle warning. +/// +[Flags] +public enum PluginWarning +{ + /// + /// No warnings have been added. + /// + None = 0, + + /// + /// Attempted to add skip button to web interface, but was unable to. + /// + UnableToAddSkipButton = 1, + + /// + /// At least one media file on the server was unable to be fingerprinted by Chromaprint. + /// + InvalidChromaprintFingerprint = 2, + + /// + /// The version of ffmpeg installed on the system is not compatible with the plugin. + /// + IncompatibleFFmpegBuild = 4, +} + +/// +/// Warning manager. +/// +public static class WarningManager +{ + private static PluginWarning warnings; + + /// + /// Set warning. + /// + /// Warning. + public static void SetFlag(PluginWarning warning) + { + warnings |= warning; + } + + /// + /// Clear warnings. + /// + public static void Clear() + { + warnings = PluginWarning.None; + } + + /// + /// Get warnings. + /// + /// Warnings. + public static string GetWarnings() + { + return warnings.ToString(); + } +} diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/FFmpegWrapper.cs b/ConfusedPolarBear.Plugin.IntroSkipper/FFmpegWrapper.cs index 86dad74..2751d45 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/FFmpegWrapper.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/FFmpegWrapper.cs @@ -51,6 +51,7 @@ public static bool CheckFFmpegVersion() "Unknown error with FFmpeg version")) { ChromaprintLogs["error"] = "unknown_error"; + WarningManager.SetFlag(PluginWarning.IncompatibleFFmpegBuild); return false; } @@ -62,6 +63,7 @@ public static bool CheckFFmpegVersion() "The installed version of ffmpeg does not support chromaprint")) { ChromaprintLogs["error"] = "chromaprint_not_supported"; + WarningManager.SetFlag(PluginWarning.IncompatibleFFmpegBuild); return false; } @@ -73,6 +75,7 @@ public static bool CheckFFmpegVersion() "The installed version of ffmpeg does not support raw binary fingerprints")) { ChromaprintLogs["error"] = "fp_format_not_supported"; + WarningManager.SetFlag(PluginWarning.IncompatibleFFmpegBuild); return false; } @@ -84,6 +87,7 @@ public static bool CheckFFmpegVersion() "The installed version of ffmpeg does not support the silencedetect filter")) { ChromaprintLogs["error"] = "silencedetect_not_supported"; + WarningManager.SetFlag(PluginWarning.IncompatibleFFmpegBuild); return false; } @@ -94,6 +98,7 @@ public static bool CheckFFmpegVersion() catch { ChromaprintLogs["error"] = "unknown_error"; + WarningManager.SetFlag(PluginWarning.IncompatibleFFmpegBuild); return false; } } diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs index 3c565e0..cf76406 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs @@ -80,7 +80,7 @@ public Plugin( } catch (Exception ex) { - // WarningManager.SetFlag(PluginWarning.UnableToAddSkipButton); + WarningManager.SetFlag(PluginWarning.UnableToAddSkipButton); if (ex is UnauthorizedAccessException) {