mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 18:14:25 +00:00
CUETools.Converter: stdin/stdout support
This commit is contained in:
@@ -143,7 +143,7 @@ namespace CUETools.Codecs
|
|||||||
|
|
||||||
public void Close()
|
public void Close()
|
||||||
{
|
{
|
||||||
if (_finalSampleCount <= 0)
|
if (_finalSampleCount <= 0 && _IO.CanSeek)
|
||||||
{
|
{
|
||||||
long dataLen = _sampleLen * Settings.PCM.BlockAlign;
|
long dataLen = _sampleLen * Settings.PCM.BlockAlign;
|
||||||
long dataLenPadded = dataLen + (dataLen & 1);
|
long dataLenPadded = dataLen + (dataLen & 1);
|
||||||
|
|||||||
@@ -40,9 +40,9 @@ namespace CUETools.Converter
|
|||||||
audioEncoderType = AudioEncoderType.Lossy;
|
audioEncoderType = AudioEncoderType.Lossy;
|
||||||
else if (args[arg] == "--lossless")
|
else if (args[arg] == "--lossless")
|
||||||
audioEncoderType = AudioEncoderType.Lossless;
|
audioEncoderType = AudioEncoderType.Lossless;
|
||||||
else if (args[arg][0] != '-' && sourceFile == null)
|
else if ((args[arg][0] != '-' || args[arg] == "-") && sourceFile == null)
|
||||||
sourceFile = args[arg];
|
sourceFile = args[arg];
|
||||||
else if (args[arg][0] != '-' && sourceFile != null && destFile == null)
|
else if ((args[arg][0] != '-' || args[arg] == "-") && sourceFile != null && destFile == null)
|
||||||
destFile = args[arg];
|
destFile = args[arg];
|
||||||
else
|
else
|
||||||
ok = false;
|
ok = false;
|
||||||
@@ -59,13 +59,13 @@ namespace CUETools.Converter
|
|||||||
return 22;
|
return 22;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (File.Exists(destFile))
|
if (destFile != "-" && File.Exists(destFile))
|
||||||
{
|
{
|
||||||
Console.Error.WriteLine("Error: file already exists.");
|
Console.Error.WriteLine("Error: file already exists.");
|
||||||
return 17;
|
return 17;
|
||||||
}
|
}
|
||||||
|
|
||||||
string extension = Path.GetExtension(destFile).ToLower();
|
string extension = destFile == "-" ? ".wav" : Path.GetExtension(destFile).ToLower();
|
||||||
DateTime start = DateTime.Now;
|
DateTime start = DateTime.Now;
|
||||||
TimeSpan lastPrint = TimeSpan.FromMilliseconds(0);
|
TimeSpan lastPrint = TimeSpan.FromMilliseconds(0);
|
||||||
CUEConfig config = new CUEConfig();
|
CUEConfig config = new CUEConfig();
|
||||||
@@ -78,9 +78,13 @@ namespace CUETools.Converter
|
|||||||
{
|
{
|
||||||
IAudioSource audioSource = null;
|
IAudioSource audioSource = null;
|
||||||
IAudioDest audioDest = null;
|
IAudioDest audioDest = null;
|
||||||
|
TagLib.UserDefined.AdditionalFileTypes.Config = config;
|
||||||
|
TagLib.File sourceInfo = sourceFile == "-" ? null : TagLib.File.Create(new TagLib.File.LocalFileAbstraction(sourceFile));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
audioSource = AudioReadWrite.GetAudioSource(sourceFile, null, config);
|
audioSource = sourceFile == "-" ?
|
||||||
|
new WAVReader("", Console.OpenStandardInput()) :
|
||||||
|
AudioReadWrite.GetAudioSource(sourceFile, null, config);
|
||||||
AudioBuffer buff = new AudioBuffer(audioSource, 0x10000);
|
AudioBuffer buff = new AudioBuffer(audioSource, 0x10000);
|
||||||
Console.Error.WriteLine("Filename : {0}", sourceFile);
|
Console.Error.WriteLine("Filename : {0}", sourceFile);
|
||||||
Console.Error.WriteLine("File Info : {0}kHz; {1} channel; {2} bit; {3}", audioSource.PCM.SampleRate, audioSource.PCM.ChannelCount, audioSource.PCM.BitsPerSample, TimeSpan.FromSeconds(audioSource.Length * 1.0 / audioSource.PCM.SampleRate));
|
Console.Error.WriteLine("File Info : {0}kHz; {1} channel; {2} bit; {3}", audioSource.PCM.SampleRate, audioSource.PCM.ChannelCount, audioSource.PCM.BitsPerSample, TimeSpan.FromSeconds(audioSource.Length * 1.0 / audioSource.PCM.SampleRate));
|
||||||
@@ -101,7 +105,9 @@ namespace CUETools.Converter
|
|||||||
object o = null;
|
object o = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
o = Activator.CreateInstance(encoder.type, destFile, settings);
|
o = destFile == "-" ?
|
||||||
|
Activator.CreateInstance(encoder.type, "", Console.OpenStandardOutput(), settings) :
|
||||||
|
Activator.CreateInstance(encoder.type, destFile, settings);
|
||||||
}
|
}
|
||||||
catch (System.Reflection.TargetInvocationException ex)
|
catch (System.Reflection.TargetInvocationException ex)
|
||||||
{
|
{
|
||||||
@@ -128,11 +134,15 @@ namespace CUETools.Converter
|
|||||||
TimeSpan elapsed = DateTime.Now - start;
|
TimeSpan elapsed = DateTime.Now - start;
|
||||||
if ((elapsed - lastPrint).TotalMilliseconds > 60)
|
if ((elapsed - lastPrint).TotalMilliseconds > 60)
|
||||||
{
|
{
|
||||||
|
long length = audioSource.Length;
|
||||||
|
if (length < 0 && sourceInfo != null) length = (long)(sourceInfo.Properties.Duration.TotalMilliseconds * audioSource.PCM.SampleRate / 1000);
|
||||||
|
if (length < audioSource.Position) length = audioSource.Position;
|
||||||
|
if (length < 1) length = 1;
|
||||||
Console.Error.Write("\rProgress : {0:00}%; {1:0.00}x; {2}/{3}",
|
Console.Error.Write("\rProgress : {0:00}%; {1:0.00}x; {2}/{3}",
|
||||||
100.0 * audioSource.Position / audioSource.Length,
|
100.0 * audioSource.Position / length,
|
||||||
audioSource.Position / elapsed.TotalSeconds / audioSource.PCM.SampleRate,
|
audioSource.Position / elapsed.TotalSeconds / audioSource.PCM.SampleRate,
|
||||||
elapsed,
|
elapsed,
|
||||||
TimeSpan.FromMilliseconds(elapsed.TotalMilliseconds / audioSource.Position * audioSource.Length)
|
TimeSpan.FromMilliseconds(elapsed.TotalMilliseconds / audioSource.Position * length)
|
||||||
);
|
);
|
||||||
lastPrint = elapsed;
|
lastPrint = elapsed;
|
||||||
}
|
}
|
||||||
@@ -156,9 +166,9 @@ namespace CUETools.Converter
|
|||||||
audioSource.Close();
|
audioSource.Close();
|
||||||
audioDest.Close();
|
audioDest.Close();
|
||||||
|
|
||||||
TagLib.UserDefined.AdditionalFileTypes.Config = config;
|
if (sourceFile != "-" && destFile != "-")
|
||||||
TagLib.File sourceInfo = TagLib.File.Create(new TagLib.File.LocalFileAbstraction(sourceFile));
|
{
|
||||||
TagLib.File destInfo = TagLib.File.Create(new TagLib.File.LocalFileAbstraction(destFile));
|
TagLib.File destInfo = destFile == "-" ? null : TagLib.File.Create(new TagLib.File.LocalFileAbstraction(destFile));
|
||||||
if (Tagging.UpdateTags(destInfo, Tagging.Analyze(sourceInfo), config))
|
if (Tagging.UpdateTags(destInfo, Tagging.Analyze(sourceInfo), config))
|
||||||
{
|
{
|
||||||
sourceInfo.Tag.CopyTo(destInfo.Tag, true);
|
sourceInfo.Tag.CopyTo(destInfo.Tag, true);
|
||||||
@@ -166,6 +176,7 @@ namespace CUETools.Converter
|
|||||||
destInfo.Save();
|
destInfo.Save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user