Audible whack-a-mole: they changed how to download pdfs

This commit is contained in:
Robert McRackan 2020-09-21 13:10:36 -04:00
parent dfc4121ab0
commit 4509b8c8eb
7 changed files with 14 additions and 12 deletions

View File

@ -45,7 +45,7 @@ namespace FileLiberator
{ {
validate(libraryBook); validate(libraryBook);
var api = await AudibleApiActions.GetApiAsync(libraryBook.Account, libraryBook.Book.Locale); var api = await GetApiAsync(libraryBook);
var actualFilePath = await PerformDownloadAsync( var actualFilePath = await PerformDownloadAsync(
tempAaxFilename, tempAaxFilename,

View File

@ -41,7 +41,8 @@ namespace FileLiberator
private async Task downloadPdfAsync(LibraryBook libraryBook, string proposedDownloadFilePath) 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 client = new HttpClient();
var actualDownloadedFilePath = await PerformDownloadAsync( var actualDownloadedFilePath = await PerformDownloadAsync(

View File

@ -38,6 +38,9 @@ namespace FileLiberator
} }
} }
protected static Task<AudibleApi.Api> GetApiAsync(LibraryBook libraryBook)
=> InternalUtilities.AudibleApiActions.GetApiAsync(libraryBook.Account, libraryBook.Book.Locale);
protected async Task<string> PerformDownloadAsync(string proposedDownloadFilePath, Func<Progress<DownloadProgress>, Task<string>> func) protected async Task<string> PerformDownloadAsync(string proposedDownloadFilePath, Func<Progress<DownloadProgress>, Task<string>> func)
{ {
var progress = new Progress<DownloadProgress>(); var progress = new Progress<DownloadProgress>();

View File

@ -13,7 +13,7 @@
<!-- <PublishSingleFile>true</PublishSingleFile> --> <!-- <PublishSingleFile>true</PublishSingleFile> -->
<RuntimeIdentifier>win-x64</RuntimeIdentifier> <RuntimeIdentifier>win-x64</RuntimeIdentifier>
<Version>4.0.6.4</Version> <Version>4.0.7.2</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -27,9 +27,7 @@
<Compile Update="UNTESTED\Dialogs\LibationFilesDialog.Designer.cs"> <Compile Update="UNTESTED\Dialogs\LibationFilesDialog.Designer.cs">
<DependentUpon>LibationFilesDialog.cs</DependentUpon> <DependentUpon>LibationFilesDialog.cs</DependentUpon>
</Compile> </Compile>
<Compile Update="UNTESTED\Dialogs\ScanAccountsDialog.cs"> <Compile Update="UNTESTED\Dialogs\ScanAccountsDialog.cs" />
<SubType>Form</SubType>
</Compile>
<Compile Update="UNTESTED\Dialogs\ScanAccountsDialog.Designer.cs"> <Compile Update="UNTESTED\Dialogs\ScanAccountsDialog.Designer.cs">
<DependentUpon>ScanAccountsDialog.cs</DependentUpon> <DependentUpon>ScanAccountsDialog.cs</DependentUpon>
</Compile> </Compile>

View File

@ -17,15 +17,15 @@ namespace LibationWinForms.BookLiberation
// thread-safe UI updates // thread-safe UI updates
public void UpdateFilename(string title) => filenameLbl.UIThread(() => filenameLbl.Text = title); 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 // this won't happen with download file. it will happen with download string
if (TotalBytesToReceive < 0) if (!TotalBytesToReceive.HasValue || TotalBytesToReceive.Value <= 0)
return; 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()); var i = int.Parse(Math.Truncate(d).ToString());
progressBar1.UIThread(() => progressBar1.Value = i); progressBar1.UIThread(() => progressBar1.Value = i);

View File

@ -126,7 +126,7 @@ namespace LibationWinForms.BookLiberation
downloadDialog.UpdateFilename(str); downloadDialog.UpdateFilename(str);
downloadDialog.Show(); 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(); downloadFile.DownloadCompleted += (_, __) => downloadDialog.Close();
await downloadFile.PerformDownloadFileAsync(url, destination); await downloadFile.PerformDownloadFileAsync(url, destination);
@ -161,7 +161,7 @@ namespace LibationWinForms.BookLiberation
void fileDownloadCompleted(object _, string __) => downloadDialog.Close(); void fileDownloadCompleted(object _, string __) => downloadDialog.Close();
void downloadProgressChanged(object _, Dinah.Core.Net.Http.DownloadProgress progress) 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) void unsubscribe(object _ = null, EventArgs __ = null)
{ {