Compare commits

...

3 Commits

Author SHA1 Message Date
Robert McRackan
7b966f6962 Add IsLiberated option to search engine. Reindex search after download and decrypt 2021-03-31 21:50:32 -04:00
Robert McRackan
c0e955d5ef Better logging and error handling during login 2021-03-15 13:30:33 -04:00
Robert McRackan
bc6f53c8ea bug fix around latest skip-bad-book feature 2020-12-23 16:07:47 -05:00
4 changed files with 65 additions and 60 deletions

View File

@@ -78,11 +78,11 @@ namespace FileLiberator
Dinah.Core.IO.FileExt.SafeDelete(aaxFilename);
}
var statusHandler = new StatusHandler();
var finalAudioExists = AudibleFileStorage.Audio.Exists(libraryBook.Book.AudibleProductId);
if (!finalAudioExists)
statusHandler.AddError("Cannot find final audio file after decryption");
return statusHandler;
return new StatusHandler { "Cannot find final audio file after decryption" };
return new StatusHandler();
}
finally
{

View File

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

View File

@@ -119,6 +119,10 @@ namespace LibationSearchEngine
[nameof(Book.IsAbridged)] = lb => lb.Book.IsAbridged,
["Abridged"] = lb => lb.Book.IsAbridged,
// this will only be evaluated at time of re-index. ie: state of files moved later will be out of sync until next re-index
["IsLiberated"] = lb => AudibleFileStorage.Audio.Exists(lb.Book.AudibleProductId),
["Liberated"] = lb => AudibleFileStorage.Audio.Exists(lb.Book.AudibleProductId),
});
private static bool isAuthorNarrated(LibraryBook lb)

View File

@@ -81,9 +81,17 @@ namespace LibationWinForms.BookLiberation
backupBook.DownloadPdf.Completed += completedAction;
}
// enables search engine to index for things like "IsLiberated"
backupBook.DownloadBook.Completed += reindex;
backupBook.DecryptBook.Completed += reindex;
backupBook.DownloadPdf.Completed += reindex;
return backupBook;
}
private static async void reindex(object sender, LibraryBook e)
=> await Task.Run(() => ApplicationServices.SearchEngineCommands.FullReIndex());
private static (AutomatedBackupsForm, LogMe) attachToBackupsForm(BackupBook backupBook)
{
#region create form and logger
@@ -334,6 +342,10 @@ namespace LibationWinForms.BookLiberation
protected abstract Task RunAsync();
protected abstract string SkipDialogText { get; }
protected abstract MessageBoxButtons SkipDialogButtons { get; }
protected abstract DialogResult CreateSkipFileResult { get; }
public async Task RunBackupAsync()
{
AutomatedBackupsForm.Show();
@@ -351,46 +363,47 @@ namespace LibationWinForms.BookLiberation
LogMe.Info("DONE");
}
protected abstract string SkipDialogText { get; }
protected abstract MessageBoxButtons SkipDialogButtons { get; }
protected abstract DialogResult CreateSkipFileResult { get; }
protected bool ValidateStatusAsync(StatusHandler statusHandler, LibraryBook libraryBook)
protected async Task<bool> ProcessOneAsync(Func<LibraryBook, Task<StatusHandler>> func, LibraryBook libraryBook)
{
if (!statusHandler.HasErrors)
return true;
LogMe.Error("ERROR. All books have not been processed. Most recent valid book: processing failed");
foreach (var errorMessage in statusHandler.Errors)
LogMe.Error(errorMessage);
string logMessage;
try
{
var dialogResult = MessageBox.Show(SkipDialogText, "Skip importing this book?", SkipDialogButtons, MessageBoxIcon.Question);
var statusHandler = await func(libraryBook);
if (dialogResult == DialogResult.Abort)
return false;
if (statusHandler.IsSuccess)
return true;
if (dialogResult == CreateSkipFileResult)
{
var path = FileManager.AudibleFileStorage.Audio.CreateSkipFile(
libraryBook.Book.Title,
libraryBook.Book.AudibleProductId,
statusHandler.Errors.Aggregate((a, b) => $"{a}\r\n{b}"));
LogMe.Info($@"
Created new skip file
[{libraryBook.Book.AudibleProductId}] {libraryBook.Book.Title}
{path}
".Trim());
}
foreach (var errorMessage in statusHandler.Errors)
LogMe.Error(errorMessage);
return true;
logMessage = statusHandler.Errors.Aggregate((a, b) => $"{a}\r\n{b}");
}
catch (Exception ex)
{
LogMe.Error(ex, "Error attempting to display skip option box");
return false;
LogMe.Error(ex);
logMessage = ex.Message + "\r\n|\r\n" + ex.StackTrace;
}
LogMe.Error("ERROR. All books have not been processed. Most recent book: processing failed");
var dialogResult = MessageBox.Show(SkipDialogText, "Skip importing this book?", SkipDialogButtons, MessageBoxIcon.Question);
if (dialogResult == DialogResult.Abort)
return false;
if (dialogResult == CreateSkipFileResult)
{
var path = FileManager.AudibleFileStorage.Audio.CreateSkipFile(libraryBook.Book.Title, libraryBook.Book.AudibleProductId, logMessage);
LogMe.Info($@"
Created new 'skip' file
[{libraryBook.Book.AudibleProductId}] {libraryBook.Book.Title}
{path}
".Trim());
}
return true;
}
}
class BackupSingle : BackupRunner
@@ -415,11 +428,8 @@ An error occurred while trying to process this book. Skip this book permanently?
protected override async Task RunAsync()
{
if (_libraryBook is null)
return;
var statusHandler = await Processable.ProcessSingleAsync(_libraryBook);
ValidateStatusAsync(statusHandler, _libraryBook);
if (_libraryBook is not null)
await ProcessOneAsync(Processable.ProcessSingleAsync, _libraryBook);
}
}
class BackupLoop : BackupRunner
@@ -443,29 +453,20 @@ An error occurred while trying to process this book
{
// support for 'skip this time only' requires state. iterators provide this state for free. therefore: use foreach/iterator here
foreach (var libraryBook in Processable.GetValidLibraryBooks())
{
try
{
var statusHandler = await Processable.ProcessBookAsync_NoValidation(libraryBook);
{
var keepGoing = await ProcessOneAsync(Processable.ProcessBookAsync_NoValidation, libraryBook);
if (!keepGoing)
return;
var keepGoing = ValidateStatusAsync(statusHandler, libraryBook);
if (!keepGoing)
return;
if (!AutomatedBackupsForm.KeepGoing)
{
if (AutomatedBackupsForm.KeepGoingVisible && !AutomatedBackupsForm.KeepGoingChecked)
LogMe.Info("'Keep going' is unchecked");
return;
}
}
if (!AutomatedBackupsForm.KeepGoing)
{
if (AutomatedBackupsForm.KeepGoingVisible && !AutomatedBackupsForm.KeepGoingChecked)
LogMe.Info("'Keep going' is unchecked");
return;
}
}
catch (Exception exc)
{
LogMe.Error(exc);
}
}
LogMe.Info("Done. All books have been processed");
LogMe.Info("Done. All books have been processed");
}
}
}
}