diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Jellyfin.LiveTv/Listings/SchedulesDirectDtos/ImageDataArrayConverter.cs | 42 | ||||
| -rw-r--r-- | src/Jellyfin.LiveTv/Listings/SchedulesDirectDtos/ShowImagesDto.cs | 1 |
2 files changed, 43 insertions, 0 deletions
diff --git a/src/Jellyfin.LiveTv/Listings/SchedulesDirectDtos/ImageDataArrayConverter.cs b/src/Jellyfin.LiveTv/Listings/SchedulesDirectDtos/ImageDataArrayConverter.cs new file mode 100644 index 0000000000..cb5ea1e684 --- /dev/null +++ b/src/Jellyfin.LiveTv/Listings/SchedulesDirectDtos/ImageDataArrayConverter.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Jellyfin.LiveTv.Listings.SchedulesDirectDtos; + +/// <summary> +/// Converter for the <c>data</c> field in SD image responses. +/// The Schedules Direct API may return a non-array value (e.g. a string error message) +/// instead of the expected image data array for programs with errors. +/// This converter returns an empty list for any non-array value. +/// </summary> +public sealed class ImageDataArrayConverter : JsonConverter<IReadOnlyList<ImageDataDto>> +{ + /// <inheritdoc /> + public override IReadOnlyList<ImageDataDto> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType == JsonTokenType.StartArray) + { + var result = new List<ImageDataDto>(); + while (reader.Read() && reader.TokenType != JsonTokenType.EndArray) + { + var item = JsonSerializer.Deserialize<ImageDataDto>(ref reader, options); + if (item is not null) + { + result.Add(item); + } + } + + return result; + } + + // Not an array (string error, null, object, etc.) — skip and return empty. + reader.Skip(); + return []; + } + + /// <inheritdoc /> + public override void Write(Utf8JsonWriter writer, IReadOnlyList<ImageDataDto> value, JsonSerializerOptions options) + => JsonSerializer.Serialize(writer, value, options); +} diff --git a/src/Jellyfin.LiveTv/Listings/SchedulesDirectDtos/ShowImagesDto.cs b/src/Jellyfin.LiveTv/Listings/SchedulesDirectDtos/ShowImagesDto.cs index 523900a96a..8db75ef0b5 100644 --- a/src/Jellyfin.LiveTv/Listings/SchedulesDirectDtos/ShowImagesDto.cs +++ b/src/Jellyfin.LiveTv/Listings/SchedulesDirectDtos/ShowImagesDto.cs @@ -19,6 +19,7 @@ namespace Jellyfin.LiveTv.Listings.SchedulesDirectDtos /// Gets or sets the list of data. /// </summary> [JsonPropertyName("data")] + [JsonConverter(typeof(ImageDataArrayConverter))] public IReadOnlyList<ImageDataDto> Data { get; set; } = Array.Empty<ImageDataDto>(); } } |
