Detect Conversion cancelled
This commit is contained in:
parent
341678d979
commit
b24df24b10
@ -17,17 +17,24 @@ namespace FileLiberator
|
|||||||
public override string Name => "Convert to Mp3";
|
public override string Name => "Convert to Mp3";
|
||||||
private Mp4File m4bBook;
|
private Mp4File m4bBook;
|
||||||
|
|
||||||
private long fileSize;
|
private long fileSize;
|
||||||
private static string Mp3FileName(string m4bPath) => Path.ChangeExtension(m4bPath ?? "", ".mp3");
|
private static string Mp3FileName(string m4bPath) => Path.ChangeExtension(m4bPath ?? "", ".mp3");
|
||||||
|
|
||||||
public override void Cancel() => m4bBook?.Cancel();
|
private bool cancelled = false;
|
||||||
|
public override void Cancel()
|
||||||
public override bool Validate(LibraryBook libraryBook)
|
|
||||||
{
|
{
|
||||||
|
m4bBook?.Cancel();
|
||||||
|
cancelled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool ValidateMp3(LibraryBook libraryBook)
|
||||||
|
{
|
||||||
var path = AudibleFileStorage.Audio.GetPath(libraryBook.Book.AudibleProductId);
|
var path = AudibleFileStorage.Audio.GetPath(libraryBook.Book.AudibleProductId);
|
||||||
return path?.ToLower()?.EndsWith(".m4b") == true && !File.Exists(Mp3FileName(path));
|
return path?.ToLower()?.EndsWith(".m4b") == true && !File.Exists(Mp3FileName(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool Validate(LibraryBook libraryBook) => ValidateMp3(libraryBook);
|
||||||
|
|
||||||
public override async Task<StatusHandler> ProcessAsync(LibraryBook libraryBook)
|
public override async Task<StatusHandler> ProcessAsync(LibraryBook libraryBook)
|
||||||
{
|
{
|
||||||
OnBegin(libraryBook);
|
OnBegin(libraryBook);
|
||||||
@ -57,12 +64,12 @@ namespace FileLiberator
|
|||||||
var realMp3Path = FileUtility.SaferMoveToValidPath(mp3File.Name, proposedMp3Path);
|
var realMp3Path = FileUtility.SaferMoveToValidPath(mp3File.Name, proposedMp3Path);
|
||||||
OnFileCreated(libraryBook, realMp3Path);
|
OnFileCreated(libraryBook, realMp3Path);
|
||||||
|
|
||||||
var statusHandler = new StatusHandler();
|
|
||||||
|
|
||||||
if (result == ConversionResult.Failed)
|
if (result == ConversionResult.Failed)
|
||||||
statusHandler.AddError("Conversion failed");
|
return new StatusHandler { "Conversion failed" };
|
||||||
|
else if (result == ConversionResult.Cancelled)
|
||||||
return statusHandler;
|
return new StatusHandler { "Cancelled" };
|
||||||
|
else
|
||||||
|
return new StatusHandler();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user