mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2026-02-21 11:58:57 -06:00
76 lines
2.4 KiB
C#
76 lines
2.4 KiB
C#
using FileFlows.VideoNodes.FfmpegBuilderNodes.Models;
|
|
|
|
namespace FileFlows.VideoNodes.FfmpegBuilderNodes;
|
|
|
|
public class FfmpegBuilderAudioSetLanguage : FfmpegBuilderNode
|
|
{
|
|
public override string HelpUrl => "https://fileflows.com/docs/plugins/video-nodes/ffmpeg-builder/set-language";
|
|
|
|
public override int Outputs => 2;
|
|
|
|
public override string Icon => "fas fa-comment-dots";
|
|
|
|
|
|
[Select(nameof(StreamTypeOptions), 1)]
|
|
public string StreamType { get; set; }
|
|
|
|
[Required]
|
|
[TextVariable(2)]
|
|
public string Language { get; set; }
|
|
|
|
private static List<ListOption> _StreamTypeOptions;
|
|
public static List<ListOption> StreamTypeOptions
|
|
{
|
|
get
|
|
{
|
|
if (_StreamTypeOptions == null)
|
|
{
|
|
_StreamTypeOptions = new List<ListOption>
|
|
{
|
|
new () { Label = "Audio", Value = "Audio" },
|
|
new () { Label = "Subtitle", Value = "Subtitle" },
|
|
new () { Label = "Both", Value = "Both" },
|
|
};
|
|
}
|
|
return _StreamTypeOptions;
|
|
}
|
|
}
|
|
|
|
public override int Execute(NodeParameters args)
|
|
{
|
|
bool changes = false;
|
|
string language = args.ReplaceVariables(Language, stripMissing: true)?.ToLowerInvariant();
|
|
if (string.IsNullOrWhiteSpace(language))
|
|
{
|
|
args.Logger?.WLog("No language set");
|
|
return 2;
|
|
}
|
|
if (StreamType == "Subtitle" || StreamType == "Both")
|
|
{
|
|
foreach (var at in Model.SubtitleStreams)
|
|
{
|
|
if (string.IsNullOrEmpty(at.Language))
|
|
{
|
|
at.Language = language;
|
|
at.ForcedChange = true; // this will ensure the language is set even if there are no changes anywhere else
|
|
changes = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(string.IsNullOrEmpty(StreamType) || StreamType == "Both" || StreamType == "Audio")
|
|
{
|
|
foreach (var at in Model.AudioStreams)
|
|
{
|
|
if (string.IsNullOrEmpty(at.Language))
|
|
{
|
|
at.Language = Language.ToLower();
|
|
at.ForcedChange = true; // this will ensure the language is set even if there are no changes anywhere else
|
|
changes = true;
|
|
}
|
|
}
|
|
}
|
|
return changes ? 1 : 2;
|
|
}
|
|
}
|