66 lines
2.7 KiB
C#
66 lines
2.7 KiB
C#
using EmbyToolbox.Models;
|
|
|
|
namespace EmbyToolbox.Services;
|
|
|
|
public sealed class ProfileOverrideBuilder
|
|
{
|
|
public EffectiveProfileSettings Build(
|
|
ConversionProfileSettingsEntry source,
|
|
ConversionProfileSettingsEntry formValues,
|
|
string sourceProfileName)
|
|
{
|
|
var changed = new List<string>();
|
|
AddIfChanged(changed, "Container", source.Container, formValues.Container);
|
|
AddIfChanged(changed, "Video", source.Video, formValues.Video);
|
|
AddIfChanged(changed, "PixelFormat", source.PixelFormat, formValues.PixelFormat);
|
|
AddIfChanged(changed, "Resolution", source.Resolution, formValues.Resolution);
|
|
AddIfChanged(changed, "Fps", source.Fps, formValues.Fps);
|
|
AddIfChanged(changed, "Audio", source.Audio, formValues.Audio);
|
|
AddIfChanged(changed, "Bitrate", source.Bitrate, formValues.Bitrate);
|
|
AddIfChanged(changed, "VideoBitrateMode", source.VideoBitrateMode, formValues.VideoBitrateMode);
|
|
if (source.VideoBitrateMbps != formValues.VideoBitrateMbps)
|
|
{
|
|
changed.Add("VideoBitrateMbps");
|
|
}
|
|
|
|
AddIfChanged(changed, "Subtitles", source.Subtitles, formValues.Subtitles);
|
|
AddIfChanged(changed, "ExternalTracks", source.ExternalTracks, formValues.ExternalTracks);
|
|
AddIfChanged(changed, "ExternalSubtitles", source.ExternalSubtitles, formValues.ExternalSubtitles);
|
|
AddIfChanged(changed, "Fonts", source.Fonts, formValues.Fonts);
|
|
|
|
return new EffectiveProfileSettings
|
|
{
|
|
SourceProfileName = sourceProfileName,
|
|
Profile = Clone(formValues, sourceProfileName),
|
|
ChangedFields = changed
|
|
};
|
|
}
|
|
|
|
public static ConversionProfileSettingsEntry Clone(ConversionProfileSettingsEntry source, string? profileName = null) =>
|
|
new()
|
|
{
|
|
Profile = string.IsNullOrWhiteSpace(profileName) ? source.Profile : profileName!,
|
|
Container = source.Container,
|
|
Video = source.Video,
|
|
PixelFormat = source.PixelFormat,
|
|
Resolution = source.Resolution,
|
|
Fps = source.Fps,
|
|
Audio = source.Audio,
|
|
Bitrate = source.Bitrate,
|
|
VideoBitrateMode = source.VideoBitrateMode,
|
|
VideoBitrateMbps = source.VideoBitrateMbps,
|
|
Subtitles = source.Subtitles,
|
|
ExternalTracks = source.ExternalTracks,
|
|
ExternalSubtitles = source.ExternalSubtitles,
|
|
Fonts = source.Fonts
|
|
};
|
|
|
|
private static void AddIfChanged(List<string> changed, string name, string? source, string? value)
|
|
{
|
|
if (!string.Equals(source?.Trim(), value?.Trim(), StringComparison.Ordinal))
|
|
{
|
|
changed.Add(name);
|
|
}
|
|
}
|
|
}
|