Downloading to use new instance locale and account

This commit is contained in:
Robert McRackan 2020-08-21 13:36:01 -04:00
parent 2e5360f0ba
commit 714bb2ba50
6 changed files with 23 additions and 16 deletions

View File

@ -43,8 +43,7 @@ namespace FileLiberator
private async Task<string> downloadBookAsync(LibraryBook libraryBook, string tempAaxFilename) private async Task<string> downloadBookAsync(LibraryBook libraryBook, string tempAaxFilename)
{ {
var locale = Localization.Get(libraryBook.Book.Locale); var api = await AudibleApiActions.GetApiAsync(libraryBook.Account, libraryBook.Book.Locale);
var api = await AudibleApiActions.GetApiAsync(locale);
var actualFilePath = await PerformDownloadAsync( var actualFilePath = await PerformDownloadAsync(
tempAaxFilename, tempAaxFilename,

View File

@ -13,12 +13,20 @@ namespace InternalUtilities
public static class AudibleApiActions public static class AudibleApiActions
{ {
/// <summary>USE THIS from within Libation. It wraps the call with correct JSONPath</summary> /// <summary>USE THIS from within Libation. It wraps the call with correct JSONPath</summary>
public static Task<Api> GetApiAsync(Locale locale, ILoginCallback loginCallback = null) public static Task<Api> GetApiAsync(string username, string localeName, ILoginCallback loginCallback = null)
=> EzApiCreator.GetApiAsync(locale, AudibleApiStorage.AccountsSettingsFile, AudibleApiStorage.TEST_GetFirstIdentityTokensJsonPath(), loginCallback); => 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> /// <summary>USE THIS from within Libation. It wraps the call with correct JSONPath</summary>
public static Task<Api> GetApiAsync(Account account, ILoginCallback loginCallback = null) 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; } private static AsyncRetryPolicy policy { get; }
= Policy.Handle<Exception>() = Policy.Handle<Exception>()

View File

@ -43,9 +43,8 @@ namespace InternalUtilities
if (!libResult.Items.Any()) if (!libResult.Items.Any())
break; 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); allItems.AddRange(libResult.Items);
} }

View File

@ -28,12 +28,12 @@ namespace InternalUtilities
public static string GetIdentityTokensJsonPath(this Account account) public static string GetIdentityTokensJsonPath(this Account account)
=> GetIdentityTokensJsonPath(account.AccountId, account.Locale?.Name); => 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 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("\"") // SubString algo is better than .Trim("\"")
// orig string " // orig string "

View File

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

View File

@ -136,11 +136,12 @@ namespace LibationLauncher
private static Account addAccountToNewAccountFile() private static Account addAccountToNewAccountFile()
{ {
// get locale from settings file // get required locale from settings file
var settingsContents = File.ReadAllText(Configuration.Instance.SettingsFilePath); var settingsContents = File.ReadAllText(Configuration.Instance.SettingsFilePath);
var jObj = JObject.Parse(settingsContents); if (!JObject.Parse(settingsContents).TryGetValue("LocaleCountryCode", out var jLocale))
var jLocale = jObj.Property("LocaleCountryCode"); return null;
var localeName = jLocale.Value.Value<string>();
var localeName = jLocale.Value<string>();
var locale = Localization.Get(localeName); var locale = Localization.Get(localeName);
var api = EzApiCreator.GetApiAsync(locale, AccountsSettingsFileLegacy30).GetAwaiter().GetResult(); var api = EzApiCreator.GetApiAsync(locale, AccountsSettingsFileLegacy30).GetAwaiter().GetResult();