mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-02-10 22:52:25 +00:00
Improve ffprobe json parsing and don't log error for Codec Type attachment
This commit is contained in:
@@ -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);
|
||||
}
|
||||
@@ -39,7 +39,6 @@ namespace Jellyfin.Extensions.Json
|
||||
new JsonFlagEnumConverterFactory(),
|
||||
new JsonStringEnumConverter(),
|
||||
new JsonNullableStructConverterFactory(),
|
||||
new JsonBoolNumberConverter(),
|
||||
new JsonDateTimeConverter(),
|
||||
new JsonStringConverter()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user