diff --git a/MusicNodes/MusicNodes.csproj b/MusicNodes/MusicNodes.csproj index c1339968..42ce300f 100644 Binary files a/MusicNodes/MusicNodes.csproj and b/MusicNodes/MusicNodes.csproj differ diff --git a/MusicNodes/MusicNodes.en.json b/MusicNodes/MusicNodes.en.json index c90305a4..5372f702 100644 --- a/MusicNodes/MusicNodes.en.json +++ b/MusicNodes/MusicNodes.en.json @@ -2,10 +2,31 @@ "Flow":{ "Parts": { "MusicFile": { - "Description": "An input music file that has had its MusicInformation read and can be processed" + "Description": "An input music file that has had its MusicInformation read and can be processed", + "Outputs": { + "1": "Music file from library" + } + }, + "ConvertAudio": { + "Description": "Convert a music file to the specified audio codec", + "Outputs": { + "1": "Audio converted and saved to temporary file", + "2": "Audio already in codec, no conversion done" + }, + "Fields": { + "Bitrate": "Bitrate", + "Bitrate-Help": "The bitrate for the new file, the higher the bitrate the better the quality but larger the file.", + "Codec": "Codec", + "Codec-Help": "The audio codec to convert the file into.", + "SkipIfCodecMatches": "Skip If Codec Matches", + "SkipIfCodecMatches-Help": "If the existing audio codec matches, this file will not be processed regardless of the bitrate. Otherwise if off, the bitrate must be less than or equal to for it to skip." + } }, "ConvertToAAC": { "Description": "Convert a music file to AAC", + "Outputs": { + "1": "Audio converted and saved to temporary file" + }, "Fields": { "Bitrate": "Bitrate", "Bitrate-Help": "The bitrate for the new AAC file, the higher the bitrate the better the quality but larger the file. 192 Kbps is the recommended rate." @@ -13,6 +34,9 @@ }, "ConvertToFLAC": { "Description": "Convert a music file to FLAC", + "Outputs": { + "1": "Audio converted and saved to temporary file" + }, "Fields": { "Bitrate": "Bitrate", "Bitrate-Help": "The bitrate for the new FLAC file, the higher the bitrate the better the quality but larger the file. 128 Kbps is the recommended rate." @@ -20,6 +44,9 @@ }, "ConvertToMP3": { "Description": "Convert a music file to MP3", + "Outputs": { + "1": "Audio converted and saved to temporary file" + }, "Fields": { "Bitrate": "Bitrate", "Bitrate-Help": "The bitrate for the new MP3 file, the higher the bitrate the better the quality but larger the file. 192 Kbps is the recommended rate." @@ -27,6 +54,9 @@ }, "ConvertToOGG": { "Description": "Convert a music file to OGG", + "Outputs": { + "1": "Audio converted and saved to temporary file" + }, "Fields": { "Bitrate": "Bitrate", "Bitrate-Help": "The bitrate for the new OGG file, the higher the bitrate the better the quality but larger the file. 128 Kbps is the recommended rate." @@ -34,6 +64,9 @@ }, "ConvertToWAV": { "Description": "Convert a music file to WAV", + "Outputs": { + "1": "Audio converted and saved to temporary file" + }, "Fields": { "Bitrate": "Bitrate", "Bitrate-Help": "The bitrate for the new WAV file, the higher the bitrate the better the quality but larger the file. 128 Kbps is the recommended rate." diff --git a/MusicNodes/Nodes/ConvertNode.cs b/MusicNodes/Nodes/ConvertNode.cs index 26af603f..0a2619d8 100644 --- a/MusicNodes/Nodes/ConvertNode.cs +++ b/MusicNodes/Nodes/ConvertNode.cs @@ -90,6 +90,64 @@ namespace FileFlows.MusicNodes // } //} + public class ConvertAudio : ConvertNode + { + protected override string Extension => Codec; + + public static List BitrateOptions => ConvertNode.BitrateOptions; + + [Select(nameof(CodecOptions), 0)] + public string Codec { get; set; } + + [Boolean(3)] + public bool SkipIfCodecMatches { get; set; } + + public override int Outputs => 2; + + private static List _CodecOptions; + public static List CodecOptions + { + get + { + if (_CodecOptions == null) + { + _CodecOptions = new List + { + new ListOption { Label = "AAC", Value = "aac"}, + new ListOption { Label = "MP3", Value = "MP3"}, + new ListOption { Label = "OGG", Value = "ogg"}, + new ListOption { Label = "WAV", Value = "wav"}, + }; + } + return _CodecOptions; + } + } + + public override int Execute(NodeParameters args) + { + MusicInfo musicInfo = GetMusicInfo(args); + if (musicInfo == null) + return -1; + + if(musicInfo.Codec?.ToLower() == Codec?.ToLower()) + { + if (SkipIfCodecMatches) + { + args.Logger?.ILog($"Music file already '{Codec}' at bitrate '{musicInfo.BitRate}', and set to skip if codec matches"); + return 2; + } + + if(musicInfo.BitRate <= Bitrate) + { + args.Logger?.ILog($"Music file already '{Codec}' at bitrate '{musicInfo.BitRate}'"); + return 2; + } + } + return base.Execute(args); + + } + } + public abstract class ConvertNode:MusicNode { protected abstract string Extension { get; }