added loggin to convert audio

This commit is contained in:
john
2023-01-16 07:27:52 +13:00
parent 0de21274c5
commit aaa576f776
3 changed files with 108 additions and 77 deletions

View File

@@ -41,7 +41,7 @@ namespace FileFlows.AudioNodes
}
private const string Audio_INFO = "AudioInfo";
protected void SetAudioInfo(NodeParameters args, AudioInfo AudioInfo, Dictionary<string, object> variables)
internal void SetAudioInfo(NodeParameters args, AudioInfo AudioInfo, Dictionary<string, object> variables)
{
if (args.Parameters.ContainsKey(Audio_INFO))
args.Parameters[Audio_INFO] = AudioInfo;
@@ -129,7 +129,6 @@ namespace FileFlows.AudioNodes
protected bool ReadAudioFileInfo(NodeParameters args, string ffmpegExe, string filename)
{
var AudioInfo = new AudioInfoHelper(ffmpegExe, args.Logger).Read(filename);
if (AudioInfo.Duration == 0)
{

View File

@@ -159,10 +159,10 @@ namespace FileFlows.AudioNodes
{
_CodecOptions = new List<ListOption>
{
new ListOption { Label = "AAC", Value = "aac"},
new ListOption { Label = "MP3", Value = "MP3"},
new ListOption { Label = "OGG", Value = "ogg"},
new ListOption { Label = "WAV", Value = "wav"},
new () { Label = "AAC", Value = "aac"},
new () { Label = "MP3", Value = "MP3"},
new () { Label = "OGG", Value = "ogg"},
new () { Label = "WAV", Value = "wav"},
};
}
return _CodecOptions;
@@ -215,9 +215,10 @@ namespace FileFlows.AudioNodes
return 2;
}
args.Logger?.ILog($"Comparing bitrate {AudioInfo.Bitrate} is less than or equal to {(Bitrate * 1024)}");
if(AudioInfo.Bitrate <= Bitrate * 1024) // this bitrate is in Kbps, whereas AudioInfo.Bitrate is bytes per second
{
args.Logger?.ILog($"Audio file already '{Codec}' at bitrate '{AudioInfo.Bitrate} bps'");
args.Logger?.ILog($"Audio file already '{Codec}' at bitrate '{AudioInfo.Bitrate} bps ({(AudioInfo.Bitrate / 1024)} KiBps)'");
return 2;
}
}

View File

@@ -1,91 +1,122 @@
#if(DEBUG)
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace FileFlows.AudioNodes.Tests
namespace FileFlows.AudioNodes.Tests;
[TestClass]
public class AudioInfoTests
{
using FileFlows.AudioNodes;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
[TestClass]
public class AudioInfoTests
const string file = @"/home/john/Music/test/test.mp3";
readonly string ffmpegExe = (OperatingSystem.IsLinux() ? "/usr/bin/ffmpeg" : @"C:\utils\ffmpeg\ffmpeg.exe");
[TestMethod]
public void AudioInfo_SplitTrack()
{
[TestMethod]
public void AudioInfo_SplitTrack()
var args = new FileFlows.Plugin.NodeParameters(file, new TestLogger(), false, string.Empty);
args.GetToolPathActual = (string tool) => ffmpegExe;
args.TempPath = @"D:\music\temp";
var AudioInfo = new AudioInfoHelper(ffmpegExe, args.Logger).Read(args.WorkingFile);
Assert.AreEqual(9, AudioInfo.Track);
}
[TestMethod]
public void AudioInfo_NormalTrack()
{
const string file = @"\\oracle\Audio\Taylor Swift\Speak Now\Taylor Swift - Speak Now - 08 - Never Grow Up.mp3";
const string ffmpegExe = @"C:\utils\ffmpeg\ffmpeg.exe";
var args = new FileFlows.Plugin.NodeParameters(file, new TestLogger(), false, string.Empty);
args.GetToolPathActual = (string tool) => ffmpegExe;
args.TempPath = @"D:\music\temp";
var AudioInfo = new AudioInfoHelper(ffmpegExe, args.Logger).Read(args.WorkingFile);
Assert.AreEqual(8, AudioInfo.Track);
}
[TestMethod]
public void AudioInfo_GetMetaData()
{
var logger = new TestLogger();
foreach (string file in Directory.GetFiles(@"/home/john/Music/test"))
{
const string file = @"\\oracle\Audio\The Cranberries\No Need To Argue\The Cranberries - No Need To Argue - 00 - I Don't Need (Demo).mp3";
const string ffmpegExe = @"C:\utils\ffmpeg\ffmpeg.exe";
var args = new FileFlows.Plugin.NodeParameters(file, new TestLogger(), false, string.Empty);
var args = new FileFlows.Plugin.NodeParameters(file, logger, false, string.Empty);
args.GetToolPathActual = (string tool) => ffmpegExe;
args.TempPath = @"D:\music\temp";
var AudioInfo = new AudioInfoHelper(ffmpegExe, args.Logger).Read(args.WorkingFile);
// laod the variables
Assert.AreEqual(1, new AudioFile().Execute(args));
Assert.AreEqual(9, AudioInfo.Track);
var audio = new AudioInfoHelper(ffmpegExe, args.Logger).Read(args.WorkingFile);
string folder = args.ReplaceVariables("{audio.ArtistThe} ({audio.Year})");
Assert.AreEqual($"{audio.Artist} ({audio.Date.Year})", folder);
string fname = args.ReplaceVariables("{audio.Artist} - {audio.Album} - {audio.Track:##} - {audio.Title}");
Assert.AreEqual($"{audio.Artist} - {audio.Track.ToString("00")} - {audio.Title}", fname);
}
}
[TestMethod]
public void AudioInfo_NormalTrack()
{
[TestMethod]
public void AudioInfo_FileNameMetadata()
{
const string ffmpegExe = @"C:\utils\ffmpeg\ffmpeg.exe";
var logger = new TestLogger();
string file = @"\\jor-el\Audio\Meat Loaf\Bat out of Hell II- Back Into Hell… (1993)\Meat Loaf - Bat out of Hell II- Back Into Hell… - 03 - Id Do Anything for Love (but I Wont Do That).flac";
var audio = new AudioInfo();
const string file = @"\\oracle\Audio\Taylor Swift\Speak Now\Taylor Swift - Speak Now - 08 - Never Grow Up.mp3";
const string ffmpegExe = @"C:\utils\ffmpeg\ffmpeg.exe";
new AudioInfoHelper(ffmpegExe, logger).ParseFileNameInfo(file, audio);
var args = new FileFlows.Plugin.NodeParameters(file, new TestLogger(), false, string.Empty);
args.GetToolPathActual = (string tool) => ffmpegExe;
args.TempPath = @"D:\music\temp";
Assert.AreEqual("Meat Loaf", audio.Artist);
Assert.AreEqual("Bat out of Hell II- Back Into Hell…", audio.Album);
Assert.AreEqual(1993, audio.Date.Year);
Assert.AreEqual("Id Do Anything for Love (but I Wont Do That)", audio.Title);
Assert.AreEqual(3, audio.Track);
}
var AudioInfo = new AudioInfoHelper(ffmpegExe, args.Logger).Read(args.WorkingFile);
[TestMethod]
public void AudioInfo_Bitrate()
{
var logger = new TestLogger();
var file = @"/home/john/Music/test/test.mp3";
var args = new FileFlows.Plugin.NodeParameters(file, logger, false, string.Empty);
args.GetToolPathActual = (string tool) => ffmpegExe;
Assert.AreEqual(8, AudioInfo.Track);
}
// load the variables
Assert.AreEqual(1, new AudioFile().Execute(args));
// convert to 192
var convert = new ConvertAudio();
convert.Bitrate = 192;
convert.SkipIfCodecMatches = false;
convert.Codec = "mp3";
convert.PreExecute(args);
int result = convert.Execute(args);
Assert.AreEqual(1, result);
[TestMethod]
public void AudioInfo_GetMetaData()
{
const string ffmpegExe = @"C:\utils\ffmpeg\ffmpeg.exe";
var logger = new TestLogger();
foreach (string file in Directory.GetFiles(@"D:\videos\Audio"))
{
var args = new FileFlows.Plugin.NodeParameters(file, logger, false, string.Empty);
args.GetToolPathActual = (string tool) => ffmpegExe;
var audio = new AudioInfoHelper(ffmpegExe, args.Logger).Read(args.WorkingFile);
Assert.AreEqual(192 * 1024, audio.Bitrate);
// laod the variables
Assert.AreEqual(1, new AudioFile().Execute(args));
var md = new Dictionary<string, object>();
convert.SetAudioInfo(args, audio, md);
Assert.AreEqual((192 * 1024).ToString(), md["audio.Bitrate"].ToString());
// converting again should skip
convert = new();
convert.SkipIfCodecMatches = false;
convert.Codec = "mp3";
convert.Bitrate = 192;
convert.PreExecute(args);
result = convert.Execute(args);
Assert.AreEqual(2, result);
var audio = new AudioInfoHelper(ffmpegExe, args.Logger).Read(args.WorkingFile);
string folder = args.ReplaceVariables("{audio.ArtistThe} ({audio.Year})");
Assert.AreEqual($"{audio.Artist} ({audio.Date.Year})", folder);
string fname = args.ReplaceVariables("{audio.Artist} - {audio.Album} - {audio.Track:##} - {audio.Title}");
Assert.AreEqual($"{audio.Artist} - {audio.Track.ToString("00")} - {audio.Title}", fname);
}
}
[TestMethod]
public void AudioInfo_FileNameMetadata()
{
const string ffmpegExe = @"C:\utils\ffmpeg\ffmpeg.exe";
var logger = new TestLogger();
string file = @"\\jor-el\Audio\Meat Loaf\Bat out of Hell II- Back Into Hell… (1993)\Meat Loaf - Bat out of Hell II- Back Into Hell… - 03 - Id Do Anything for Love (but I Wont Do That).flac";
var audio = new AudioInfo();
new AudioInfoHelper(ffmpegExe, logger).ParseFileNameInfo(file, audio);
Assert.AreEqual("Meat Loaf", audio.Artist);
Assert.AreEqual("Bat out of Hell II- Back Into Hell…", audio.Album);
Assert.AreEqual(1993, audio.Date.Year);
Assert.AreEqual("Id Do Anything for Love (but I Wont Do That)", audio.Title);
Assert.AreEqual(3, audio.Track);
}
string log = logger.ToString();
}
}