From b9770220dbc189801905a3b918f68c802f3817e6 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Thu, 1 Jul 2021 21:56:38 -0600 Subject: [PATCH 1/9] Fixed stupid mistake. I need to go to ber. --- AaxDecrypter/AaxcDownloadConverter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AaxDecrypter/AaxcDownloadConverter.cs b/AaxDecrypter/AaxcDownloadConverter.cs index 7438ec61..2944c9d7 100644 --- a/AaxDecrypter/AaxcDownloadConverter.cs +++ b/AaxDecrypter/AaxcDownloadConverter.cs @@ -230,7 +230,7 @@ namespace AaxDecrypter } catch (Exception ex) { - Serilog.Log.Logger.Error(ex, $"{nameof(Step5_CreateCue)}. FAILED"); + Serilog.Log.Logger.Error(ex, $"{nameof(Step6_CreateNfo)}. FAILED"); } return !isCanceled; } From 5d4bcb2db0d936a1bb7e49f6c0fd5f2131064064 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Fri, 2 Jul 2021 13:50:18 -0600 Subject: [PATCH 2/9] Removed unnecessary conversion to List. --- DtoImporterService/BookImporter.cs | 4 ++-- DtoImporterService/LibraryImporter.cs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/DtoImporterService/BookImporter.cs b/DtoImporterService/BookImporter.cs index 8d6bbd27..4fe3a70e 100644 --- a/DtoImporterService/BookImporter.cs +++ b/DtoImporterService/BookImporter.cs @@ -21,7 +21,7 @@ namespace DtoImporterService new CategoryImporter(DbContext).Import(importItems); // get distinct - var productIds = importItems.Select(i => i.DtoItem.ProductId).ToList(); + var productIds = importItems.Select(i => i.DtoItem.ProductId); // load db existing => .Local loadLocal_books(productIds); @@ -31,7 +31,7 @@ namespace DtoImporterService return qtyNew; } - private void loadLocal_books(List productIds) + private void loadLocal_books(IEnumerable productIds) { var localProductIds = DbContext.Books.Local.Select(b => b.AudibleProductId); var remainingProductIds = productIds diff --git a/DtoImporterService/LibraryImporter.cs b/DtoImporterService/LibraryImporter.cs index 48e9b628..b0077145 100644 --- a/DtoImporterService/LibraryImporter.cs +++ b/DtoImporterService/LibraryImporter.cs @@ -34,8 +34,8 @@ namespace DtoImporterService // // CURRENT SOLUTION: don't re-insert - var currentLibraryProductIds = DbContext.Library.Select(l => l.Book.AudibleProductId).ToList(); - var newItems = importItems.Where(dto => !currentLibraryProductIds.Contains(dto.DtoItem.ProductId)).ToList(); + var currentLibraryProductIds = DbContext.Library.Select(l => l.Book.AudibleProductId); + var newItems = importItems.Where(dto => !currentLibraryProductIds.Contains(dto.DtoItem.ProductId)); foreach (var newItem in newItems) { @@ -55,7 +55,7 @@ namespace DtoImporterService u.UpdateAccount(item.AccountId); } - var qtyNew = newItems.Count; + var qtyNew = newItems.Count(); return qtyNew; } } From 00f7e4b7796c724192e4246c0498e6b183782f18 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Fri, 2 Jul 2021 14:07:42 -0600 Subject: [PATCH 3/9] Remove items from library. --- DtoImporterService/LibraryImporter.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/DtoImporterService/LibraryImporter.cs b/DtoImporterService/LibraryImporter.cs index b0077145..430919c3 100644 --- a/DtoImporterService/LibraryImporter.cs +++ b/DtoImporterService/LibraryImporter.cs @@ -35,7 +35,10 @@ namespace DtoImporterService // CURRENT SOLUTION: don't re-insert var currentLibraryProductIds = DbContext.Library.Select(l => l.Book.AudibleProductId); + var audibleLibraryProductIds = importItems.Select(i => i.DtoItem.ProductId); + var newItems = importItems.Where(dto => !currentLibraryProductIds.Contains(dto.DtoItem.ProductId)); + var removedItems = DbContext.Library.Where(l => !audibleLibraryProductIds.Contains(l.Book.AudibleProductId)); foreach (var newItem in newItems) { @@ -55,7 +58,10 @@ namespace DtoImporterService u.UpdateAccount(item.AccountId); } + DbContext.Library.RemoveRange(removedItems); + var qtyNew = newItems.Count(); + var qtyRemoved = removedItems.Count(); return qtyNew; } } From 771d992da718da66319fadf129655137f4e8b6c3 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Fri, 2 Jul 2021 15:01:55 -0600 Subject: [PATCH 4/9] Added count of items removed from library. --- ApplicationServices/LibraryCommands.cs | 16 +++++++++------- DtoImporterService/LibraryImporter.cs | 2 +- LibationWinForms/Dialogs/IndexLibraryDialog.cs | 3 ++- LibationWinForms/Form1.cs | 3 ++- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/ApplicationServices/LibraryCommands.cs b/ApplicationServices/LibraryCommands.cs index 3ec19cc7..70ecefb4 100644 --- a/ApplicationServices/LibraryCommands.cs +++ b/ApplicationServices/LibraryCommands.cs @@ -13,10 +13,10 @@ namespace ApplicationServices { public static class LibraryCommands { - public static async Task<(int totalCount, int newCount)> ImportAccountAsync(Func loginCallbackFactoryFunc, params Account[] accounts) + public static async Task<(int totalCount, int newCount, int removedCount)> ImportAccountAsync(Func loginCallbackFactoryFunc, params Account[] accounts) { if (accounts is null || accounts.Length == 0) - return (0, 0); + return (0, 0, 0); try { @@ -25,13 +25,13 @@ namespace ApplicationServices var totalCount = importItems.Count; Log.Logger.Information($"GetAllLibraryItems: Total count {totalCount}"); - var newCount = await importIntoDbAsync(importItems); + (var newCount, var removedCount) = await importIntoDbAsync(importItems); Log.Logger.Information($"Import: New count {newCount}"); await Task.Run(() => SearchEngineCommands.FullReIndex()); Log.Logger.Information("FullReIndex: success"); - return (totalCount, newCount); + return (totalCount, newCount, removedCount); } catch (AudibleApi.Authentication.LoginFailedException lfEx) { @@ -90,14 +90,16 @@ namespace ApplicationServices return dtoItems.Select(d => new ImportItem { DtoItem = d, AccountId = account.AccountId, LocaleName = account.Locale?.Name }).ToList(); } - private static async Task importIntoDbAsync(List importItems) + private static async Task<(ushort newCount, ushort removedCount)> importIntoDbAsync(List importItems) { using var context = DbContexts.GetContext(); var libraryImporter = new LibraryImporter(context); - var newCount = await Task.Run(() => libraryImporter.Import(importItems)); + var newAndRemoved = await Task.Run(() => libraryImporter.Import(importItems)); context.SaveChanges(); - return newCount; + var newCount = (ushort)(newAndRemoved >> 0x10); + var removedCount = (ushort)(newAndRemoved & 0xffff); + return (newCount, removedCount); } public static int UpdateTags(this LibationContext context, Book book, string newTags) diff --git a/DtoImporterService/LibraryImporter.cs b/DtoImporterService/LibraryImporter.cs index 430919c3..76e2103d 100644 --- a/DtoImporterService/LibraryImporter.cs +++ b/DtoImporterService/LibraryImporter.cs @@ -62,7 +62,7 @@ namespace DtoImporterService var qtyNew = newItems.Count(); var qtyRemoved = removedItems.Count(); - return qtyNew; + return (qtyNew << 0x10) | (qtyRemoved & 0xffff); } } } diff --git a/LibationWinForms/Dialogs/IndexLibraryDialog.cs b/LibationWinForms/Dialogs/IndexLibraryDialog.cs index f3b6594c..40f5fa31 100644 --- a/LibationWinForms/Dialogs/IndexLibraryDialog.cs +++ b/LibationWinForms/Dialogs/IndexLibraryDialog.cs @@ -11,6 +11,7 @@ namespace LibationWinForms.Dialogs private Account[] _accounts { get; } public int NewBooksAdded { get; private set; } + public int OldBooksRemoved { get; private set; } public int TotalBooksProcessed { get; private set; } public IndexLibraryDialog(params Account[] accounts) @@ -31,7 +32,7 @@ namespace LibationWinForms.Dialogs try { - (TotalBooksProcessed, NewBooksAdded) = await LibraryCommands.ImportAccountAsync((account) => new WinformResponder(account), _accounts); + (TotalBooksProcessed, NewBooksAdded, OldBooksRemoved) = await LibraryCommands.ImportAccountAsync((account) => new WinformResponder(account), _accounts); } catch (Exception ex) { diff --git a/LibationWinForms/Form1.cs b/LibationWinForms/Form1.cs index 3c4fa133..1e180277 100644 --- a/LibationWinForms/Form1.cs +++ b/LibationWinForms/Form1.cs @@ -284,8 +284,9 @@ namespace LibationWinForms var totalProcessed = dialog.TotalBooksProcessed; var newAdded = dialog.NewBooksAdded; + var oldRemoved = dialog.OldBooksRemoved; - MessageBox.Show($"Total processed: {totalProcessed}\r\nNew: {newAdded}"); + MessageBox.Show($"Total processed: {totalProcessed}\r\nNew: {newAdded}\r\nRemoved: {oldRemoved}"); if (totalProcessed > 0) reloadGrid(); From 35fc3581b3fab2fa70e88747395411eb8f08b334 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Fri, 2 Jul 2021 15:23:26 -0600 Subject: [PATCH 5/9] Revert "Added count of items removed from library." This reverts commit 771d992da718da66319fadf129655137f4e8b6c3. --- ApplicationServices/LibraryCommands.cs | 16 +++++++--------- DtoImporterService/LibraryImporter.cs | 2 +- LibationWinForms/Dialogs/IndexLibraryDialog.cs | 3 +-- LibationWinForms/Form1.cs | 3 +-- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/ApplicationServices/LibraryCommands.cs b/ApplicationServices/LibraryCommands.cs index 70ecefb4..3ec19cc7 100644 --- a/ApplicationServices/LibraryCommands.cs +++ b/ApplicationServices/LibraryCommands.cs @@ -13,10 +13,10 @@ namespace ApplicationServices { public static class LibraryCommands { - public static async Task<(int totalCount, int newCount, int removedCount)> ImportAccountAsync(Func loginCallbackFactoryFunc, params Account[] accounts) + public static async Task<(int totalCount, int newCount)> ImportAccountAsync(Func loginCallbackFactoryFunc, params Account[] accounts) { if (accounts is null || accounts.Length == 0) - return (0, 0, 0); + return (0, 0); try { @@ -25,13 +25,13 @@ namespace ApplicationServices var totalCount = importItems.Count; Log.Logger.Information($"GetAllLibraryItems: Total count {totalCount}"); - (var newCount, var removedCount) = await importIntoDbAsync(importItems); + var newCount = await importIntoDbAsync(importItems); Log.Logger.Information($"Import: New count {newCount}"); await Task.Run(() => SearchEngineCommands.FullReIndex()); Log.Logger.Information("FullReIndex: success"); - return (totalCount, newCount, removedCount); + return (totalCount, newCount); } catch (AudibleApi.Authentication.LoginFailedException lfEx) { @@ -90,16 +90,14 @@ namespace ApplicationServices return dtoItems.Select(d => new ImportItem { DtoItem = d, AccountId = account.AccountId, LocaleName = account.Locale?.Name }).ToList(); } - private static async Task<(ushort newCount, ushort removedCount)> importIntoDbAsync(List importItems) + private static async Task importIntoDbAsync(List importItems) { using var context = DbContexts.GetContext(); var libraryImporter = new LibraryImporter(context); - var newAndRemoved = await Task.Run(() => libraryImporter.Import(importItems)); + var newCount = await Task.Run(() => libraryImporter.Import(importItems)); context.SaveChanges(); - var newCount = (ushort)(newAndRemoved >> 0x10); - var removedCount = (ushort)(newAndRemoved & 0xffff); - return (newCount, removedCount); + return newCount; } public static int UpdateTags(this LibationContext context, Book book, string newTags) diff --git a/DtoImporterService/LibraryImporter.cs b/DtoImporterService/LibraryImporter.cs index 76e2103d..430919c3 100644 --- a/DtoImporterService/LibraryImporter.cs +++ b/DtoImporterService/LibraryImporter.cs @@ -62,7 +62,7 @@ namespace DtoImporterService var qtyNew = newItems.Count(); var qtyRemoved = removedItems.Count(); - return (qtyNew << 0x10) | (qtyRemoved & 0xffff); + return qtyNew; } } } diff --git a/LibationWinForms/Dialogs/IndexLibraryDialog.cs b/LibationWinForms/Dialogs/IndexLibraryDialog.cs index 40f5fa31..f3b6594c 100644 --- a/LibationWinForms/Dialogs/IndexLibraryDialog.cs +++ b/LibationWinForms/Dialogs/IndexLibraryDialog.cs @@ -11,7 +11,6 @@ namespace LibationWinForms.Dialogs private Account[] _accounts { get; } public int NewBooksAdded { get; private set; } - public int OldBooksRemoved { get; private set; } public int TotalBooksProcessed { get; private set; } public IndexLibraryDialog(params Account[] accounts) @@ -32,7 +31,7 @@ namespace LibationWinForms.Dialogs try { - (TotalBooksProcessed, NewBooksAdded, OldBooksRemoved) = await LibraryCommands.ImportAccountAsync((account) => new WinformResponder(account), _accounts); + (TotalBooksProcessed, NewBooksAdded) = await LibraryCommands.ImportAccountAsync((account) => new WinformResponder(account), _accounts); } catch (Exception ex) { diff --git a/LibationWinForms/Form1.cs b/LibationWinForms/Form1.cs index 1e180277..3c4fa133 100644 --- a/LibationWinForms/Form1.cs +++ b/LibationWinForms/Form1.cs @@ -284,9 +284,8 @@ namespace LibationWinForms var totalProcessed = dialog.TotalBooksProcessed; var newAdded = dialog.NewBooksAdded; - var oldRemoved = dialog.OldBooksRemoved; - MessageBox.Show($"Total processed: {totalProcessed}\r\nNew: {newAdded}\r\nRemoved: {oldRemoved}"); + MessageBox.Show($"Total processed: {totalProcessed}\r\nNew: {newAdded}"); if (totalProcessed > 0) reloadGrid(); From 81195e382e7a11fbbc99e65b786aee558584442e Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Fri, 2 Jul 2021 15:24:05 -0600 Subject: [PATCH 6/9] Revert "Remove items from library." This reverts commit 00f7e4b7796c724192e4246c0498e6b183782f18. --- DtoImporterService/LibraryImporter.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/DtoImporterService/LibraryImporter.cs b/DtoImporterService/LibraryImporter.cs index 430919c3..b0077145 100644 --- a/DtoImporterService/LibraryImporter.cs +++ b/DtoImporterService/LibraryImporter.cs @@ -35,10 +35,7 @@ namespace DtoImporterService // CURRENT SOLUTION: don't re-insert var currentLibraryProductIds = DbContext.Library.Select(l => l.Book.AudibleProductId); - var audibleLibraryProductIds = importItems.Select(i => i.DtoItem.ProductId); - var newItems = importItems.Where(dto => !currentLibraryProductIds.Contains(dto.DtoItem.ProductId)); - var removedItems = DbContext.Library.Where(l => !audibleLibraryProductIds.Contains(l.Book.AudibleProductId)); foreach (var newItem in newItems) { @@ -58,10 +55,7 @@ namespace DtoImporterService u.UpdateAccount(item.AccountId); } - DbContext.Library.RemoveRange(removedItems); - var qtyNew = newItems.Count(); - var qtyRemoved = removedItems.Count(); return qtyNew; } } From 097bda2d2504682f741d0f2d1fd893eb450231d3 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Fri, 2 Jul 2021 15:58:37 -0600 Subject: [PATCH 7/9] Added null check. --- FileLiberator/DownloadDecryptBook.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FileLiberator/DownloadDecryptBook.cs b/FileLiberator/DownloadDecryptBook.cs index cc22ef7e..89934d4b 100644 --- a/FileLiberator/DownloadDecryptBook.cs +++ b/FileLiberator/DownloadDecryptBook.cs @@ -218,7 +218,7 @@ namespace FileLiberator public void Cancel() { - aaxcDownloader.Cancel(); + aaxcDownloader?.Cancel(); } } } From 4b2c8ee5131b7a6ecee34897919128b4cc39c9c3 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Fri, 2 Jul 2021 17:00:04 -0600 Subject: [PATCH 8/9] Add any subtitle to the title. --- DtoImporterService/BookImporter.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/DtoImporterService/BookImporter.cs b/DtoImporterService/BookImporter.cs index 4fe3a70e..157a3670 100644 --- a/DtoImporterService/BookImporter.cs +++ b/DtoImporterService/BookImporter.cs @@ -67,6 +67,9 @@ namespace DtoImporterService { var item = importItem.DtoItem; + //Add any subtitle after the title title. + var title = item.Title + (!string.IsNullOrWhiteSpace(item.Subtitle) ? $": {item.Subtitle}" : ""); + // absence of authors is very rare, but possible if (!item.Authors?.Any() ?? true) item.Authors = new[] { new Person { Name = "", Asin = null } }; @@ -102,7 +105,7 @@ namespace DtoImporterService var book = DbContext.Books.Add(new Book( new AudibleProductId(item.ProductId), - item.Title, + title, item.Description, item.LengthInMinutes, authors, From 5df7d80aacca1320b9ed0fcc7ca5fe261738e4f4 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Fri, 2 Jul 2021 21:21:17 -0600 Subject: [PATCH 9/9] Revert earlier. --- DtoImporterService/BookImporter.cs | 4 ++-- DtoImporterService/LibraryImporter.cs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/DtoImporterService/BookImporter.cs b/DtoImporterService/BookImporter.cs index 157a3670..b2889b50 100644 --- a/DtoImporterService/BookImporter.cs +++ b/DtoImporterService/BookImporter.cs @@ -21,7 +21,7 @@ namespace DtoImporterService new CategoryImporter(DbContext).Import(importItems); // get distinct - var productIds = importItems.Select(i => i.DtoItem.ProductId); + var productIds = importItems.Select(i => i.DtoItem.ProductId).ToList(); // load db existing => .Local loadLocal_books(productIds); @@ -31,7 +31,7 @@ namespace DtoImporterService return qtyNew; } - private void loadLocal_books(IEnumerable productIds) + private void loadLocal_books(List productIds) { var localProductIds = DbContext.Books.Local.Select(b => b.AudibleProductId); var remainingProductIds = productIds diff --git a/DtoImporterService/LibraryImporter.cs b/DtoImporterService/LibraryImporter.cs index b0077145..48e9b628 100644 --- a/DtoImporterService/LibraryImporter.cs +++ b/DtoImporterService/LibraryImporter.cs @@ -34,8 +34,8 @@ namespace DtoImporterService // // CURRENT SOLUTION: don't re-insert - var currentLibraryProductIds = DbContext.Library.Select(l => l.Book.AudibleProductId); - var newItems = importItems.Where(dto => !currentLibraryProductIds.Contains(dto.DtoItem.ProductId)); + var currentLibraryProductIds = DbContext.Library.Select(l => l.Book.AudibleProductId).ToList(); + var newItems = importItems.Where(dto => !currentLibraryProductIds.Contains(dto.DtoItem.ProductId)).ToList(); foreach (var newItem in newItems) { @@ -55,7 +55,7 @@ namespace DtoImporterService u.UpdateAccount(item.AccountId); } - var qtyNew = newItems.Count(); + var qtyNew = newItems.Count; return qtyNew; } }