Downloading to use new instance locale and account
This commit is contained in:
parent
2e5360f0ba
commit
714bb2ba50
6 changed files with 23 additions and 16 deletions
|
|
@ -43,8 +43,7 @@ namespace FileLiberator
|
|||
|
||||
private async Task<string> downloadBookAsync(LibraryBook libraryBook, string tempAaxFilename)
|
||||
{
|
||||
var locale = Localization.Get(libraryBook.Book.Locale);
|
||||
var api = await AudibleApiActions.GetApiAsync(locale);
|
||||
var api = await AudibleApiActions.GetApiAsync(libraryBook.Account, libraryBook.Book.Locale);
|
||||
|
||||
var actualFilePath = await PerformDownloadAsync(
|
||||
tempAaxFilename,
|
||||
|
|
|
|||
|
|
@ -13,12 +13,20 @@ namespace InternalUtilities
|
|||
public static class AudibleApiActions
|
||||
{
|
||||
/// <summary>USE THIS from within Libation. It wraps the call with correct JSONPath</summary>
|
||||
public static Task<Api> GetApiAsync(Locale locale, ILoginCallback loginCallback = null)
|
||||
=> EzApiCreator.GetApiAsync(locale, AudibleApiStorage.AccountsSettingsFile, AudibleApiStorage.TEST_GetFirstIdentityTokensJsonPath(), loginCallback);
|
||||
public static Task<Api> GetApiAsync(string username, string localeName, ILoginCallback loginCallback = null)
|
||||
=> EzApiCreator.GetApiAsync(
|
||||
Localization.Get(localeName),
|
||||
AudibleApiStorage.AccountsSettingsFile,
|
||||
AudibleApiStorage.GetIdentityTokensJsonPath(username, localeName),
|
||||
loginCallback);
|
||||
|
||||
/// <summary>USE THIS from within Libation. It wraps the call with correct JSONPath</summary>
|
||||
public static Task<Api> GetApiAsync(Account account, ILoginCallback loginCallback = null)
|
||||
=> EzApiCreator.GetApiAsync(account.Locale, AudibleApiStorage.AccountsSettingsFile, account.GetIdentityTokensJsonPath(), loginCallback);
|
||||
=> EzApiCreator.GetApiAsync(
|
||||
account.Locale,
|
||||
AudibleApiStorage.AccountsSettingsFile,
|
||||
account.GetIdentityTokensJsonPath(),
|
||||
loginCallback);
|
||||
|
||||
private static AsyncRetryPolicy policy { get; }
|
||||
= Policy.Handle<Exception>()
|
||||
|
|
|
|||
|
|
@ -43,9 +43,8 @@ namespace InternalUtilities
|
|||
|
||||
if (!libResult.Items.Any())
|
||||
break;
|
||||
else
|
||||
Serilog.Log.Logger.Information($"Page {i}: {libResult.Items.Length} results");
|
||||
|
||||
|
||||
Serilog.Log.Logger.Information($"Page {i}: {libResult.Items.Length} results");
|
||||
allItems.AddRange(libResult.Items);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,12 +28,12 @@ namespace InternalUtilities
|
|||
|
||||
public static string GetIdentityTokensJsonPath(this Account account)
|
||||
=> GetIdentityTokensJsonPath(account.AccountId, account.Locale?.Name);
|
||||
public static string GetIdentityTokensJsonPath(string username, string locale)
|
||||
public static string GetIdentityTokensJsonPath(string username, string localeName)
|
||||
{
|
||||
var usernameSanitized = trimSurroundingQuotes(JsonConvert.ToString(username));
|
||||
var localeSanitized = trimSurroundingQuotes(JsonConvert.ToString(locale));
|
||||
var localeNameSanitized = trimSurroundingQuotes(JsonConvert.ToString(localeName));
|
||||
|
||||
return $"$.AccountsSettings[?(@.AccountId == '{usernameSanitized}' && @.IdentityTokens.LocaleName == '{localeSanitized}')].IdentityTokens";
|
||||
return $"$.AccountsSettings[?(@.AccountId == '{usernameSanitized}' && @.IdentityTokens.LocaleName == '{localeNameSanitized}')].IdentityTokens";
|
||||
}
|
||||
// SubString algo is better than .Trim("\"")
|
||||
// orig string "
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
<!-- <PublishSingleFile>true</PublishSingleFile> -->
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
|
||||
<Version>3.1.12.194</Version>
|
||||
<Version>3.1.12.196</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -136,11 +136,12 @@ namespace LibationLauncher
|
|||
|
||||
private static Account addAccountToNewAccountFile()
|
||||
{
|
||||
// get locale from settings file
|
||||
// get required locale from settings file
|
||||
var settingsContents = File.ReadAllText(Configuration.Instance.SettingsFilePath);
|
||||
var jObj = JObject.Parse(settingsContents);
|
||||
var jLocale = jObj.Property("LocaleCountryCode");
|
||||
var localeName = jLocale.Value.Value<string>();
|
||||
if (!JObject.Parse(settingsContents).TryGetValue("LocaleCountryCode", out var jLocale))
|
||||
return null;
|
||||
|
||||
var localeName = jLocale.Value<string>();
|
||||
var locale = Localization.Get(localeName);
|
||||
|
||||
var api = EzApiCreator.GetApiAsync(locale, AccountsSettingsFileLegacy30).GetAwaiter().GetResult();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue