mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 18:14:25 +00:00
2.0.2
This commit is contained in:
@@ -17,26 +17,32 @@ namespace CUETools.Processor
|
||||
public static class AudioReadWrite {
|
||||
public static IAudioSource GetAudioSource(string path, Stream IO, string extension, CUEConfig config)
|
||||
{
|
||||
switch (extension)
|
||||
CUEToolsFormat fmt;
|
||||
if (!extension.StartsWith(".") || !config.formats.TryGetValue(extension.Substring(1), out fmt))
|
||||
throw new Exception("Unsupported audio type: " + path);
|
||||
CUEToolsUDC decoder;
|
||||
if (fmt.decoder == null || !config.decoders.TryGetValue(fmt.decoder, out decoder))
|
||||
throw new Exception("Unsupported audio type: " + path);
|
||||
switch (decoder.className)
|
||||
{
|
||||
case ".wav":
|
||||
case "WAVReader":
|
||||
return new WAVReader(path, IO);
|
||||
case ".m4a":
|
||||
case "ALACReader":
|
||||
return new ALACReader(path, IO);
|
||||
#if !MONO
|
||||
case ".flac":
|
||||
case "FLACReader":
|
||||
return new FLACReader(path, IO, config.disableAsm);
|
||||
case ".wv":
|
||||
case "WavPackReader":
|
||||
return new WavPackReader(path, IO, null);
|
||||
case ".ape":
|
||||
case "APEReader":
|
||||
return new APEReader(path, IO);
|
||||
case ".tta":
|
||||
case "TTAReader":
|
||||
return new TTAReader(path, IO);
|
||||
#endif
|
||||
default:
|
||||
if (extension == "." + config.udc1Extension && config.udc1Decoder != "")
|
||||
return new UserDefinedReader(path, IO, config.udc1Decoder, config.udc1Params);
|
||||
throw new Exception("Unsupported audio type: " + path);
|
||||
if (decoder.path == null)
|
||||
throw new Exception("Unsupported audio type: " + path);
|
||||
return new UserDefinedReader(path, IO, decoder.path, decoder.parameters);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,59 +69,71 @@ namespace CUETools.Processor
|
||||
return new LossyWAVReader(lossySource, lwcdfSource);
|
||||
}
|
||||
|
||||
public static IAudioDest GetAudioDest(string path, int bitsPerSample, int channelCount, int sampleRate, long finalSampleCount, string extension, CUEConfig config) {
|
||||
public static IAudioDest GetAudioDest(AudioEncoderType audioEncoderType, string path, int bitsPerSample, int channelCount, int sampleRate, long finalSampleCount, string extension, CUEConfig config)
|
||||
{
|
||||
IAudioDest dest;
|
||||
switch (extension) {
|
||||
case ".wav":
|
||||
if (audioEncoderType == AudioEncoderType.NoAudio || extension == ".dummy")
|
||||
{
|
||||
dest = new DummyWriter(path, bitsPerSample, channelCount, sampleRate);
|
||||
dest.FinalSampleCount = finalSampleCount;
|
||||
return dest;
|
||||
}
|
||||
CUEToolsFormat fmt;
|
||||
if (!extension.StartsWith(".") || !config.formats.TryGetValue(extension.Substring(1), out fmt))
|
||||
throw new Exception("Unsupported audio type: " + path);
|
||||
string encoderName = audioEncoderType == AudioEncoderType.Lossless ? fmt.encoderLossless :
|
||||
audioEncoderType == AudioEncoderType.Lossy ? fmt.encoderLossy :
|
||||
null;
|
||||
CUEToolsUDC encoder;
|
||||
if (encoderName == null || !config.encoders.TryGetValue(encoderName, out encoder))
|
||||
throw new Exception("Unsupported audio type: " + path);
|
||||
switch (encoder.className)
|
||||
{
|
||||
case "WAVWriter":
|
||||
dest = new WAVWriter(path, bitsPerSample, channelCount, sampleRate, null);
|
||||
break;
|
||||
#if !MONO
|
||||
case ".flac":
|
||||
case "FLACWriter":
|
||||
dest = new FLACWriter(path, bitsPerSample, channelCount, sampleRate);
|
||||
((FLACWriter)dest).CompressionLevel = (int)config.flacCompressionLevel;
|
||||
((FLACWriter)dest).Verify = config.flacVerify;
|
||||
((FLACWriter)dest).DisableAsm = config.disableAsm;
|
||||
break;
|
||||
case ".wv":
|
||||
case "WavPackWriter":
|
||||
dest = new WavPackWriter(path, bitsPerSample, channelCount, sampleRate);
|
||||
((WavPackWriter)dest).CompressionMode = config.wvCompressionMode;
|
||||
((WavPackWriter)dest).ExtraMode = config.wvExtraMode;
|
||||
((WavPackWriter)dest).MD5Sum = config.wvStoreMD5;
|
||||
break;
|
||||
case ".ape":
|
||||
case "APEWriter":
|
||||
dest = new APEWriter(path, bitsPerSample, channelCount, sampleRate);
|
||||
((APEWriter)dest).CompressionLevel = (int)config.apeCompressionLevel;
|
||||
break;
|
||||
case ".tta":
|
||||
case "TTAWriter":
|
||||
dest = new TTAWriter(path, bitsPerSample, channelCount, sampleRate);
|
||||
break;
|
||||
case ".dummy":
|
||||
dest = new DummyWriter(path, bitsPerSample, channelCount, sampleRate);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
if (extension == "." + config.udc1Extension && config.udc1Encoder != "")
|
||||
{
|
||||
dest = new UserDefinedWriter(path, bitsPerSample, channelCount, sampleRate, null, config.udc1Encoder, config.udc1EncParams);
|
||||
break;
|
||||
}
|
||||
throw new Exception("Unsupported audio type: " + path);
|
||||
if (encoder.path == null)
|
||||
throw new Exception("Unsupported audio type: " + path);
|
||||
dest = new UserDefinedWriter(path, bitsPerSample, channelCount, sampleRate, null, encoder.path, encoder.parameters);
|
||||
break;
|
||||
}
|
||||
dest.FinalSampleCount = finalSampleCount;
|
||||
return dest;
|
||||
}
|
||||
|
||||
public static IAudioDest GetAudioDest(string path, long finalSampleCount, int bitsPerSample, int sampleRate, CUEConfig config)
|
||||
public static IAudioDest GetAudioDest(AudioEncoderType audioEncoderType, string path, long finalSampleCount, int bitsPerSample, int sampleRate, CUEConfig config)
|
||||
{
|
||||
string extension = Path.GetExtension(path).ToLower();
|
||||
string filename = Path.GetFileNameWithoutExtension(path);
|
||||
if (Path.GetExtension(filename).ToLower() != ".lossy")
|
||||
return GetAudioDest(path, bitsPerSample, 2, sampleRate, finalSampleCount, extension, config);
|
||||
if (audioEncoderType == AudioEncoderType.NoAudio || audioEncoderType == AudioEncoderType.Lossless || Path.GetExtension(filename).ToLower() != ".lossy")
|
||||
return GetAudioDest(audioEncoderType, path, bitsPerSample, 2, sampleRate, finalSampleCount, extension, config);
|
||||
|
||||
string lwcdfPath = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(filename) + ".lwcdf" + extension);
|
||||
int lossyBitsPerSample = (config.detectHDCD && config.decodeHDCD && !config.decodeHDCDtoLW16) ? 24 : 16;
|
||||
IAudioDest lossyDest = GetAudioDest(path, lossyBitsPerSample, 2, sampleRate, finalSampleCount, extension, config);
|
||||
IAudioDest lwcdfDest = config.lossyWAVHybrid ? GetAudioDest(lwcdfPath, bitsPerSample, 2, sampleRate, finalSampleCount, extension, config) : null;
|
||||
IAudioDest lossyDest = GetAudioDest(AudioEncoderType.Lossless, path, lossyBitsPerSample, 2, sampleRate, finalSampleCount, extension, config);
|
||||
IAudioDest lwcdfDest = audioEncoderType == AudioEncoderType.Hybrid ? GetAudioDest(AudioEncoderType.Lossless, lwcdfPath, bitsPerSample, 2, sampleRate, finalSampleCount, extension, config) : null;
|
||||
return new LossyWAVWriter(lossyDest, lwcdfDest, bitsPerSample, 2, sampleRate, config.lossyWAVQuality);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,10 @@
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="CSScriptLibrary.v1.1, Version=2.3.2.0, Culture=neutral">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>.\CSScriptLibrary.v1.1.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ICSharpCode.SharpZipLib, Version=0.85.5.452, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>.\ICSharpCode.SharpZipLib.dll</HintPath>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -43,26 +43,36 @@ namespace CUETools.Processor
|
||||
public class SettingsReader {
|
||||
Dictionary<string, string> _settings;
|
||||
|
||||
public SettingsReader(string appName, string fileName) {
|
||||
public SettingsReader(string appName, string fileName, string appPath) {
|
||||
_settings = new Dictionary<string, string>();
|
||||
bool userProfilesEnabled = (appPath == null || File.Exists(Path.Combine(Path.GetDirectoryName(appPath), "user_profiles_enabled")));
|
||||
|
||||
string path = Path.Combine(SettingsShared.GetMyAppDataDir(appName), fileName);
|
||||
string path = Path.Combine(
|
||||
userProfilesEnabled ? SettingsShared.GetMyAppDataDir(appName) : Path.GetDirectoryName(appPath),
|
||||
userProfilesEnabled ? fileName : appName + "." + fileName);
|
||||
if (!File.Exists(path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
using (StreamReader sr = new StreamReader(path, Encoding.UTF8)) {
|
||||
string line, name, val;
|
||||
string line, name = null, val;
|
||||
int pos;
|
||||
|
||||
while ((line = sr.ReadLine()) != null) {
|
||||
pos = line.IndexOf('=');
|
||||
if (pos != -1) {
|
||||
name = line.Substring(0, pos);
|
||||
val = line.Substring(pos + 1);
|
||||
|
||||
if (!_settings.ContainsKey(name)) {
|
||||
_settings.Add(name, val);
|
||||
if (pos > 0)
|
||||
{
|
||||
name = line.Substring(0, pos);
|
||||
val = line.Substring(pos + 1);
|
||||
if (!_settings.ContainsKey(name))
|
||||
_settings.Add(name, val);
|
||||
}
|
||||
else
|
||||
{
|
||||
val = line.Substring(pos + 1);
|
||||
if (_settings.ContainsKey(name))
|
||||
_settings[name] += "\r\n" + val;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,8 +110,12 @@ namespace CUETools.Processor
|
||||
public class SettingsWriter {
|
||||
StreamWriter _sw;
|
||||
|
||||
public SettingsWriter(string appName, string fileName) {
|
||||
string path = Path.Combine(SettingsShared.GetMyAppDataDir(appName), fileName);
|
||||
public SettingsWriter(string appName, string fileName, string appPath)
|
||||
{
|
||||
bool userProfilesEnabled = (appPath == null || File.Exists(Path.Combine(Path.GetDirectoryName(appPath), "user_profiles_enabled")));
|
||||
string path = Path.Combine(
|
||||
userProfilesEnabled ? SettingsShared.GetMyAppDataDir(appName) : Path.GetDirectoryName(appPath),
|
||||
userProfilesEnabled ? fileName : appName + "." + fileName);
|
||||
|
||||
_sw = new StreamWriter(path, false, Encoding.UTF8);
|
||||
}
|
||||
@@ -110,6 +124,17 @@ namespace CUETools.Processor
|
||||
_sw.WriteLine(name + "=" + value);
|
||||
}
|
||||
|
||||
public void SaveText(string name, string value)
|
||||
{
|
||||
_sw.Write(name);
|
||||
using (StringReader sr = new StringReader(value))
|
||||
{
|
||||
string lineStr;
|
||||
while ((lineStr = sr.ReadLine()) != null)
|
||||
_sw.WriteLine("=" + lineStr);
|
||||
}
|
||||
}
|
||||
|
||||
public void Save(string name, bool value) {
|
||||
Save(name, value ? "1" : "0");
|
||||
}
|
||||
|
||||
@@ -19,10 +19,15 @@ namespace CUETools.Processor
|
||||
return true;
|
||||
}
|
||||
if (fileInfo is TagLib.Mpeg4.File)
|
||||
return true;
|
||||
if (fileInfo is TagLib.UserDefined.File && !(fileInfo as TagLib.UserDefined.File).SupportsAPEv2)
|
||||
{
|
||||
if (!(fileInfo as TagLib.UserDefined.File).SupportsID3v2)
|
||||
// remove fb2k/nero nasty tags mess
|
||||
((TagLib.Mpeg4.File)fileInfo).UserData.RemoveChild("tags");
|
||||
TagLib.Mpeg4.AppleTag mpeg4 = (TagLib.Mpeg4.AppleTag)fileInfo.GetTag(TagLib.TagTypes.Apple, true);
|
||||
return true;
|
||||
}
|
||||
if (fileInfo is TagLib.UserDefined.File && (fileInfo as TagLib.UserDefined.File).Tagger != CUEToolsTagger.APEv2)
|
||||
{
|
||||
if ((fileInfo as TagLib.UserDefined.File).Tagger != CUEToolsTagger.ID3v2)
|
||||
return false;
|
||||
TagLib.Id3v2.Tag id3v2 = (TagLib.Id3v2.Tag)fileInfo.GetTag(TagLib.TagTypes.Id3v2, true);
|
||||
return true;
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TagLib;
|
||||
|
||||
namespace TagLib.UserDefined {
|
||||
@@ -45,9 +46,7 @@ namespace TagLib.UserDefined {
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private bool _supportsAPEv2 = true;
|
||||
|
||||
private bool _supportsID3v2 = true;
|
||||
private CUETools.Processor.CUEToolsTagger tagger;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -72,17 +71,20 @@ namespace TagLib.UserDefined {
|
||||
/// <exception cref="ArgumentNullException">
|
||||
/// <paramref name="path" /> is <see langword="null" />.
|
||||
/// </exception>
|
||||
public File (string path, ReadStyle propertiesStyle, bool supportsAPEv2, bool supportsID3v2)
|
||||
public File (string path, ReadStyle propertiesStyle, CUETools.Processor.CUEToolsTagger _tagger)
|
||||
: base (path, propertiesStyle)
|
||||
{
|
||||
_supportsAPEv2 = supportsAPEv2;
|
||||
_supportsID3v2 = supportsID3v2;
|
||||
// Make sure we have an APE tag.
|
||||
if (_supportsAPEv2)
|
||||
GetTag(TagTypes.Ape, true);
|
||||
else
|
||||
if (_supportsID3v2)
|
||||
tagger = _tagger;
|
||||
// Make sure we have a tag.
|
||||
switch (tagger)
|
||||
{
|
||||
case CUETools.Processor.CUEToolsTagger.APEv2:
|
||||
GetTag(TagTypes.Ape, true);
|
||||
break;
|
||||
case CUETools.Processor.CUEToolsTagger.ID3v2:
|
||||
GetTag(TagTypes.Id3v2, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -97,17 +99,20 @@ namespace TagLib.UserDefined {
|
||||
/// <exception cref="ArgumentNullException">
|
||||
/// <paramref name="path" /> is <see langword="null" />.
|
||||
/// </exception>
|
||||
public File(string path, bool supportsAPEv2, bool supportsID3v2)
|
||||
public File(string path, CUETools.Processor.CUEToolsTagger _tagger)
|
||||
: base(path)
|
||||
{
|
||||
_supportsAPEv2 = supportsAPEv2;
|
||||
_supportsID3v2 = supportsID3v2;
|
||||
// Make sure we have an APE tag.
|
||||
if (_supportsAPEv2)
|
||||
GetTag(TagTypes.Ape, true);
|
||||
else
|
||||
if (_supportsID3v2)
|
||||
tagger = _tagger;
|
||||
// Make sure we have a tag.
|
||||
switch (tagger)
|
||||
{
|
||||
case CUETools.Processor.CUEToolsTagger.APEv2:
|
||||
GetTag(TagTypes.Ape, true);
|
||||
break;
|
||||
case CUETools.Processor.CUEToolsTagger.ID3v2:
|
||||
GetTag(TagTypes.Id3v2, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -129,17 +134,20 @@ namespace TagLib.UserDefined {
|
||||
/// />.
|
||||
/// </exception>
|
||||
public File (File.IFileAbstraction abstraction,
|
||||
ReadStyle propertiesStyle, bool supportsAPEv2, bool supportsID3v2)
|
||||
ReadStyle propertiesStyle, CUETools.Processor.CUEToolsTagger _tagger)
|
||||
: base (abstraction, propertiesStyle)
|
||||
{
|
||||
_supportsAPEv2 = supportsAPEv2;
|
||||
_supportsID3v2 = supportsID3v2;
|
||||
// Make sure we have an APE tag.
|
||||
if (_supportsAPEv2)
|
||||
GetTag(TagTypes.Ape, true);
|
||||
else
|
||||
if (_supportsID3v2)
|
||||
tagger = _tagger;
|
||||
// Make sure we have a tag.
|
||||
switch (tagger)
|
||||
{
|
||||
case CUETools.Processor.CUEToolsTagger.APEv2:
|
||||
GetTag(TagTypes.Ape, true);
|
||||
break;
|
||||
case CUETools.Processor.CUEToolsTagger.ID3v2:
|
||||
GetTag(TagTypes.Id3v2, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -155,17 +163,20 @@ namespace TagLib.UserDefined {
|
||||
/// <paramref name="abstraction" /> is <see langword="null"
|
||||
/// />.
|
||||
/// </exception>
|
||||
public File(File.IFileAbstraction abstraction, bool supportsAPEv2, bool supportsID3v2)
|
||||
public File(File.IFileAbstraction abstraction, CUETools.Processor.CUEToolsTagger _tagger)
|
||||
: base (abstraction)
|
||||
{
|
||||
_supportsAPEv2 = supportsAPEv2;
|
||||
_supportsID3v2 = supportsID3v2;
|
||||
// Make sure we have an APE tag.
|
||||
if (_supportsAPEv2)
|
||||
GetTag(TagTypes.Ape, true);
|
||||
else
|
||||
if (_supportsID3v2)
|
||||
tagger = _tagger;
|
||||
// Make sure we have a tag.
|
||||
switch (tagger)
|
||||
{
|
||||
case CUETools.Processor.CUEToolsTagger.APEv2:
|
||||
GetTag(TagTypes.Ape, true);
|
||||
break;
|
||||
case CUETools.Processor.CUEToolsTagger.ID3v2:
|
||||
GetTag(TagTypes.Id3v2, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -174,22 +185,13 @@ namespace TagLib.UserDefined {
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public bool SupportsAPEv2
|
||||
public CUETools.Processor.CUEToolsTagger Tagger
|
||||
{
|
||||
get
|
||||
{
|
||||
return _supportsAPEv2;
|
||||
return tagger;
|
||||
}
|
||||
}
|
||||
|
||||
public bool SupportsID3v2
|
||||
{
|
||||
get
|
||||
{
|
||||
return _supportsID3v2;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a tag of a specified type from the current instance,
|
||||
@@ -329,12 +331,9 @@ namespace TagLib.UserDefined {
|
||||
|
||||
private static TagLib.File UserDefinedResolver(TagLib.File.IFileAbstraction abstraction, string mimetype, TagLib.ReadStyle style)
|
||||
{
|
||||
if (mimetype == "taglib/flac" || mimetype == "taglib/wv" || mimetype == "taglib/ape" || mimetype == "taglib/wav" || mimetype == "taglib/ogg" || mimetype == "taglib/m4a" || mimetype == "taglib/mp3")
|
||||
return null;
|
||||
if (mimetype == "taglib/tta")
|
||||
return new File(abstraction, style, true, false);
|
||||
if (mimetype == "taglib/" + _config.udc1Extension)
|
||||
return new File(abstraction, style, _config.udc1APEv2, _config.udc1ID3v2);
|
||||
foreach (KeyValuePair<string,CUETools.Processor.CUEToolsFormat> fmt in _config.formats)
|
||||
if (fmt.Value.tagger != CUETools.Processor.CUEToolsTagger.TagLibSharp && mimetype == "taglib/" + fmt.Key)
|
||||
return new File(abstraction, style, fmt.Value.tagger);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user