From 55b57cf9a93b20b073a2126b960d78a2d0999ff8 Mon Sep 17 00:00:00 2001 From: Robert McRackan Date: Mon, 4 Nov 2019 16:00:18 -0500 Subject: [PATCH] do not import episodes --- LibationWinForm/UNTESTED/Form1.cs | 48 +++++++++++++++++++++++-------- __TODO.txt | 2 -- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/LibationWinForm/UNTESTED/Form1.cs b/LibationWinForm/UNTESTED/Form1.cs index 66210980..630c8107 100644 --- a/LibationWinForm/UNTESTED/Form1.cs +++ b/LibationWinForm/UNTESTED/Form1.cs @@ -17,17 +17,17 @@ namespace LibationWinForm // initial call here will initiate config loading private Configuration config { get; } = Configuration.Instance; - private string backupsCountsLbl_Format; - private string pdfsCountsLbl_Format; - private string visibleCountLbl_Format; + private string backupsCountsLbl_Format { get; } + private string pdfsCountsLbl_Format { get; } + private string visibleCountLbl_Format { get; } - private string reimportMostRecentLibraryScanToolStripMenuItem_format; - private string beginImportingBookDetailsToolStripMenuItem_format; + private string reimportMostRecentLibraryScanToolStripMenuItem_format { get; } + private string beginImportingBookDetailsToolStripMenuItem_format { get; } - private string beginBookBackupsToolStripMenuItem_format; - private string beginPdfBackupsToolStripMenuItem_format; + private string beginBookBackupsToolStripMenuItem_format { get; } + private string beginPdfBackupsToolStripMenuItem_format { get; } - public Form1() + public Form1() { InitializeComponent(); @@ -372,24 +372,48 @@ await audibleApi(); int totalCount; int newCount; - // seems to be very common the 1st time after long absence. either figure out why, or run 2x before declaring error + // bug on audible's side. the 1st time after a long absence, a query to get library will return without titles or authors. a subsequent identical query will be successful. this is true whether or tokens are refreshed + // worse, this 1st dummy call doesn't seem to help: + // var page = await api.GetLibraryAsync(new AudibleApi.LibraryOptions { NumberOfResultPerPage = 1, PageNumber = 1, PurchasedAfter = DateTime.Now.AddYears(-20), ResponseGroups = AudibleApi.LibraryOptions.ResponseGroupOptions.ALL_OPTIONS }); + // i don't want to incur the cost of making a full dummy call every time because it fails sometimes try { var items = await InternalUtilities.AudibleApiExtensions.GetAllLibraryItemsAsync(api); + + // remove episode parents + items.RemoveAll(i => i.Episodes); +// // add individual/children episodes +// var childIds = items +// .Where(i => i.Episodes) +// .SelectMany(ep => ep.Relationships) +// .Where(r => r.RelationshipToProduct == AudibleApiDTOs.RelationshipToProduct.Child && r.RelationshipType == AudibleApiDTOs.RelationshipType.Episode) +// .Select(c => c.Asin) +// .ToList(); +// foreach (var childId in childIds) +// { +//// clean this up +// var bookResult = await api.GetLibraryBookAsync(childId, AudibleApi.LibraryOptions.ResponseGroupOptions.ALL_OPTIONS); +// var bookResultString = bookResult.ToString(); +// var bookResultJson = AudibleApiDTOs.LibraryApiV10.FromJson(bookResultString); +// var bookItem = bookResultJson.Item; +// items.Add(bookItem); +// } +// extract code in 'try' so retry in 'catch' isn't duplicate code totalCount = items.Count; newCount = await Task.Run(() => new DtoImporterService.LibraryImporter().Import(items)); } - catch + catch (Exception ex1) { try { var items = await InternalUtilities.AudibleApiExtensions.GetAllLibraryItemsAsync(api); + items.RemoveAll(i => i.Episodes); totalCount = items.Count; newCount = await Task.Run(() => new DtoImporterService.LibraryImporter().Import(items)); } - catch (Exception ex) + catch (Exception ex2) { - MessageBox.Show("Error importing library.\r\n" + ex.Message, "Error importing library", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Error importing library.\r\n" + ex2.Message, "Error importing library", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } diff --git a/__TODO.txt b/__TODO.txt index 49d2b7e8..d8d36ecc 100644 --- a/__TODO.txt +++ b/__TODO.txt @@ -3,8 +3,6 @@ integrate API into libation. replace all authentication, audible communication IN-PROGRESS ----------- -download via api with UI integration -- functionality: episodes library import UI - disable main ui - updates on which stage and how long it's expected to take