private async Task <string> aaxToM4bConverterDecrypt(string aaxFilename, LibraryBook libraryBook) { DecryptBegin?.Invoke(this, $"Begin decrypting {aaxFilename}"); try { using var persister = AudibleApiStorage.GetAccountsSettingsPersister(); var account = persister .AccountsSettings .GetAccount(libraryBook.Account, libraryBook.Book.Locale); var converter = await AaxToM4bConverter.CreateAsync(aaxFilename, account.DecryptKey); converter.AppName = "Libation"; TitleDiscovered?.Invoke(this, converter.tags.title); AuthorsDiscovered?.Invoke(this, converter.tags.author); NarratorsDiscovered?.Invoke(this, converter.tags.narrator); CoverImageFilepathDiscovered?.Invoke(this, converter.coverBytes); // override default which was set in CreateAsync var proposedOutputFile = Path.Combine(AudibleFileStorage.DecryptInProgress, $"[{libraryBook.Book.AudibleProductId}].m4b"); converter.SetOutputFilename(proposedOutputFile); converter.DecryptProgressUpdate += (s, progress) => UpdateProgress?.Invoke(this, progress); // REAL WORK DONE HERE var success = await Task.Run(() => converter.Run()); // decrypt failed if (!success) { return(null); } account.DecryptKey = converter.decryptKey; return(converter.outputFileName); } finally { DecryptCompleted?.Invoke(this, $"Completed decrypting {aaxFilename}"); } }
private async Task <string> aaxToM4bConverterDecryptAsync(string cacheDir, string destinationDir, LibraryBook libraryBook) { DecryptBegin?.Invoke(this, $"Begin decrypting {libraryBook}"); try { validate(libraryBook); var api = await InternalUtilities.AudibleApiActions.GetApiAsync(libraryBook.Account, libraryBook.Book.Locale); var contentLic = await api.GetDownloadLicenseAsync(libraryBook.Book.AudibleProductId); var aaxcDecryptDlLic = new DownloadLicense ( contentLic.ContentMetadata?.ContentUrl?.OfflineUrl, contentLic.Voucher?.Key, contentLic.Voucher?.Iv, Resources.UserAgent ); if (Configuration.Instance.AllowLibationFixup) { aaxcDecryptDlLic.ChapterInfo = new AAXClean.ChapterInfo(); foreach (var chap in contentLic.ContentMetadata?.ChapterInfo?.Chapters) { aaxcDecryptDlLic.ChapterInfo.AddChapter(chap.Title, TimeSpan.FromMilliseconds(chap.LengthMs)); } } var format = Configuration.Instance.DecryptToLossy ? OutputFormat.Mp3 : OutputFormat.Mp4a; var extension = format switch { OutputFormat.Mp4a => "m4b", OutputFormat.Mp3 => "mp3", _ => throw new NotImplementedException(), }; var proposedOutputFile = Path.Combine(destinationDir, $"{PathLib.ToPathSafeString(libraryBook.Book.Title)} [{libraryBook.Book.AudibleProductId}].{extension}"); aaxcDownloader = new AaxcDownloadConverter(proposedOutputFile, cacheDir, aaxcDecryptDlLic, format) { AppName = "Libation" }; aaxcDownloader.DecryptProgressUpdate += (s, progress) => UpdateProgress?.Invoke(this, progress); aaxcDownloader.DecryptTimeRemaining += (s, remaining) => UpdateRemainingTime?.Invoke(this, remaining); aaxcDownloader.RetrievedCoverArt += AaxcDownloader_RetrievedCoverArt; aaxcDownloader.RetrievedTags += aaxcDownloader_RetrievedTags; // REAL WORK DONE HERE var success = await Task.Run(() => aaxcDownloader.Run()); // decrypt failed if (!success) { return(null); } return(aaxcDownloader.OutputFileName); } finally { DecryptCompleted?.Invoke(this, $"Completed downloading and decrypting {libraryBook.Book.Title}"); } }