mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 18:14:25 +00:00
drive read offset detection
This commit is contained in:
@@ -414,6 +414,71 @@ namespace CUETools.AccurateRip
|
||||
return r;
|
||||
}
|
||||
|
||||
static string CachePath
|
||||
{
|
||||
get
|
||||
{
|
||||
string cache = System.IO.Path.Combine(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "CUE Tools"), "AccurateRipCache");
|
||||
if (!Directory.Exists(cache))
|
||||
Directory.CreateDirectory(cache);
|
||||
return cache;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool FindDriveReadOffset(string driveName, out int driveReadOffset)
|
||||
{
|
||||
string fileName = System.IO.Path.Combine(CachePath, "DriveOffsets.bin");
|
||||
if (!File.Exists(fileName))
|
||||
{
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.accuraterip.com/accuraterip/DriveOffsets.bin");
|
||||
req.Method = "GET";
|
||||
try
|
||||
{
|
||||
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
|
||||
if (resp.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
driveReadOffset = 0;
|
||||
return false;
|
||||
}
|
||||
Stream respStream = resp.GetResponseStream();
|
||||
FileStream myOffsetsSaved = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write);
|
||||
byte [] buff = new byte[0x8000];
|
||||
do
|
||||
{
|
||||
int count = respStream.Read(buff, 0, buff.Length);
|
||||
if (count == 0) break;
|
||||
myOffsetsSaved.Write(buff, 0, count);
|
||||
} while (true);
|
||||
respStream.Close();
|
||||
myOffsetsSaved.Close();
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
driveReadOffset = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
FileStream myOffsets = new FileStream(fileName, FileMode.Open, FileAccess.Read);
|
||||
BinaryReader offsetReader = new BinaryReader(myOffsets);
|
||||
do
|
||||
{
|
||||
short readOffset = offsetReader.ReadInt16();
|
||||
byte[] name = offsetReader.ReadBytes(0x21);
|
||||
byte[] misc = offsetReader.ReadBytes(0x22);
|
||||
int len = name.Length;
|
||||
while (len > 0 && name[len - 1] == '\0') len--;
|
||||
string strname = Encoding.ASCII.GetString(name,0,len);
|
||||
if (strname == driveName)
|
||||
{
|
||||
driveReadOffset = readOffset;
|
||||
return true;
|
||||
}
|
||||
} while (myOffsets.Position + 0x45 <= myOffsets.Length);
|
||||
offsetReader.Close();
|
||||
driveReadOffset = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static string CalculateCDDBId(CDImageLayout toc)
|
||||
{
|
||||
uint cddbDiscId = 0;
|
||||
|
||||
@@ -34,12 +34,6 @@ namespace CUERipper
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Usage()
|
||||
{
|
||||
Console.WriteLine("Usage : CUERipper.exe <file.wav>");
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string programVersion = "CUERipper v1.9.3 Copyright (C) 2008 Gregory S. Chudov";
|
||||
@@ -47,12 +41,7 @@ namespace CUERipper
|
||||
Console.WriteLine("{0}", programVersion);
|
||||
Console.WriteLine("This is free software under the GNU GPLv3+ license; There is NO WARRANTY, to");
|
||||
Console.WriteLine("the extent permitted by law. <http://www.gnu.org/licenses/> for details.");
|
||||
if (args.Length < 1)
|
||||
{
|
||||
Usage();
|
||||
return;
|
||||
}
|
||||
string destFile = args[0];
|
||||
|
||||
char[] drives = CDDriveReader.DrivesAvailable();
|
||||
if (drives.Length < 1)
|
||||
{
|
||||
@@ -66,7 +55,10 @@ namespace CUERipper
|
||||
{
|
||||
CDDriveReader audioSource = new CDDriveReader();
|
||||
audioSource.Open(driveLetter);
|
||||
audioSource.DriveOffset = 48;
|
||||
int driveOffset;
|
||||
if (!AccurateRipVerify.FindDriveReadOffset(audioSource.ARName, out driveOffset))
|
||||
throw new Exception("Failed to find drive read offset for drive" + audioSource.ARName);
|
||||
audioSource.DriveOffset = driveOffset;
|
||||
|
||||
//bool toStdout = false;
|
||||
AccurateRipVerify arVerify = new AccurateRipVerify(audioSource.TOC);
|
||||
@@ -89,17 +81,16 @@ namespace CUERipper
|
||||
release = null;
|
||||
}
|
||||
|
||||
if (destFile == null || destFile == "")
|
||||
destFile = (release == null) ? "cdimage.flac" : release.GetArtist() + " - " + release.GetTitle() + ".flac";
|
||||
string destFile = (release == null) ? "cdimage.flac" : release.GetArtist() + " - " + release.GetTitle() + ".flac";
|
||||
|
||||
Console.WriteLine("Drive : {0}", audioSource.Path);
|
||||
Console.WriteLine("Read offset : {0}", audioSource.DriveOffset);
|
||||
Console.WriteLine("Filename : {0}", destFile);
|
||||
Console.WriteLine("Disk length : {0}", CDImageLayout.TimeToString(audioSource.TOC.AudioLength));
|
||||
Console.WriteLine("AccurateRip : {0}", arVerify.ARStatus == null ? "ok" : arVerify.ARStatus);
|
||||
Console.WriteLine("MusicBrainz : {0}", release == null ? "not found" : release.GetArtist() + " - " + release.GetTitle());
|
||||
|
||||
IAudioDest audioDest = new FLACWriter(destFile, audioSource.BitsPerSample, audioSource.ChannelCount, audioSource.SampleRate);
|
||||
//IAudioDest audioDest = new WAVWriter(destFile, audioSource.BitsPerSample, audioSource.ChannelCount, audioSource.SampleRate, toStdout ? Console.OpenStandardOutput() : null);
|
||||
audioDest.FinalSampleCount = (long)audioSource.Length;
|
||||
|
||||
|
||||
|
||||
@@ -389,6 +389,14 @@ namespace CUETools.Ripper.SCSI
|
||||
}
|
||||
}
|
||||
|
||||
public string ARName
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_info.InquiryData.VendorIdentification + " - " + m_info.InquiryData.ProductIdentification;
|
||||
}
|
||||
}
|
||||
|
||||
public ulong Position
|
||||
{
|
||||
get
|
||||
|
||||
@@ -489,14 +489,13 @@ namespace CUETools.Processor
|
||||
{
|
||||
CDDriveReader ripper = new CDDriveReader();
|
||||
ripper.Open(pathIn[0]);
|
||||
// We needed to clone TOC in case we reuse the ripper, because it's going to modify it.
|
||||
//_toc = (CDImageLayout)ripper.TOC.Clone();
|
||||
_toc = (CDImageLayout)ripper.TOC;
|
||||
_driveName = ripper.Path;
|
||||
_driveOffset = ripper.DriveOffset = 48;
|
||||
_toc = ripper.TOC;
|
||||
_driveName = ripper.ARName;
|
||||
ripper.Close();
|
||||
if (_toc.AudioTracks > 0)
|
||||
{
|
||||
if (!AccurateRipVerify.FindDriveReadOffset(_driveName, out _driveOffset))
|
||||
throw new Exception("Failed to find drive read offset for drive" + _driveName);
|
||||
_isCD = true;
|
||||
SourceInfo cdInfo;
|
||||
cdInfo.Path = pathIn;
|
||||
|
||||
Reference in New Issue
Block a user