From 13294d3414f7f85092bd3c8dea2420b6386f5109 Mon Sep 17 00:00:00 2001 From: Sean Kelly Date: Mon, 27 Sep 2021 21:34:43 +1300 Subject: [PATCH] Added m4b & mp3 methods for multiple files. --- AaxDecrypter/AaxcDownloadConverter.cs | 45 ++++++++++++++++----------- FileLiberator/DownloadDecryptBook.cs | 2 +- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/AaxDecrypter/AaxcDownloadConverter.cs b/AaxDecrypter/AaxcDownloadConverter.cs index b9da026e..a261ce06 100644 --- a/AaxDecrypter/AaxcDownloadConverter.cs +++ b/AaxDecrypter/AaxcDownloadConverter.cs @@ -102,8 +102,33 @@ namespace AaxDecrypter aaxFile.SetDecryptionKey(downloadLicense.AudibleKey, downloadLicense.AudibleIV); aaxFile.ConversionProgressUpdate += AaxFile_ConversionProgressUpdate; + if(OutputFormat == OutputFormat.M4b) + ConvertToMultiMp4b(); + else + ConvertToMultiMp3(); + aaxFile.ConversionProgressUpdate -= AaxFile_ConversionProgressUpdate; + + aaxFile.Close(); + + return true; + } + + private void ConvertToMultiMp4b() + { + var chapterCount = 0; + aaxFile.ConvertToMultiMp4a(downloadLicense.ChapterInfo, newSplitCallback => + { + chapterCount++; + var fileName = Path.ChangeExtension(outputFileName, $"{chapterCount}.m4b"); + if (File.Exists(fileName)) + FileExt.SafeDelete(fileName); + newSplitCallback.OutputFile = File.Open(fileName, FileMode.OpenOrCreate); + }); + } + + private void ConvertToMultiMp3() + { var chapterCount = 0; - //TODO make this work with m4b files aaxFile.ConvertToMultiMp3(downloadLicense.ChapterInfo, newSplitCallback => { chapterCount++; @@ -111,24 +136,8 @@ 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() - { - Track = chapterCount.ToString(), - Artist = aaxFile.AppleTags.AlbumArtists, - Album = aaxFile.AppleTags.Album, - Title = aaxFile.AppleTags.Title, - Genre = aaxFile.AppleTags.Generes - } - }; + newSplitCallback.LameConfig.ID3.Track = chapterCount.ToString(); }); - aaxFile.ConversionProgressUpdate -= AaxFile_ConversionProgressUpdate; - - aaxFile.Close(); - - return true; } private void AaxFile_ConversionProgressUpdate(object sender, ConversionProgressEventArgs e) diff --git a/FileLiberator/DownloadDecryptBook.cs b/FileLiberator/DownloadDecryptBook.cs index 0a993fc1..aebebba4 100644 --- a/FileLiberator/DownloadDecryptBook.cs +++ b/FileLiberator/DownloadDecryptBook.cs @@ -140,7 +140,7 @@ namespace FileLiberator { // create final directory. move each file into it. MOVE AUDIO FILE LAST // new dir: safetitle_limit50char + " [" + productId + "]" - + // TODO make this method handle multiple audio files or a single audio file. var destinationDir = AudibleFileStorage.Audio.GetDestDir(product.Title, product.AudibleProductId); Directory.CreateDirectory(destinationDir);