private async Task <string> downloadPdfAsync(LibraryBook libraryBook, string proposedDownloadFilePath) { OnStreamingBegin(proposedDownloadFilePath); try { var api = await libraryBook.GetApiAsync(); var downloadUrl = await api.GetPdfDownloadLinkAsync(libraryBook.Book.AudibleProductId); var progress = new Progress <DownloadProgress>(); progress.ProgressChanged += (_, e) => OnStreamingProgressChanged(e); var client = new HttpClient(); var actualDownloadedFilePath = await client.DownloadFileAsync(downloadUrl, proposedDownloadFilePath, progress); OnFileCreated(libraryBook, actualDownloadedFilePath); OnStatusUpdate(actualDownloadedFilePath); return(actualDownloadedFilePath); } finally { OnStreamingCompleted(proposedDownloadFilePath); } }
private async Task <bool> downloadAudiobookAsync(LibraryBook libraryBook) { OnStreamingBegin($"Begin decrypting {libraryBook}"); try { downloadValidation(libraryBook); var api = await libraryBook.GetApiAsync(); var contentLic = await api.GetDownloadLicenseAsync(libraryBook.Book.AudibleProductId); var audiobookDlLic = new DownloadLicense ( contentLic?.ContentMetadata?.ContentUrl?.OfflineUrl, contentLic?.Voucher?.Key, contentLic?.Voucher?.Iv, Resources.USER_AGENT ); //I assume if ContentFormat == "MPEG" that the delivered file is an unencrypted mp3. //I also assume that if DrmType != Adrm, the file will be an mp3. //These assumptions may be wrong, and only time and bug reports will tell. var outputFormat = contentLic.ContentMetadata.ContentReference.ContentFormat == "MPEG" || (Configuration.Instance.AllowLibationFixup && Configuration.Instance.DecryptToLossy) ? OutputFormat.Mp3 : OutputFormat.M4b; if (Configuration.Instance.AllowLibationFixup || outputFormat == OutputFormat.Mp3) { audiobookDlLic.ChapterInfo = new AAXClean.ChapterInfo(); foreach (var chap in contentLic.ContentMetadata?.ChapterInfo?.Chapters) { audiobookDlLic.ChapterInfo.AddChapter(chap.Title, TimeSpan.FromMilliseconds(chap.LengthMs)); } } var outFileName = AudibleFileStorage.Audio.GetInProgressFilename(libraryBook, outputFormat.ToString().ToLower()); var cacheDir = AudibleFileStorage.DownloadsInProgressDirectory; abDownloader = contentLic.DrmType != AudibleApi.Common.DrmType.Adrm ? new UnencryptedAudiobookDownloader(outFileName, cacheDir, audiobookDlLic) : Configuration.Instance.SplitFilesByChapter ? new AaxcDownloadMultiConverter( outFileName, cacheDir, audiobookDlLic, outputFormat, AudibleFileStorage.Audio.CreateMultipartRenamerFunc(libraryBook) ) : new AaxcDownloadSingleConverter(outFileName, cacheDir, audiobookDlLic, outputFormat); abDownloader.DecryptProgressUpdate += (_, progress) => OnStreamingProgressChanged(progress); abDownloader.DecryptTimeRemaining += (_, remaining) => OnStreamingTimeRemaining(remaining); abDownloader.RetrievedTitle += (_, title) => OnTitleDiscovered(title); abDownloader.RetrievedAuthors += (_, authors) => OnAuthorsDiscovered(authors); abDownloader.RetrievedNarrators += (_, narrators) => OnNarratorsDiscovered(narrators); abDownloader.RetrievedCoverArt += AaxcDownloader_RetrievedCoverArt; abDownloader.FileCreated += (_, path) => OnFileCreated(libraryBook, path); // REAL WORK DONE HERE var success = await Task.Run(abDownloader.Run); return(success); } finally { OnStreamingCompleted($"Completed downloading and decrypting {libraryBook.Book.Title}"); } }