Added configuration and wired it up.

This commit is contained in:
Sean Kelly 2021-09-27 20:18:50 +13:00
parent 36f58b64d6
commit 8a74a29700
7 changed files with 391 additions and 319 deletions

View file

@ -15,7 +15,7 @@ namespace AaxDecrypter
private OutputFormat OutputFormat { get; }
public AaxcDownloadConverter(string outFileName, string cacheDirectory, DownloadLicense dlLic, OutputFormat outputFormat)
public AaxcDownloadConverter(string outFileName, string cacheDirectory, DownloadLicense dlLic, OutputFormat outputFormat, bool splitFileByChapters)
:base(outFileName, cacheDirectory, dlLic)
{
OutputFormat = outputFormat;
@ -25,8 +25,8 @@ namespace AaxDecrypter
Name = "Download and Convert Aaxc To " + OutputFormat,
["Step 1: Get Aaxc Metadata"] = Step1_GetMetadata,
["Step 2: Download Decrypted Audiobook"] = Step2_DownloadAudiobook,
//["Step 3: Create Cue"] = Step3_CreateCue,
["Step 2: Download Decrypted Audiobook"] = splitFileByChapters ? Step2_DownloadAudiobookAsMultipleFilesPerChapter : Step2_DownloadAudiobookAsSingleFile,
["Step 3: Create Cue"] = Step3_CreateCue,
["Step 4: Cleanup"] = Step4_Cleanup,
};
}
@ -53,7 +53,7 @@ namespace AaxDecrypter
return !isCanceled;
}
protected override bool Step2_DownloadAudiobook()
protected override bool Step2_DownloadAudiobookAsSingleFile()
{
var zeroProgress = new DownloadProgress
{
@ -67,11 +67,43 @@ namespace AaxDecrypter
aaxFile.SetDecryptionKey(downloadLicense.AudibleKey, downloadLicense.AudibleIV);
aaxFile.ConversionProgressUpdate += AaxFile_ConversionProgressUpdate;
//var decryptionResult = OutputFormat == OutputFormat.Mp4a ? aaxFile.ConvertToMp4a(outFile, downloadLicense.ChapterInfo) : aaxFile.ConvertToMp3(outFile);
if (File.Exists(outputFileName))
FileExt.SafeDelete(outputFileName);
var outputFile = File.Open(outputFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
aaxFile.ConversionProgressUpdate += AaxFile_ConversionProgressUpdate;
var decryptionResult = OutputFormat == OutputFormat.M4b ? aaxFile.ConvertToMp4a(outputFile, downloadLicense.ChapterInfo) : aaxFile.ConvertToMp3(outputFile);
aaxFile.ConversionProgressUpdate -= AaxFile_ConversionProgressUpdate;
aaxFile.Close();
downloadLicense.ChapterInfo = aaxFile.Chapters;
CloseInputFileStream();
OnDecryptProgressUpdate(zeroProgress);
return decryptionResult == ConversionResult.NoErrorsDetected && !isCanceled;
}
public bool Step2_DownloadAudiobookAsMultipleFilesPerChapter()
{
var zeroProgress = new DownloadProgress
{
BytesReceived = 0,
ProgressPercentage = 0,
TotalBytesToReceive = InputFileStream.Length
};
OnDecryptProgressUpdate(zeroProgress);
aaxFile.SetDecryptionKey(downloadLicense.AudibleKey, downloadLicense.AudibleIV);
aaxFile.ConversionProgressUpdate += AaxFile_ConversionProgressUpdate;
var chapterCount = 0;
//aaxFile.ConvertToMultiMp4a(downloadLicense.ChapterInfo, newSplitCallback =>
//TODO make this work with m4b files
aaxFile.ConvertToMultiMp3(downloadLicense.ChapterInfo, newSplitCallback =>
{
chapterCount++;
@ -79,6 +111,7 @@ namespace AaxDecrypter
if (File.Exists(fileName))
FileExt.SafeDelete(fileName);
newSplitCallback.OutputFile = File.Open(fileName, FileMode.OpenOrCreate);
//TODO clean up all this junk
newSplitCallback.LameConfig = new NAudio.Lame.LameConfig
{
ID3 = new NAudio.Lame.ID3TagData()
@ -91,15 +124,10 @@ namespace AaxDecrypter
}
};
});
aaxFile.ConversionProgressUpdate -= AaxFile_ConversionProgressUpdate;
aaxFile.Close();
CloseInputFileStream();
OnDecryptProgressUpdate(zeroProgress);
return true;
}

View file

@ -59,7 +59,7 @@ namespace AaxDecrypter
public abstract void Cancel();
protected abstract int GetSpeedup(TimeSpan elapsed);
protected abstract bool Step2_DownloadAudiobook();
protected abstract bool Step2_DownloadAudiobookAsSingleFile(); //TODO do I need to change this??
protected abstract bool Step1_GetMetadata();
public virtual void SetCoverArt(byte[] coverArt)

View file

@ -21,7 +21,7 @@ namespace AaxDecrypter
Name = "Download Mp3 Audiobook",
["Step 1: Get Mp3 Metadata"] = Step1_GetMetadata,
["Step 2: Download Audiobook"] = Step2_DownloadAudiobook,
["Step 2: Download Audiobook"] = Step2_DownloadAudiobookAsSingleFile,
["Step 3: Create Cue"] = Step3_CreateCue,
["Step 4: Cleanup"] = Step4_Cleanup,
};
@ -46,7 +46,7 @@ namespace AaxDecrypter
return !isCanceled;
}
protected override bool Step2_DownloadAudiobook()
protected override bool Step2_DownloadAudiobookAsSingleFile()
{
DateTime startTime = DateTime.Now;