Sumplified download decrypt progress update.
This commit is contained in:
parent
792207caee
commit
be41dca9e0
@ -144,8 +144,7 @@ namespace FileLiberator.AaxcDownloadDecrypt
|
|||||||
|
|
||||||
var aaxcProcesser = new FFMpegAaxcProcesser(DecryptSupportLibraries.ffmpegPath);
|
var aaxcProcesser = new FFMpegAaxcProcesser(DecryptSupportLibraries.ffmpegPath);
|
||||||
|
|
||||||
aaxcProcesser.ProgressUpdate += (_, e) =>
|
aaxcProcesser.ProgressUpdate += AaxcProcesser_ProgressUpdate;
|
||||||
DecryptProgressUpdate?.Invoke(this, (int)e.ProgressPercent);
|
|
||||||
|
|
||||||
aaxcProcesser.ProcessBook(
|
aaxcProcesser.ProcessBook(
|
||||||
downloadLicense.DownloadUrl,
|
downloadLicense.DownloadUrl,
|
||||||
@ -160,6 +159,13 @@ namespace FileLiberator.AaxcDownloadDecrypt
|
|||||||
return aaxcProcesser.Succeeded;
|
return aaxcProcesser.Succeeded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AaxcProcesser_ProgressUpdate(object sender, TimeSpan e)
|
||||||
|
{
|
||||||
|
double progressPercent = Math.Max(100 * e.TotalSeconds / tags.duration.TotalSeconds, 1);
|
||||||
|
|
||||||
|
DecryptProgressUpdate?.Invoke(this, (int)progressPercent);
|
||||||
|
}
|
||||||
|
|
||||||
private static string GenerateFfmpegChapters(ChapterInfo chapters)
|
private static string GenerateFfmpegChapters(ChapterInfo chapters)
|
||||||
{
|
{
|
||||||
var stringBuilder = new System.Text.StringBuilder();
|
var stringBuilder = new System.Text.StringBuilder();
|
||||||
|
|||||||
@ -6,18 +6,13 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace FileLiberator.AaxcDownloadDecrypt
|
namespace FileLiberator.AaxcDownloadDecrypt
|
||||||
{
|
{
|
||||||
public class AaxcProgress : EventArgs
|
|
||||||
{
|
|
||||||
public TimeSpan ProcessedTime { get; set; }
|
|
||||||
public TimeSpan AudioDuration { get; set; }
|
|
||||||
public double ProgressPercent => Math.Round(100 * ProcessedTime.TotalSeconds / AudioDuration.TotalSeconds,2);
|
|
||||||
}
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Download audible aaxc, decrypt, remux, add metadata, and insert cover art.
|
/// Download audible aaxc, decrypt, remux, add metadata, and insert cover art.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class FFMpegAaxcProcesser
|
class FFMpegAaxcProcesser
|
||||||
{
|
{
|
||||||
public event EventHandler<AaxcProgress> ProgressUpdate;
|
public event EventHandler<TimeSpan> ProgressUpdate;
|
||||||
public string FFMpegPath { get; }
|
public string FFMpegPath { get; }
|
||||||
public bool IsRunning { get; set; } = false;
|
public bool IsRunning { get; set; } = false;
|
||||||
public bool Succeeded { get; private set; }
|
public bool Succeeded { get; private set; }
|
||||||
@ -50,11 +45,9 @@ namespace FileLiberator.AaxcDownloadDecrypt
|
|||||||
|
|
||||||
IsRunning = true;
|
IsRunning = true;
|
||||||
|
|
||||||
downloader.ErrorDataReceived += Downloader_ErrorDataReceived;
|
|
||||||
remuxer.ErrorDataReceived += Remuxer_ErrorDataReceived;
|
remuxer.ErrorDataReceived += Remuxer_ErrorDataReceived;
|
||||||
|
|
||||||
downloader.Start();
|
downloader.Start();
|
||||||
downloader.BeginErrorReadLine();
|
|
||||||
|
|
||||||
var pipedOutput = downloader.StandardOutput.BaseStream;
|
var pipedOutput = downloader.StandardOutput.BaseStream;
|
||||||
|
|
||||||
@ -91,22 +84,6 @@ namespace FileLiberator.AaxcDownloadDecrypt
|
|||||||
IsRunning = false;
|
IsRunning = false;
|
||||||
Succeeded = downloader.ExitCode == 0 && remuxer.ExitCode == 0;
|
Succeeded = downloader.ExitCode == 0 && remuxer.ExitCode == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Downloader_ErrorDataReceived(object sender, DataReceivedEventArgs e)
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrEmpty(e.Data) && durationRegex.IsMatch(e.Data))
|
|
||||||
{
|
|
||||||
//get total audio stream duration
|
|
||||||
var match = durationRegex.Match(e.Data);
|
|
||||||
|
|
||||||
int hours = int.Parse(match.Groups[1].Value);
|
|
||||||
int minutes = int.Parse(match.Groups[2].Value);
|
|
||||||
int seconds = int.Parse(match.Groups[3].Value);
|
|
||||||
|
|
||||||
duration = new TimeSpan(hours, minutes, seconds);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Remuxer_ErrorDataReceived(object sender, DataReceivedEventArgs e)
|
private void Remuxer_ErrorDataReceived(object sender, DataReceivedEventArgs e)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(e.Data) && processedTimeRegex.IsMatch(e.Data))
|
if (!string.IsNullOrEmpty(e.Data) && processedTimeRegex.IsMatch(e.Data))
|
||||||
@ -120,11 +97,7 @@ namespace FileLiberator.AaxcDownloadDecrypt
|
|||||||
|
|
||||||
position = new TimeSpan(hours, minutes, seconds);
|
position = new TimeSpan(hours, minutes, seconds);
|
||||||
|
|
||||||
ProgressUpdate?.Invoke(sender, new AaxcProgress
|
ProgressUpdate?.Invoke(sender, position);
|
||||||
{
|
|
||||||
ProcessedTime = position,
|
|
||||||
AudioDuration = duration
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +106,6 @@ namespace FileLiberator.AaxcDownloadDecrypt
|
|||||||
{
|
{
|
||||||
FileName = FFMpegPath,
|
FileName = FFMpegPath,
|
||||||
RedirectStandardOutput = true,
|
RedirectStandardOutput = true,
|
||||||
RedirectStandardError = true,
|
|
||||||
CreateNoWindow = true,
|
CreateNoWindow = true,
|
||||||
WindowStyle = ProcessWindowStyle.Hidden,
|
WindowStyle = ProcessWindowStyle.Hidden,
|
||||||
UseShellExecute = false,
|
UseShellExecute = false,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user