Improve ffprobe json parsing and don't log error for Codec Type attachment

This commit is contained in:
Bond_009
2023-02-01 14:58:04 +01:00
parent 992b460912
commit 65d605b17d
11 changed files with 169 additions and 96 deletions

View File

@@ -0,0 +1,34 @@
using System;
using System.Buffers;
using System.Buffers.Text;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Jellyfin.Extensions.Json.Converters;
/// <summary>
/// Converts a string to a boolean.
/// This is needed for FFprobe.
/// </summary>
public class JsonBoolStringConverter : JsonConverter<bool>
{
/// <inheritdoc />
public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.String)
{
ReadOnlySpan<byte> utf8Span = reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan;
if (Utf8Parser.TryParse(utf8Span, out bool val, out _, 'l'))
{
return val;
}
}
return reader.GetBoolean();
}
/// <inheritdoc />
public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options)
=> writer.WriteBooleanValue(value);
}

View File

@@ -39,7 +39,6 @@ namespace Jellyfin.Extensions.Json
new JsonFlagEnumConverterFactory(),
new JsonStringEnumConverter(),
new JsonNullableStructConverterFactory(),
new JsonBoolNumberConverter(),
new JsonDateTimeConverter(),
new JsonStringConverter()
}