fix(config): read an unusable encoding.xml EncoderPreset as the default
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/pr/ci Pipeline was successful

An element the enum cannot parse throws, and the configuration manager
catches that and returns defaults, so one bad preset discarded every other
encoding setting.

- serialize EncoderPreset through a string surrogate in XML
- fall back to auto for an empty, unknown or out-of-range value
This commit is contained in:
2026-09-12 16:26:01 +10:00
parent dcb6ae396c
commit 3b60289502
2 changed files with 74 additions and 0 deletions
@@ -1,7 +1,10 @@
#pragma warning disable CA1819 // XML serialization handles collections improperly, so we need to use arrays
#nullable disable
using System;
using System.ComponentModel;
using System.Text.Json.Serialization;
using System.Xml.Serialization;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Model.Configuration;
@@ -234,8 +237,27 @@ public class EncodingOptions
/// <summary>
/// Gets or sets the encoder preset.
/// </summary>
[XmlIgnore]
public EncoderPreset EncoderPreset { get; set; }
/// <summary>
/// Gets or sets the encoder preset as it is stored in the configuration file. Files written before the preset
/// list was validated can carry an empty element, which has to read back as the default rather than throw and
/// take the rest of the configuration down with it.
/// </summary>
[JsonIgnore]
[XmlElement(nameof(EncoderPreset))]
public string EncoderPresetXml
{
get => EncoderPreset.ToString();
// TryParse also accepts a number, which would yield a preset value nothing maps to, so the result has to be
// a declared one.
set => EncoderPreset = Enum.TryParse<EncoderPreset>(value, true, out var encoderPreset) && Enum.IsDefined(encoderPreset)
? encoderPreset
: EncoderPreset.auto;
}
/// <summary>
/// Gets or sets a value indicating whether the framerate is doubled when deinterlacing.
/// </summary>