Add Track Number support and make Cancel async
This commit is contained in:
parent
ae6c2afb30
commit
4658afdc20
@ -5,8 +5,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AAXClean" Version="0.4.7" />
|
<PackageReference Include="AAXClean.Codecs" Version="0.2.8" />
|
||||||
<PackageReference Include="AAXClean.Codecs" Version="0.2.7" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using AAXClean;
|
using AAXClean;
|
||||||
using Dinah.Core.Net.Http;
|
using Dinah.Core.Net.Http;
|
||||||
|
|
||||||
@ -109,10 +110,11 @@ namespace AaxDecrypter
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Cancel()
|
public override async Task CancelAsync()
|
||||||
{
|
{
|
||||||
IsCanceled = true;
|
IsCanceled = true;
|
||||||
AaxFile?.Cancel();
|
if (AaxFile != null)
|
||||||
|
await AaxFile.CancelAsync();
|
||||||
AaxFile?.Dispose();
|
AaxFile?.Dispose();
|
||||||
CloseInputFileStream();
|
CloseInputFileStream();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,7 +61,7 @@ That naming may not be desirable for everyone, but it's an easy change to instea
|
|||||||
{
|
{
|
||||||
var zeroProgress = Step_DownloadAudiobook_Start();
|
var zeroProgress = Step_DownloadAudiobook_Start();
|
||||||
|
|
||||||
var chapters = DownloadOptions.ChapterInfo.Chapters.ToList();
|
var chapters = DownloadOptions.ChapterInfo.Chapters;
|
||||||
|
|
||||||
// Ensure split files are at least minChapterLength in duration.
|
// Ensure split files are at least minChapterLength in duration.
|
||||||
var splitChapters = new ChapterInfo(DownloadOptions.ChapterInfo.StartOffset);
|
var splitChapters = new ChapterInfo(DownloadOptions.ChapterInfo.StartOffset);
|
||||||
@ -104,8 +104,13 @@ That naming may not be desirable for everyone, but it's an easy change to instea
|
|||||||
{
|
{
|
||||||
var chapterCount = 0;
|
var chapterCount = 0;
|
||||||
return AaxFile.ConvertToMultiMp4a(splitChapters, newSplitCallback =>
|
return AaxFile.ConvertToMultiMp4a(splitChapters, newSplitCallback =>
|
||||||
createOutputFileStream(++chapterCount, splitChapters, newSplitCallback),
|
{
|
||||||
DownloadOptions.TrimOutputToChapterLength);
|
createOutputFileStream(++chapterCount, splitChapters, newSplitCallback);
|
||||||
|
|
||||||
|
newSplitCallback.TrackNumber = chapterCount;
|
||||||
|
newSplitCallback.TrackCount = splitChapters.Count;
|
||||||
|
|
||||||
|
}, DownloadOptions.TrimOutputToChapterLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConversionResult ConvertToMultiMp3(ChapterInfo splitChapters)
|
private ConversionResult ConvertToMultiMp3(ChapterInfo splitChapters)
|
||||||
@ -114,7 +119,10 @@ That naming may not be desirable for everyone, but it's an easy change to instea
|
|||||||
return AaxFile.ConvertToMultiMp3(splitChapters, newSplitCallback =>
|
return AaxFile.ConvertToMultiMp3(splitChapters, newSplitCallback =>
|
||||||
{
|
{
|
||||||
createOutputFileStream(++chapterCount, splitChapters, newSplitCallback);
|
createOutputFileStream(++chapterCount, splitChapters, newSplitCallback);
|
||||||
((NAudio.Lame.LameConfig)newSplitCallback.UserState).ID3.Track = chapterCount.ToString();
|
|
||||||
|
newSplitCallback.TrackNumber = chapterCount;
|
||||||
|
newSplitCallback.TrackCount = splitChapters.Count;
|
||||||
|
|
||||||
}, DownloadOptions.LameConfig, DownloadOptions.TrimOutputToChapterLength);
|
}, DownloadOptions.LameConfig, DownloadOptions.TrimOutputToChapterLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +133,8 @@ That naming may not be desirable for everyone, but it's an easy change to instea
|
|||||||
OutputFileName = OutputFileName,
|
OutputFileName = OutputFileName,
|
||||||
PartsPosition = currentChapter,
|
PartsPosition = currentChapter,
|
||||||
PartsTotal = splitChapters.Count,
|
PartsTotal = splitChapters.Count,
|
||||||
Title = newSplitCallback?.Chapter?.Title
|
Title = newSplitCallback?.Chapter?.Title,
|
||||||
|
|
||||||
});
|
});
|
||||||
fileName = FileUtility.GetValidFilename(fileName);
|
fileName = FileUtility.GetValidFilename(fileName);
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Dinah.Core;
|
using Dinah.Core;
|
||||||
using Dinah.Core.Net.Http;
|
using Dinah.Core.Net.Http;
|
||||||
using Dinah.Core.StepRunner;
|
using Dinah.Core.StepRunner;
|
||||||
@ -55,7 +56,7 @@ namespace AaxDecrypter
|
|||||||
FileUtility.SaferDelete(OutputFileName);
|
FileUtility.SaferDelete(OutputFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void Cancel();
|
public abstract Task CancelAsync();
|
||||||
|
|
||||||
public virtual void SetCoverArt(byte[] coverArt)
|
public virtual void SetCoverArt(byte[] coverArt)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Dinah.Core.Net.Http;
|
using Dinah.Core.Net.Http;
|
||||||
using Dinah.Core.StepRunner;
|
using Dinah.Core.StepRunner;
|
||||||
using FileManager;
|
using FileManager;
|
||||||
@ -24,10 +25,11 @@ namespace AaxDecrypter
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Cancel()
|
public override Task CancelAsync()
|
||||||
{
|
{
|
||||||
IsCanceled = true;
|
IsCanceled = true;
|
||||||
CloseInputFileStream();
|
CloseInputFileStream();
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected bool Step_GetMetadata()
|
protected bool Step_GetMetadata()
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
using LibationFileManager;
|
using LibationFileManager;
|
||||||
using NAudio.Lame;
|
using NAudio.Lame;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace FileLiberator
|
namespace FileLiberator
|
||||||
{
|
{
|
||||||
@ -12,7 +13,7 @@ namespace FileLiberator
|
|||||||
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 abstract void Cancel();
|
public abstract Task CancelAsync();
|
||||||
|
|
||||||
protected LameConfig GetLameOptions(Configuration config)
|
protected LameConfig GetLameOptions(Configuration config)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -19,10 +19,7 @@ namespace FileLiberator
|
|||||||
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()
|
public override Task CancelAsync() => m4bBook?.CancelAsync();
|
||||||
{
|
|
||||||
m4bBook?.Cancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool ValidateMp3(LibraryBook libraryBook)
|
public static bool ValidateMp3(LibraryBook libraryBook)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -21,7 +21,7 @@ namespace FileLiberator
|
|||||||
|
|
||||||
public override bool Validate(LibraryBook libraryBook) => !libraryBook.Book.Audio_Exists();
|
public override bool Validate(LibraryBook libraryBook) => !libraryBook.Book.Audio_Exists();
|
||||||
|
|
||||||
public override void Cancel() => abDownloader?.Cancel();
|
public override Task CancelAsync() => abDownloader?.CancelAsync();
|
||||||
|
|
||||||
public override async Task<StatusHandler> ProcessAsync(LibraryBook libraryBook)
|
public override async Task<StatusHandler> ProcessAsync(LibraryBook libraryBook)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -143,10 +143,7 @@ namespace LibationWinForms.ProcessQueue
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (CurrentProcessable is AudioDecodable audioDecodable)
|
if (CurrentProcessable is AudioDecodable audioDecodable)
|
||||||
{
|
await audioDecodable.CancelAsync();
|
||||||
//There's some threadding bug that causes this to hang if executed synchronously.
|
|
||||||
await Task.Run(audioDecodable.Cancel);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user