diff --git a/FileLiberator/UNTESTED/DecryptBook.cs b/FileLiberator/UNTESTED/DecryptBook.cs index 685d9c41..b331d137 100644 --- a/FileLiberator/UNTESTED/DecryptBook.cs +++ b/FileLiberator/UNTESTED/DecryptBook.cs @@ -56,7 +56,9 @@ namespace FileLiberator if (AudibleFileStorage.Audio.Exists(libraryBook.Book.AudibleProductId)) return new StatusHandler { "Cannot find decrypt. Final audio file already exists" }; - var outputAudioFilename = await aaxToM4bConverterDecrypt(aaxFilename, libraryBook); + var chapters = await downloadChapterNames(libraryBook); + + var outputAudioFilename = await aaxToM4bConverterDecrypt(aaxFilename, libraryBook, chapters); // decrypt failed if (outputAudioFilename == null) @@ -90,7 +92,7 @@ namespace FileLiberator } } - private async Task aaxToM4bConverterDecrypt(string aaxFilename, LibraryBook libraryBook) + private async Task aaxToM4bConverterDecrypt(string aaxFilename, LibraryBook libraryBook, Chapters chapters = null) { DecryptBegin?.Invoke(this, $"Begin decrypting {aaxFilename}"); @@ -102,7 +104,7 @@ namespace FileLiberator .AccountsSettings .GetAccount(libraryBook.Account, libraryBook.Book.Locale); - var converter = await AaxToM4bConverter.CreateAsync(aaxFilename, account.DecryptKey); + var converter = await AaxToM4bConverter.CreateAsync(aaxFilename, account.DecryptKey, chapters); converter.AppName = "Libation"; TitleDiscovered?.Invoke(this, converter.tags.title); @@ -132,6 +134,23 @@ namespace FileLiberator } } + private async Task downloadChapterNames(LibraryBook libraryBook) + { + try + { + var api = await AudibleApiActions.GetApiAsync(libraryBook.Account, libraryBook.Book.Locale); + var contentMetadata = await api.GetLibraryBookMetadataAsync(libraryBook.Book.AudibleProductId); + + if (contentMetadata?.ChapterInfo != null) + return new DownloadedChapters(contentMetadata.ChapterInfo); + return null; + } + catch + { + return null; + } + } + private static string moveFilesToBooksDir(Book product, string outputAudioFilename) { // create final directory. move each file into it. MOVE AUDIO FILE LAST diff --git a/FileLiberator/UNTESTED/DownloadedChapters.cs b/FileLiberator/UNTESTED/DownloadedChapters.cs new file mode 100644 index 00000000..7a95f83c --- /dev/null +++ b/FileLiberator/UNTESTED/DownloadedChapters.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.Linq; +using System.Text; +using AaxDecrypter; +using AudibleApiDTOs; +using Dinah.Core.Diagnostics; + + +namespace FileLiberator +{ + public class DownloadedChapters : Chapters + { + public DownloadedChapters(ChapterInfo chapterInfo) + { + AddChapters(chapterInfo.Chapters + .Select(c => new AaxDecrypter.Chapter(c.StartOffsetMs / 1000d, (c.StartOffsetMs + c.LengthMs) / 1000d, c.Title))); + } + } +} diff --git a/LibationLauncher/LibationLauncher.csproj b/LibationLauncher/LibationLauncher.csproj index c5b085d2..2bf9d8e8 100644 --- a/LibationLauncher/LibationLauncher.csproj +++ b/LibationLauncher/LibationLauncher.csproj @@ -13,7 +13,7 @@ win-x64 - 4.2.4.8 + 4.2.4.9