Add <account nickname> tag (#629)

This commit is contained in:
Mbucari 2023-06-14 11:56:38 -06:00
parent 7a9c6720c7
commit 6d13325c4f
6 changed files with 38 additions and 22 deletions

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using AudibleUtilities;
using DataLayer; using DataLayer;
using Dinah.Core; using Dinah.Core;
using LibationFileManager; using LibationFileManager;
@ -20,13 +21,22 @@ namespace FileLiberator
public static async Task<AudibleApi.Api> GetApiAsync(this LibraryBook libraryBook) public static async Task<AudibleApi.Api> GetApiAsync(this LibraryBook libraryBook)
{ {
var apiExtended = await AudibleUtilities.ApiExtended.CreateAsync(libraryBook.Account, libraryBook.Book.Locale); var apiExtended = await ApiExtended.CreateAsync(libraryBook.Account, libraryBook.Book.Locale);
return apiExtended.Api; return apiExtended.Api;
} }
public static LibraryBookDto ToDto(this LibraryBook libraryBook) => new() public static LibraryBookDto ToDto(this LibraryBook libraryBook)
{
using var persister = AudibleApiStorage.GetAccountsSettingsPersister();
var nickname
= persister.AccountsSettings.Accounts
.FirstOrDefault(a => a.AccountId == libraryBook.Account)
?.AccountName;
return new()
{ {
Account = libraryBook.Account, Account = libraryBook.Account,
AccountNickname = nickname,
DateAdded = libraryBook.DateAdded, DateAdded = libraryBook.DateAdded,
AudibleProductId = libraryBook.Book.AudibleProductId, AudibleProductId = libraryBook.Book.AudibleProductId,
@ -50,4 +60,5 @@ namespace FileLiberator
Language = libraryBook.Book.Language Language = libraryBook.Book.Language
}; };
} }
}
} }

View File

@ -37,5 +37,6 @@ namespace LibationFileManager
{ {
public DateTime? DateAdded { get; set; } public DateTime? DateAdded { get; set; }
public string Account { get; set; } public string Account { get; set; }
public string AccountNickname { get; set; }
} }
} }

View File

@ -52,7 +52,8 @@ namespace LibationFileManager
private static readonly LibraryBookDto libraryBookDto private static readonly LibraryBookDto libraryBookDto
= new() = new()
{ {
Account = "my account", Account = "myaccount@example.co",
AccountNickname = "my account",
DateAdded = new DateTime(2022, 6, 9, 0, 0, 0), DateAdded = new DateTime(2022, 6, 9, 0, 0, 0),
DatePublished = new DateTime(2017, 2, 27, 0, 0, 0), DatePublished = new DateTime(2017, 2, 27, 0, 0, 0),
AudibleProductId = "123456789", AudibleProductId = "123456789",

View File

@ -37,6 +37,7 @@ namespace LibationFileManager
public static TemplateTags SampleRate { get; } = new TemplateTags("samplerate", "File's orig. sample rate"); public static TemplateTags SampleRate { get; } = new TemplateTags("samplerate", "File's orig. sample rate");
public static TemplateTags Channels { get; } = new TemplateTags("channels", "Number of audio channels"); public static TemplateTags Channels { get; } = new TemplateTags("channels", "Number of audio channels");
public static TemplateTags Account { get; } = new TemplateTags("account", "Audible account of this book"); public static TemplateTags Account { get; } = new TemplateTags("account", "Audible account of this book");
public static TemplateTags AccountNickname { get; } = new TemplateTags("account nickname", "Audible account nickname of this book");
public static TemplateTags Locale { get; } = new ("locale", "Region/country"); public static TemplateTags Locale { get; } = new ("locale", "Region/country");
public static TemplateTags YearPublished { get; } = new("year", "Year published"); public static TemplateTags YearPublished { get; } = new("year", "Year published");
public static TemplateTags Language { get; } = new("language", "Book's language"); public static TemplateTags Language { get; } = new("language", "Book's language");

View File

@ -215,6 +215,7 @@ namespace LibationFileManager
{ TemplateTags.SampleRate, lb => (int?)(lb.IsPodcastParent ? null : lb.SampleRate) }, { TemplateTags.SampleRate, lb => (int?)(lb.IsPodcastParent ? null : lb.SampleRate) },
{ TemplateTags.Channels, lb => (int?)(lb.IsPodcastParent ? null : lb.Channels) }, { TemplateTags.Channels, lb => (int?)(lb.IsPodcastParent ? null : lb.Channels) },
{ TemplateTags.Account, lb => lb.Account }, { TemplateTags.Account, lb => lb.Account },
{ TemplateTags.AccountNickname, lb => lb.AccountNickname },
{ TemplateTags.Locale, lb => lb.Locale }, { TemplateTags.Locale, lb => lb.Locale },
{ TemplateTags.YearPublished, lb => lb.YearPublished }, { TemplateTags.YearPublished, lb => lb.YearPublished },
{ TemplateTags.DatePublished, lb => lb.DatePublished }, { TemplateTags.DatePublished, lb => lb.DatePublished },

View File

@ -26,7 +26,8 @@ namespace TemplatesTests
public static LibraryBookDto GetLibraryBook(string seriesName = "Sherlock Holmes") public static LibraryBookDto GetLibraryBook(string seriesName = "Sherlock Holmes")
=> new() => new()
{ {
Account = "my account", Account = "myaccount@example.co",
AccountNickname = "my account",
DateAdded = new DateTime(2022, 6, 9, 0, 0, 0), DateAdded = new DateTime(2022, 6, 9, 0, 0, 0),
DatePublished = new DateTime(2017, 2, 27, 0, 0, 0), DatePublished = new DateTime(2017, 2, 27, 0, 0, 0),
FileDate = new DateTime(2023, 1, 28, 0, 0, 0), FileDate = new DateTime(2023, 1, 28, 0, 0, 0),