Skip to content

Commit

Permalink
Add warnings to support bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
ConfusedPolarBear committed Nov 11, 2022
1 parent f4e84d4 commit cc01c76
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 2 deletions.
34 changes: 34 additions & 0 deletions ConfusedPolarBear.Plugin.IntroSkipper.Tests/TestWarnings.cs
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public ReadOnlyCollection<QueuedEpisode> 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<uint>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public ActionResult<string> GetSupportBundle()
bundle.Append(" seasons");
bundle.Append('\n');

bundle.Append("* Warnings: `");
bundle.Append(WarningManager.GetWarnings());
bundle.Append("`\n");

bundle.Append(FFmpegWrapper.GetChromaprintLogs());

return bundle.ToString();
Expand Down
64 changes: 64 additions & 0 deletions ConfusedPolarBear.Plugin.IntroSkipper/Data/PluginWarning.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
5 changes: 5 additions & 0 deletions ConfusedPolarBear.Plugin.IntroSkipper/FFmpegWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public static bool CheckFFmpegVersion()
"Unknown error with FFmpeg version"))
{
ChromaprintLogs["error"] = "unknown_error";
WarningManager.SetFlag(PluginWarning.IncompatibleFFmpegBuild);
return false;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -94,6 +98,7 @@ public static bool CheckFFmpegVersion()
catch
{
ChromaprintLogs["error"] = "unknown_error";
WarningManager.SetFlag(PluginWarning.IncompatibleFFmpegBuild);
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public Plugin(
}
catch (Exception ex)
{
// WarningManager.SetFlag(PluginWarning.UnableToAddSkipButton);
WarningManager.SetFlag(PluginWarning.UnableToAddSkipButton);

if (ex is UnauthorizedAccessException)
{
Expand Down

0 comments on commit cc01c76

Please sign in to comment.