Simplified download decrypt progress update.
Removed unused fields and properties.
This commit is contained in:
parent
792207caee
commit
0c159df6ca
@ -144,8 +144,7 @@ namespace FileLiberator.AaxcDownloadDecrypt
|
||||
|
||||
var aaxcProcesser = new FFMpegAaxcProcesser(DecryptSupportLibraries.ffmpegPath);
|
||||
|
||||
aaxcProcesser.ProgressUpdate += (_, e) =>
|
||||
DecryptProgressUpdate?.Invoke(this, (int)e.ProgressPercent);
|
||||
aaxcProcesser.ProgressUpdate += AaxcProcesser_ProgressUpdate;
|
||||
|
||||
aaxcProcesser.ProcessBook(
|
||||
downloadLicense.DownloadUrl,
|
||||
@ -160,6 +159,13 @@ namespace FileLiberator.AaxcDownloadDecrypt
|
||||
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)
|
||||
{
|
||||
var stringBuilder = new System.Text.StringBuilder();
|
||||
|
||||
@ -6,27 +6,19 @@ using System.Threading.Tasks;
|
||||
|
||||
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>
|
||||
/// Download audible aaxc, decrypt, remux, add metadata, and insert cover art.
|
||||
/// </summary>
|
||||
class FFMpegAaxcProcesser
|
||||
{
|
||||
public event EventHandler<AaxcProgress> ProgressUpdate;
|
||||
public event EventHandler<TimeSpan> ProgressUpdate;
|
||||
public string FFMpegPath { get; }
|
||||
public bool IsRunning { get; set; } = false;
|
||||
public bool Succeeded { get; private set; }
|
||||
|
||||
|
||||
private static Regex processedTimeRegex = new Regex("time=(\\d{2}):(\\d{2}):(\\d{2}).\\d{2}", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
private static Regex durationRegex = new Regex("Duration: (\\d{2}):(\\d{2}):(\\d{2}).\\d{2}", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
private TimeSpan duration { get; set; }
|
||||
private TimeSpan position { get; set; }
|
||||
public FFMpegAaxcProcesser(string ffmpegPath)
|
||||
{
|
||||
FFMpegPath = ffmpegPath;
|
||||
@ -50,11 +42,9 @@ namespace FileLiberator.AaxcDownloadDecrypt
|
||||
|
||||
IsRunning = true;
|
||||
|
||||
downloader.ErrorDataReceived += Downloader_ErrorDataReceived;
|
||||
remuxer.ErrorDataReceived += Remuxer_ErrorDataReceived;
|
||||
|
||||
downloader.Start();
|
||||
downloader.BeginErrorReadLine();
|
||||
|
||||
var pipedOutput = downloader.StandardOutput.BaseStream;
|
||||
|
||||
@ -91,22 +81,6 @@ namespace FileLiberator.AaxcDownloadDecrypt
|
||||
IsRunning = false;
|
||||
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)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(e.Data) && processedTimeRegex.IsMatch(e.Data))
|
||||
@ -118,13 +92,9 @@ namespace FileLiberator.AaxcDownloadDecrypt
|
||||
int minutes = int.Parse(match.Groups[2].Value);
|
||||
int seconds = int.Parse(match.Groups[3].Value);
|
||||
|
||||
position = new TimeSpan(hours, minutes, seconds);
|
||||
var position = new TimeSpan(hours, minutes, seconds);
|
||||
|
||||
ProgressUpdate?.Invoke(sender, new AaxcProgress
|
||||
{
|
||||
ProcessedTime = position,
|
||||
AudioDuration = duration
|
||||
});
|
||||
ProgressUpdate?.Invoke(sender, position);
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,7 +103,6 @@ namespace FileLiberator.AaxcDownloadDecrypt
|
||||
{
|
||||
FileName = FFMpegPath,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
CreateNoWindow = true,
|
||||
WindowStyle = ProcessWindowStyle.Hidden,
|
||||
UseShellExecute = false,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user