Git resolve
This commit is contained in:
parent
e4257afc14
commit
673451dc11
@ -16,22 +16,22 @@ namespace FileLiberator
|
|||||||
public class DownloadDecryptBook : IAudioDecodable
|
public class DownloadDecryptBook : IAudioDecodable
|
||||||
{
|
{
|
||||||
|
|
||||||
private AaxcDownloadConverter aaxcDownloader;
|
private AaxcDownloadConverter aaxcDownloader;
|
||||||
|
|
||||||
public event EventHandler<TimeSpan> StreamingTimeRemaining;
|
public event EventHandler<TimeSpan> StreamingTimeRemaining;
|
||||||
public event EventHandler<Action<byte[]>> RequestCoverArt;
|
public event EventHandler<Action<byte[]>> RequestCoverArt;
|
||||||
public event EventHandler<string> TitleDiscovered;
|
public event EventHandler<string> TitleDiscovered;
|
||||||
public event EventHandler<string> AuthorsDiscovered;
|
public event EventHandler<string> AuthorsDiscovered;
|
||||||
public event EventHandler<string> NarratorsDiscovered;
|
public event EventHandler<string> NarratorsDiscovered;
|
||||||
public event EventHandler<byte[]> CoverImageDiscovered;
|
public event EventHandler<byte[]> CoverImageDiscovered;
|
||||||
public event EventHandler<string> StreamingBegin;
|
public event EventHandler<string> StreamingBegin;
|
||||||
public event EventHandler<DownloadProgress> StreamingProgressChanged;
|
public event EventHandler<DownloadProgress> StreamingProgressChanged;
|
||||||
public event EventHandler<string> StreamingCompleted;
|
public event EventHandler<string> StreamingCompleted;
|
||||||
public event EventHandler<LibraryBook> Begin;
|
public event EventHandler<LibraryBook> Begin;
|
||||||
public event EventHandler<string> StatusUpdate;
|
public event EventHandler<string> StatusUpdate;
|
||||||
public event EventHandler<LibraryBook> Completed;
|
public event EventHandler<LibraryBook> Completed;
|
||||||
|
|
||||||
public async Task<StatusHandler> ProcessAsync(LibraryBook libraryBook)
|
public async Task<StatusHandler> ProcessAsync(LibraryBook libraryBook)
|
||||||
{
|
{
|
||||||
Begin?.Invoke(this, libraryBook);
|
Begin?.Invoke(this, libraryBook);
|
||||||
|
|
||||||
@ -47,12 +47,10 @@ namespace FileLiberator
|
|||||||
return new StatusHandler { "Decrypt failed" };
|
return new StatusHandler { "Decrypt failed" };
|
||||||
|
|
||||||
// moves files and returns dest dir
|
// moves files and returns dest dir
|
||||||
var moveResults = MoveFilesToBooksDir(libraryBook.Book, outputAudioFilename);
|
_ = moveFilesToBooksDir(libraryBook.Book, outputAudioFilename);
|
||||||
|
|
||||||
if (!moveResults.movedAudioFile)
|
// only need to update if success. if failure, it will remain at 0 == NotLiberated
|
||||||
return new StatusHandler { "Cannot find final audio file after decryption" };
|
ApplicationServices.LibraryCommands.UpdateBook(libraryBook, LiberatedStatus.Liberated);
|
||||||
|
|
||||||
libraryBook.Book.UserDefinedItem.BookStatus = LiberatedStatus.Liberated;
|
|
||||||
|
|
||||||
return new StatusHandler();
|
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)
|
if (e is null && Configuration.Instance.AllowLibationFixup)
|
||||||
{
|
{
|
||||||
@ -142,10 +140,10 @@ namespace FileLiberator
|
|||||||
{
|
{
|
||||||
TitleDiscovered?.Invoke(this, e.TitleSansUnabridged);
|
TitleDiscovered?.Invoke(this, e.TitleSansUnabridged);
|
||||||
AuthorsDiscovered?.Invoke(this, e.FirstAuthor ?? "[unknown]");
|
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
|
// create final directory. move each file into it. MOVE AUDIO FILE LAST
|
||||||
// new dir: safetitle_limit50char + " [" + productId + "]"
|
// new dir: safetitle_limit50char + " [" + productId + "]"
|
||||||
@ -160,7 +158,6 @@ namespace FileLiberator
|
|||||||
// audio filename: safetitle_limit50char + " [" + productId + "]." + audio_ext
|
// audio filename: safetitle_limit50char + " [" + productId + "]." + audio_ext
|
||||||
var audioFileName = FileUtility.GetValidFilename(destinationDir, product.Title, musicFileExt, product.AudibleProductId);
|
var audioFileName = FileUtility.GetValidFilename(destinationDir, product.Title, musicFileExt, product.AudibleProductId);
|
||||||
|
|
||||||
bool movedAudioFile = false;
|
|
||||||
foreach (var f in sortedFiles)
|
foreach (var f in sortedFiles)
|
||||||
{
|
{
|
||||||
var dest
|
var dest
|
||||||
@ -173,14 +170,11 @@ namespace FileLiberator
|
|||||||
Cue.UpdateFileName(f, audioFileName);
|
Cue.UpdateFileName(f, audioFileName);
|
||||||
|
|
||||||
File.Move(f.FullName, dest);
|
File.Move(f.FullName, dest);
|
||||||
|
|
||||||
movedAudioFile |= AudibleFileStorage.Audio.IsFileTypeMatch(f);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AudibleFileStorage.Audio.Refresh();
|
AudibleFileStorage.Audio.Refresh();
|
||||||
|
|
||||||
return (destinationDir, movedAudioFile);
|
return destinationDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<FileInfo> getProductFilesSorted(Book product, string outputAudioFilename)
|
private static List<FileInfo> getProductFilesSorted(Book product, string outputAudioFilename)
|
||||||
@ -203,26 +197,26 @@ namespace FileLiberator
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void validate(LibraryBook libraryBook)
|
private static void validate(LibraryBook libraryBook)
|
||||||
{
|
{
|
||||||
string errorString(string field)
|
string errorString(string field)
|
||||||
=> $"{errorTitle()}\r\nCannot download book. {field} is not known. Try re-importing the account which owns this book.";
|
=> $"{errorTitle()}\r\nCannot download book. {field} is not known. Try re-importing the account which owns this book.";
|
||||||
|
|
||||||
string errorTitle()
|
string errorTitle()
|
||||||
{
|
{
|
||||||
var title
|
var title
|
||||||
= (libraryBook.Book.Title.Length > 53)
|
= (libraryBook.Book.Title.Length > 53)
|
||||||
? $"{libraryBook.Book.Title.Truncate(50)}..."
|
? $"{libraryBook.Book.Title.Truncate(50)}..."
|
||||||
: libraryBook.Book.Title;
|
: libraryBook.Book.Title;
|
||||||
var errorBookTitle = $"{title} [{libraryBook.Book.AudibleProductId}]";
|
var errorBookTitle = $"{title} [{libraryBook.Book.AudibleProductId}]";
|
||||||
return errorBookTitle;
|
return errorBookTitle;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(libraryBook.Account))
|
if (string.IsNullOrWhiteSpace(libraryBook.Account))
|
||||||
throw new Exception(errorString("Account"));
|
throw new Exception(errorString("Account"));
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(libraryBook.Book.Locale))
|
if (string.IsNullOrWhiteSpace(libraryBook.Book.Locale))
|
||||||
throw new Exception(errorString("Locale"));
|
throw new Exception(errorString("Locale"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Validate(LibraryBook libraryBook) => !libraryBook.Book.Audio_Exists;
|
public bool Validate(LibraryBook libraryBook) => !libraryBook.Book.Audio_Exists;
|
||||||
|
|
||||||
@ -231,4 +225,4 @@ namespace FileLiberator
|
|||||||
aaxcDownloader?.Cancel();
|
aaxcDownloader?.Cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user