* include new external login interfaces in ApiExtended
* new ext method to simplify api access in file liberator
This commit is contained in:
parent
51020ef99e
commit
926a7a1148
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<Version>6.0.0.1</Version>
|
<Version>6.0.0.2</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using AudibleApi.Common;
|
using AudibleApi.Common;
|
||||||
|
|
||||||
namespace InternalUtilities
|
namespace DtoImporterService
|
||||||
{
|
{
|
||||||
public class ImportItem
|
public class ImportItem
|
||||||
{
|
{
|
||||||
@ -84,9 +84,8 @@ namespace FileLiberator
|
|||||||
{
|
{
|
||||||
validate(libraryBook);
|
validate(libraryBook);
|
||||||
|
|
||||||
var apiExtended = await InternalUtilities.ApiExtended.CreateAsync(libraryBook.Account, libraryBook.Book.Locale);
|
var api = await libraryBook.GetApiAsync();
|
||||||
|
var contentLic = await api.GetDownloadLicenseAsync(libraryBook.Book.AudibleProductId);
|
||||||
var contentLic = await apiExtended.Api.GetDownloadLicenseAsync(libraryBook.Book.AudibleProductId);
|
|
||||||
|
|
||||||
var aaxcDecryptDlLic = new DownloadLicense
|
var aaxcDecryptDlLic = new DownloadLicense
|
||||||
(
|
(
|
||||||
|
|||||||
@ -59,8 +59,8 @@ namespace FileLiberator
|
|||||||
|
|
||||||
private async Task<string> downloadPdfAsync(LibraryBook libraryBook, string proposedDownloadFilePath)
|
private async Task<string> downloadPdfAsync(LibraryBook libraryBook, string proposedDownloadFilePath)
|
||||||
{
|
{
|
||||||
var apiExtended = await GetApiExtendedAsync(libraryBook);
|
var api = await libraryBook.GetApiAsync();
|
||||||
var downloadUrl = await apiExtended.Api.GetPdfDownloadLinkAsync(libraryBook.Book.AudibleProductId);
|
var downloadUrl = await api.GetPdfDownloadLinkAsync(libraryBook.Book.AudibleProductId);
|
||||||
|
|
||||||
var client = new HttpClient();
|
var client = new HttpClient();
|
||||||
var actualDownloadedFilePath = await PerformDownloadAsync(
|
var actualDownloadedFilePath = await PerformDownloadAsync(
|
||||||
|
|||||||
@ -40,9 +40,6 @@ namespace FileLiberator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Task<InternalUtilities.ApiExtended> GetApiExtendedAsync(LibraryBook libraryBook)
|
|
||||||
=> InternalUtilities.ApiExtended.CreateAsync(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>();
|
||||||
|
|||||||
@ -1,16 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DataLayer;
|
using DataLayer;
|
||||||
using Dinah.Core;
|
using Dinah.Core;
|
||||||
using Dinah.Core.ErrorHandling;
|
|
||||||
|
|
||||||
namespace FileLiberator
|
namespace FileLiberator
|
||||||
{
|
{
|
||||||
public static class LoggerUtilities
|
public static class UtilityExtensions
|
||||||
{
|
{
|
||||||
public static (string id, string title, string locale, string account) LogFriendly(this LibraryBook libraryBook)
|
public static (string id, string title, string locale, string account) LogFriendly(this LibraryBook libraryBook)
|
||||||
=> (
|
=> (
|
||||||
@ -19,5 +16,11 @@ namespace FileLiberator
|
|||||||
locale: libraryBook.Book.Locale,
|
locale: libraryBook.Book.Locale,
|
||||||
account: libraryBook.Account.ToMask()
|
account: libraryBook.Account.ToMask()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public static async Task<AudibleApi.Api> GetApiAsync(this LibraryBook libraryBook)
|
||||||
|
{
|
||||||
|
var apiExtended = await InternalUtilities.ApiExtended.CreateAsync(libraryBook.Account, libraryBook.Book.Locale);
|
||||||
|
return apiExtended.Api;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -17,6 +17,57 @@ namespace InternalUtilities
|
|||||||
|
|
||||||
private ApiExtended(Api api) => Api = api;
|
private ApiExtended(Api api) => Api = api;
|
||||||
|
|
||||||
|
public static async Task<ApiExtended> CreateAsync(ILoginChoice loginChoice, Account account)
|
||||||
|
{
|
||||||
|
Serilog.Log.Logger.Information("GetApiAsync. {@DebugInfo}", new
|
||||||
|
{
|
||||||
|
LoginType = nameof(ILoginChoice),
|
||||||
|
Account = account?.MaskedLogEntry ?? "[null]",
|
||||||
|
LocaleName = account?.Locale?.Name
|
||||||
|
});
|
||||||
|
|
||||||
|
var api = await EzApiCreator.GetApiAsync(
|
||||||
|
account.Locale,
|
||||||
|
AudibleApiStorage.AccountsSettingsFile,
|
||||||
|
loginChoice,
|
||||||
|
account.GetIdentityTokensJsonPath());
|
||||||
|
return new ApiExtended(api);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<ApiExtended> CreateAsync(ILoginCallback loginCallback, Account account)
|
||||||
|
{
|
||||||
|
Serilog.Log.Logger.Information("GetApiAsync ILoginCallback. {@DebugInfo}", new
|
||||||
|
{
|
||||||
|
LoginType = nameof(ILoginCallback),
|
||||||
|
Account = account?.MaskedLogEntry ?? "[null]",
|
||||||
|
LocaleName = account?.Locale?.Name
|
||||||
|
});
|
||||||
|
|
||||||
|
var api = await EzApiCreator.GetApiAsync(
|
||||||
|
account.Locale,
|
||||||
|
AudibleApiStorage.AccountsSettingsFile,
|
||||||
|
loginCallback,
|
||||||
|
account.GetIdentityTokensJsonPath());
|
||||||
|
return new ApiExtended(api);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<ApiExtended> CreateAsync(ILoginExternal loginExternal, Account account)
|
||||||
|
{
|
||||||
|
Serilog.Log.Logger.Information("GetApiAsync ILoginExternal. {@DebugInfo}", new
|
||||||
|
{
|
||||||
|
LoginType = nameof(ILoginExternal),
|
||||||
|
Account = account?.MaskedLogEntry ?? "[null]",
|
||||||
|
LocaleName = account?.Locale?.Name
|
||||||
|
});
|
||||||
|
|
||||||
|
var api = await EzApiCreator.GetApiAsync(
|
||||||
|
account.Locale,
|
||||||
|
AudibleApiStorage.AccountsSettingsFile,
|
||||||
|
loginExternal,
|
||||||
|
account.GetIdentityTokensJsonPath());
|
||||||
|
return new ApiExtended(api);
|
||||||
|
}
|
||||||
|
|
||||||
public static async Task<ApiExtended> CreateAsync(string username, string localeName)
|
public static async Task<ApiExtended> CreateAsync(string username, string localeName)
|
||||||
{
|
{
|
||||||
Serilog.Log.Logger.Information("GetApiAsync. {@DebugInfo}", new
|
Serilog.Log.Logger.Information("GetApiAsync. {@DebugInfo}", new
|
||||||
@ -32,22 +83,6 @@ namespace InternalUtilities
|
|||||||
return new ApiExtended(api);
|
return new ApiExtended(api);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<ApiExtended> CreateAsync(ILoginCallback loginCallback, Account account)
|
|
||||||
{
|
|
||||||
Serilog.Log.Logger.Information("GetApiAsync. {@DebugInfo}", new
|
|
||||||
{
|
|
||||||
Account = account?.MaskedLogEntry ?? "[null]",
|
|
||||||
LocaleName = account?.Locale?.Name
|
|
||||||
});
|
|
||||||
|
|
||||||
var api = await EzApiCreator.GetApiAsync(
|
|
||||||
account.Locale,
|
|
||||||
AudibleApiStorage.AccountsSettingsFile,
|
|
||||||
loginCallback,
|
|
||||||
account.GetIdentityTokensJsonPath());
|
|
||||||
return new ApiExtended(api);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static AsyncRetryPolicy policy { get; }
|
private static AsyncRetryPolicy policy { get; }
|
||||||
= Policy.Handle<Exception>()
|
= Policy.Handle<Exception>()
|
||||||
// 2 retries == 3 total
|
// 2 retries == 3 total
|
||||||
|
|||||||
@ -76,9 +76,9 @@ namespace InternalUtilities
|
|||||||
|
|
||||||
var distinct = items.GetSeriesDistinct();
|
var distinct = items.GetSeriesDistinct();
|
||||||
if (distinct.Any(s => s.SeriesId is null))
|
if (distinct.Any(s => s.SeriesId is null))
|
||||||
exceptions.Add(new ArgumentException($"Collection contains {nameof(Item.Series)} with null {nameof(AudibleApi.Common.Series.SeriesId)}", nameof(items)));
|
exceptions.Add(new ArgumentException($"Collection contains {nameof(Item.Series)} with null {nameof(Series.SeriesId)}", nameof(items)));
|
||||||
if (distinct.Any(s => s.SeriesName is null))
|
if (distinct.Any(s => s.SeriesName is null))
|
||||||
exceptions.Add(new ArgumentException($"Collection contains {nameof(Item.Series)} with null {nameof(AudibleApi.Common.Series.SeriesName)}", nameof(items)));
|
exceptions.Add(new ArgumentException($"Collection contains {nameof(Item.Series)} with null {nameof(Series.SeriesName)}", nameof(items)));
|
||||||
|
|
||||||
return exceptions;
|
return exceptions;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user