Add warnings to support bundle

This commit is contained in:
ConfusedPolarBear 2022-11-06 21:25:23 -06:00
parent f4e84d4d07
commit cc01c7657d
6 changed files with 110 additions and 2 deletions

View File

@ -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());
}
}

View File

@ -78,7 +78,8 @@ public class ChromaprintAnalyzer : IMediaFileAnalyzer
} }
catch (FingerprintException ex) 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 // Fallback to an empty fingerprint on any error
fingerprintCache[episode.EpisodeId] = Array.Empty<uint>(); fingerprintCache[episode.EpisodeId] = Array.Empty<uint>();

View File

@ -58,6 +58,10 @@ public class TroubleshootingController : ControllerBase
bundle.Append(" seasons"); bundle.Append(" seasons");
bundle.Append('\n'); bundle.Append('\n');
bundle.Append("* Warnings: `");
bundle.Append(WarningManager.GetWarnings());
bundle.Append("`\n");
bundle.Append(FFmpegWrapper.GetChromaprintLogs()); bundle.Append(FFmpegWrapper.GetChromaprintLogs());
return bundle.ToString(); return bundle.ToString();

View File

@ -0,0 +1,64 @@
namespace ConfusedPolarBear.Plugin.IntroSkipper;
using System;
/// <summary>
/// Support bundle warning.
/// </summary>
[Flags]
public enum PluginWarning
{
/// <summary>
/// No warnings have been added.
/// </summary>
None = 0,
/// <summary>
/// Attempted to add skip button to web interface, but was unable to.
/// </summary>
UnableToAddSkipButton = 1,
/// <summary>
/// At least one media file on the server was unable to be fingerprinted by Chromaprint.
/// </summary>
InvalidChromaprintFingerprint = 2,
/// <summary>
/// The version of ffmpeg installed on the system is not compatible with the plugin.
/// </summary>
IncompatibleFFmpegBuild = 4,
}
/// <summary>
/// Warning manager.
/// </summary>
public static class WarningManager
{
private static PluginWarning warnings;
/// <summary>
/// Set warning.
/// </summary>
/// <param name="warning">Warning.</param>
public static void SetFlag(PluginWarning warning)
{
warnings |= warning;
}
/// <summary>
/// Clear warnings.
/// </summary>
public static void Clear()
{
warnings = PluginWarning.None;
}
/// <summary>
/// Get warnings.
/// </summary>
/// <returns>Warnings.</returns>
public static string GetWarnings()
{
return warnings.ToString();
}
}

View File

@ -51,6 +51,7 @@ public static class FFmpegWrapper
"Unknown error with FFmpeg version")) "Unknown error with FFmpeg version"))
{ {
ChromaprintLogs["error"] = "unknown_error"; ChromaprintLogs["error"] = "unknown_error";
WarningManager.SetFlag(PluginWarning.IncompatibleFFmpegBuild);
return false; return false;
} }
@ -62,6 +63,7 @@ public static class FFmpegWrapper
"The installed version of ffmpeg does not support chromaprint")) "The installed version of ffmpeg does not support chromaprint"))
{ {
ChromaprintLogs["error"] = "chromaprint_not_supported"; ChromaprintLogs["error"] = "chromaprint_not_supported";
WarningManager.SetFlag(PluginWarning.IncompatibleFFmpegBuild);
return false; return false;
} }
@ -73,6 +75,7 @@ public static class FFmpegWrapper
"The installed version of ffmpeg does not support raw binary fingerprints")) "The installed version of ffmpeg does not support raw binary fingerprints"))
{ {
ChromaprintLogs["error"] = "fp_format_not_supported"; ChromaprintLogs["error"] = "fp_format_not_supported";
WarningManager.SetFlag(PluginWarning.IncompatibleFFmpegBuild);
return false; return false;
} }
@ -84,6 +87,7 @@ public static class FFmpegWrapper
"The installed version of ffmpeg does not support the silencedetect filter")) "The installed version of ffmpeg does not support the silencedetect filter"))
{ {
ChromaprintLogs["error"] = "silencedetect_not_supported"; ChromaprintLogs["error"] = "silencedetect_not_supported";
WarningManager.SetFlag(PluginWarning.IncompatibleFFmpegBuild);
return false; return false;
} }
@ -94,6 +98,7 @@ public static class FFmpegWrapper
catch catch
{ {
ChromaprintLogs["error"] = "unknown_error"; ChromaprintLogs["error"] = "unknown_error";
WarningManager.SetFlag(PluginWarning.IncompatibleFFmpegBuild);
return false; return false;
} }
} }

View File

@ -80,7 +80,7 @@ public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
} }
catch (Exception ex) catch (Exception ex)
{ {
// WarningManager.SetFlag(PluginWarning.UnableToAddSkipButton); WarningManager.SetFlag(PluginWarning.UnableToAddSkipButton);
if (ex is UnauthorizedAccessException) if (ex is UnauthorizedAccessException)
{ {