From 673451dc11106cb21a203a64b09e8f98f72eacd9 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Sat, 21 Aug 2021 22:08:35 -0600 Subject: [PATCH] Git resolve --- FileLiberator/DownloadDecryptBook.cs | 84 +++++++++++++--------------- 1 file changed, 39 insertions(+), 45 deletions(-) diff --git a/FileLiberator/DownloadDecryptBook.cs b/FileLiberator/DownloadDecryptBook.cs index 8dc6eea8..450cdb6a 100644 --- a/FileLiberator/DownloadDecryptBook.cs +++ b/FileLiberator/DownloadDecryptBook.cs @@ -16,22 +16,22 @@ namespace FileLiberator public class DownloadDecryptBook : IAudioDecodable { - private AaxcDownloadConverter aaxcDownloader; + private AaxcDownloadConverter aaxcDownloader; - public event EventHandler StreamingTimeRemaining; - public event EventHandler> RequestCoverArt; - public event EventHandler TitleDiscovered; - public event EventHandler AuthorsDiscovered; - public event EventHandler NarratorsDiscovered; - public event EventHandler CoverImageDiscovered; - public event EventHandler StreamingBegin; - public event EventHandler StreamingProgressChanged; - public event EventHandler StreamingCompleted; - public event EventHandler Begin; - public event EventHandler StatusUpdate; - public event EventHandler Completed; + public event EventHandler StreamingTimeRemaining; + public event EventHandler> RequestCoverArt; + public event EventHandler TitleDiscovered; + public event EventHandler AuthorsDiscovered; + public event EventHandler NarratorsDiscovered; + public event EventHandler CoverImageDiscovered; + public event EventHandler StreamingBegin; + public event EventHandler StreamingProgressChanged; + public event EventHandler StreamingCompleted; + public event EventHandler Begin; + public event EventHandler StatusUpdate; + public event EventHandler Completed; - public async Task ProcessAsync(LibraryBook libraryBook) + public async Task ProcessAsync(LibraryBook libraryBook) { Begin?.Invoke(this, libraryBook); @@ -47,12 +47,10 @@ namespace FileLiberator return new StatusHandler { "Decrypt failed" }; // moves files and returns dest dir - var moveResults = MoveFilesToBooksDir(libraryBook.Book, outputAudioFilename); + _ = moveFilesToBooksDir(libraryBook.Book, outputAudioFilename); - if (!moveResults.movedAudioFile) - return new StatusHandler { "Cannot find final audio file after decryption" }; - - libraryBook.Book.UserDefinedItem.BookStatus = LiberatedStatus.Liberated; + // only need to update if success. if failure, it will remain at 0 == NotLiberated + ApplicationServices.LibraryCommands.UpdateBook(libraryBook, LiberatedStatus.Liberated); return new StatusHandler(); } @@ -125,7 +123,7 @@ namespace FileLiberator } - private void AaxcDownloader_RetrievedCoverArt(object sender, byte[] e) + private void AaxcDownloader_RetrievedCoverArt(object sender, byte[] e) { if (e is null && Configuration.Instance.AllowLibationFixup) { @@ -142,10 +140,10 @@ namespace FileLiberator { TitleDiscovered?.Invoke(this, e.TitleSansUnabridged); AuthorsDiscovered?.Invoke(this, e.FirstAuthor ?? "[unknown]"); - NarratorsDiscovered?.Invoke(this, e.Narrator ?? "[unknown]"); + NarratorsDiscovered?.Invoke(this, e.Narrator ?? "[unknown]"); } - private static (string destinationDir, bool movedAudioFile) MoveFilesToBooksDir(Book product, string outputAudioFilename) + private static string moveFilesToBooksDir(Book product, string outputAudioFilename) { // create final directory. move each file into it. MOVE AUDIO FILE LAST // new dir: safetitle_limit50char + " [" + productId + "]" @@ -160,7 +158,6 @@ namespace FileLiberator // audio filename: safetitle_limit50char + " [" + productId + "]." + audio_ext var audioFileName = FileUtility.GetValidFilename(destinationDir, product.Title, musicFileExt, product.AudibleProductId); - bool movedAudioFile = false; foreach (var f in sortedFiles) { var dest @@ -173,14 +170,11 @@ namespace FileLiberator Cue.UpdateFileName(f, audioFileName); File.Move(f.FullName, dest); - - movedAudioFile |= AudibleFileStorage.Audio.IsFileTypeMatch(f); - } AudibleFileStorage.Audio.Refresh(); - return (destinationDir, movedAudioFile); + return destinationDir; } private static List getProductFilesSorted(Book product, string outputAudioFilename) @@ -203,26 +197,26 @@ namespace FileLiberator } private static void validate(LibraryBook libraryBook) - { - string errorString(string field) - => $"{errorTitle()}\r\nCannot download book. {field} is not known. Try re-importing the account which owns this book."; + { + string errorString(string field) + => $"{errorTitle()}\r\nCannot download book. {field} is not known. Try re-importing the account which owns this book."; - string errorTitle() - { - var title - = (libraryBook.Book.Title.Length > 53) - ? $"{libraryBook.Book.Title.Truncate(50)}..." - : libraryBook.Book.Title; - var errorBookTitle = $"{title} [{libraryBook.Book.AudibleProductId}]"; - return errorBookTitle; - }; + string errorTitle() + { + var title + = (libraryBook.Book.Title.Length > 53) + ? $"{libraryBook.Book.Title.Truncate(50)}..." + : libraryBook.Book.Title; + var errorBookTitle = $"{title} [{libraryBook.Book.AudibleProductId}]"; + return errorBookTitle; + }; - if (string.IsNullOrWhiteSpace(libraryBook.Account)) - throw new Exception(errorString("Account")); + if (string.IsNullOrWhiteSpace(libraryBook.Account)) + throw new Exception(errorString("Account")); - if (string.IsNullOrWhiteSpace(libraryBook.Book.Locale)) - throw new Exception(errorString("Locale")); - } + if (string.IsNullOrWhiteSpace(libraryBook.Book.Locale)) + throw new Exception(errorString("Locale")); + } public bool Validate(LibraryBook libraryBook) => !libraryBook.Book.Audio_Exists; @@ -231,4 +225,4 @@ namespace FileLiberator aaxcDownloader?.Cancel(); } } -} +} \ No newline at end of file