From 4509b8c8eb58b89ba1464ee74a4881c38e41d5ad Mon Sep 17 00:00:00 2001 From: Robert McRackan Date: Mon, 21 Sep 2020 13:10:36 -0400 Subject: [PATCH] Audible whack-a-mole: they changed how to download pdfs --- FileLiberator/UNTESTED/DownloadBook.cs | 2 +- FileLiberator/UNTESTED/DownloadPdf.cs | 3 ++- FileLiberator/UNTESTED/DownloadableBase.cs | 3 +++ LibationLauncher/LibationLauncher.csproj | 2 +- LibationWinForms/LibationWinForms.csproj | 4 +--- LibationWinForms/UNTESTED/BookLiberation/DownloadForm.cs | 8 ++++---- .../BookLiberation/ProcessorAutomationController.cs | 4 ++-- 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/FileLiberator/UNTESTED/DownloadBook.cs b/FileLiberator/UNTESTED/DownloadBook.cs index f3eecbfb..7d90e864 100644 --- a/FileLiberator/UNTESTED/DownloadBook.cs +++ b/FileLiberator/UNTESTED/DownloadBook.cs @@ -45,7 +45,7 @@ namespace FileLiberator { validate(libraryBook); - var api = await AudibleApiActions.GetApiAsync(libraryBook.Account, libraryBook.Book.Locale); + var api = await GetApiAsync(libraryBook); var actualFilePath = await PerformDownloadAsync( tempAaxFilename, diff --git a/FileLiberator/UNTESTED/DownloadPdf.cs b/FileLiberator/UNTESTED/DownloadPdf.cs index 41e5d68a..2a41f793 100644 --- a/FileLiberator/UNTESTED/DownloadPdf.cs +++ b/FileLiberator/UNTESTED/DownloadPdf.cs @@ -41,7 +41,8 @@ namespace FileLiberator private async Task downloadPdfAsync(LibraryBook libraryBook, string proposedDownloadFilePath) { - var downloadUrl = getdownloadUrl(libraryBook); + var api = await GetApiAsync(libraryBook); + var downloadUrl = await api.GetPdfDownloadLinkAsync(libraryBook.Book.AudibleProductId); var client = new HttpClient(); var actualDownloadedFilePath = await PerformDownloadAsync( diff --git a/FileLiberator/UNTESTED/DownloadableBase.cs b/FileLiberator/UNTESTED/DownloadableBase.cs index ba0d3966..da78a8a6 100644 --- a/FileLiberator/UNTESTED/DownloadableBase.cs +++ b/FileLiberator/UNTESTED/DownloadableBase.cs @@ -38,6 +38,9 @@ namespace FileLiberator } } + protected static Task GetApiAsync(LibraryBook libraryBook) + => InternalUtilities.AudibleApiActions.GetApiAsync(libraryBook.Account, libraryBook.Book.Locale); + protected async Task PerformDownloadAsync(string proposedDownloadFilePath, Func, Task> func) { var progress = new Progress(); diff --git a/LibationLauncher/LibationLauncher.csproj b/LibationLauncher/LibationLauncher.csproj index 75b6dd85..9702bd61 100644 --- a/LibationLauncher/LibationLauncher.csproj +++ b/LibationLauncher/LibationLauncher.csproj @@ -13,7 +13,7 @@ win-x64 - 4.0.6.4 + 4.0.7.2 diff --git a/LibationWinForms/LibationWinForms.csproj b/LibationWinForms/LibationWinForms.csproj index a5634bb3..9ab8af74 100644 --- a/LibationWinForms/LibationWinForms.csproj +++ b/LibationWinForms/LibationWinForms.csproj @@ -27,9 +27,7 @@ LibationFilesDialog.cs - - Form - + ScanAccountsDialog.cs diff --git a/LibationWinForms/UNTESTED/BookLiberation/DownloadForm.cs b/LibationWinForms/UNTESTED/BookLiberation/DownloadForm.cs index 9390368f..c6083826 100644 --- a/LibationWinForms/UNTESTED/BookLiberation/DownloadForm.cs +++ b/LibationWinForms/UNTESTED/BookLiberation/DownloadForm.cs @@ -17,15 +17,15 @@ namespace LibationWinForms.BookLiberation // thread-safe UI updates public void UpdateFilename(string title) => filenameLbl.UIThread(() => filenameLbl.Text = title); - public void DownloadProgressChanged(long BytesReceived, long TotalBytesToReceive) + public void DownloadProgressChanged(long BytesReceived, long? TotalBytesToReceive) { // this won't happen with download file. it will happen with download string - if (TotalBytesToReceive < 0) + if (!TotalBytesToReceive.HasValue || TotalBytesToReceive.Value <= 0) return; - progressLbl.UIThread(() => progressLbl.Text = $"{BytesReceived:#,##0} of {TotalBytesToReceive:#,##0}"); + progressLbl.UIThread(() => progressLbl.Text = $"{BytesReceived:#,##0} of {TotalBytesToReceive.Value:#,##0}"); - var d = double.Parse(BytesReceived.ToString()) / double.Parse(TotalBytesToReceive.ToString()) * 100.0; + var d = double.Parse(BytesReceived.ToString()) / double.Parse(TotalBytesToReceive.Value.ToString()) * 100.0; var i = int.Parse(Math.Truncate(d).ToString()); progressBar1.UIThread(() => progressBar1.Value = i); diff --git a/LibationWinForms/UNTESTED/BookLiberation/ProcessorAutomationController.cs b/LibationWinForms/UNTESTED/BookLiberation/ProcessorAutomationController.cs index e8731f0a..eabc5623 100644 --- a/LibationWinForms/UNTESTED/BookLiberation/ProcessorAutomationController.cs +++ b/LibationWinForms/UNTESTED/BookLiberation/ProcessorAutomationController.cs @@ -126,7 +126,7 @@ namespace LibationWinForms.BookLiberation downloadDialog.UpdateFilename(str); downloadDialog.Show(); }; - downloadFile.DownloadProgressChanged += (_, progress) => downloadDialog.DownloadProgressChanged(progress.BytesReceived, progress.TotalBytesToReceive.Value); + downloadFile.DownloadProgressChanged += (_, progress) => downloadDialog.DownloadProgressChanged(progress.BytesReceived, progress.TotalBytesToReceive); downloadFile.DownloadCompleted += (_, __) => downloadDialog.Close(); await downloadFile.PerformDownloadFileAsync(url, destination); @@ -161,7 +161,7 @@ namespace LibationWinForms.BookLiberation void fileDownloadCompleted(object _, string __) => downloadDialog.Close(); void downloadProgressChanged(object _, Dinah.Core.Net.Http.DownloadProgress progress) - => downloadDialog.DownloadProgressChanged(progress.BytesReceived, progress.TotalBytesToReceive.Value); + => downloadDialog.DownloadProgressChanged(progress.BytesReceived, progress.TotalBytesToReceive); void unsubscribe(object _ = null, EventArgs __ = null) {