Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lay295 committed Dec 21, 2020
2 parents 902b617 + ef09495 commit 3e19e64
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 9 deletions.
16 changes: 16 additions & 0 deletions TwitchDownloaderCLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Program
{
static string previousStatus = "";
static string ffmpegPath = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "ffmpeg.exe" : "ffmpeg";
static bool was_last_message_percent = false;
static void Main(string[] args)
{
if (args.Any(x => x.Equals("--download-ffmpeg")))
Expand Down Expand Up @@ -241,6 +242,11 @@ private static void Progress_ProgressChanged(object sender, ProgressReport e)
{
if (e.reportType == ReportType.Message)
{
if (was_last_message_percent)
{
was_last_message_percent = false;
Console.WriteLine("");
}
string currentStatus = "[STATUS] - " + e.data;
if (currentStatus != previousStatus)
{
Expand All @@ -250,8 +256,18 @@ private static void Progress_ProgressChanged(object sender, ProgressReport e)
}
else if (e.reportType == ReportType.Log)
{
if(was_last_message_percent)
{
was_last_message_percent = false;
Console.WriteLine("");
}
Console.WriteLine("[LOG] - " + e.data);
}
else if (e.reportType == ReportType.MessageInfo)
{
Console.Write("\r[STATUS] - " + e.data);
was_last_message_percent = true;
}
}
}
}
2 changes: 1 addition & 1 deletion TwitchDownloaderCore/ChatDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public async Task DownloadAsync(IProgress<ProgressReport> progress, Cancellation

int percent = (int)Math.Floor((latestMessage - videoStart) / videoDuration * 100);
progress.Report(new ProgressReport() { reportType = ReportType.Percent, data = percent });
progress.Report(new ProgressReport() { reportType = ReportType.Message, data = $"Downloading {percent}%" });
progress.Report(new ProgressReport() { reportType = ReportType.MessageInfo, data = $"Downloading {percent}%" });

cancellationToken.ThrowIfCancellationRequested();

Expand Down
6 changes: 3 additions & 3 deletions TwitchDownloaderCore/ChatRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ await Task.Run(() =>
CheckCancelation(cancellationToken, downloadFolder);
}
});

progress.Report(new ProgressReport() { reportType = ReportType.Message, data = "Rendering Video 0%" });
progress.Report(new ProgressReport() { reportType = ReportType.MessageInfo, data = "Rendering Video 0%" });
await Task.Run(() => RenderVideo(renderOptions, new Queue<TwitchComment>(finalComments.OrderBy(x => x.SecondsOffset)), chatJson, progress), cancellationToken);
progress.Report(new ProgressReport() { reportType = ReportType.Message, data = "Cleaning up..." });
Cleanup(downloadFolder);
Expand Down Expand Up @@ -428,7 +428,7 @@ private void RenderVideo(ChatRenderOptions renderOptions, Queue<TwitchComment> f
progress.Report(new ProgressReport() { reportType = ReportType.Percent, data = percentInt });
int timeLeftInt = (int)Math.Floor(100.0 / percentDouble * stopwatch.Elapsed.TotalSeconds) - (int)stopwatch.Elapsed.TotalSeconds;
TimeSpan timeLeft = new TimeSpan(0, 0, timeLeftInt);
progress.Report(new ProgressReport() { reportType = ReportType.Message, data = $"Rendering Video {percentInt}% ({timeLeft.ToString(@"h\hm\ms\s")} left)" });
progress.Report(new ProgressReport() { reportType = ReportType.MessageInfo, data = $"Rendering Video {percentInt}% ({timeLeft.ToString(@"h\hm\ms\s")} left)" });
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion TwitchDownloaderCore/ProgressReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ public enum ReportType
{
Log,
Percent,
Message
Message,
MessageInfo
}

public class ProgressReport
Expand Down
2 changes: 1 addition & 1 deletion TwitchDownloaderCore/VideoDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public async Task DownloadAsync(IProgress<ProgressReport> progress, Cancellation

doneCount++;
int percent = (int)Math.Floor(((double)doneCount / (double)partCount) * 100);
progress.Report(new ProgressReport() { reportType = ReportType.Message, data = String.Format("Downloading {0}% (1/3)", percent) });
progress.Report(new ProgressReport() { reportType = ReportType.MessageInfo, data = String.Format("Downloading {0}% (1/3)", percent) });
progress.Report(new ProgressReport() { reportType = ReportType.Percent, data = percent });

return;
Expand Down
2 changes: 1 addition & 1 deletion TwitchDownloaderWPF/PageChatDownload.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private void OnProgressChanged(ProgressReport progress)
{
if (progress.reportType == ReportType.Percent)
statusProgressBar.Value = (int)progress.data;
if (progress.reportType == ReportType.Message)
if (progress.reportType == ReportType.Message || progress.reportType == ReportType.MessageInfo)
statusMessage.Text = (string)progress.data;
if (progress.reportType == ReportType.Log)
AppendLog((string)progress.data);
Expand Down
2 changes: 1 addition & 1 deletion TwitchDownloaderWPF/PageChatRender.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private void OnProgressChanged(ProgressReport progress)
{
if (progress.reportType == ReportType.Percent)
statusProgressBar.Value = (int)progress.data;
if (progress.reportType == ReportType.Message)
if (progress.reportType == ReportType.Message || progress.reportType == ReportType.MessageInfo)
statusMessage.Text = (string)progress.data;
if (progress.reportType == ReportType.Log)
AppendLog((string)progress.data);
Expand Down
2 changes: 1 addition & 1 deletion TwitchDownloaderWPF/PageVodDownload.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private void OnProgressChanged(ProgressReport progress)
{
if (progress.reportType == ReportType.Percent)
statusProgressBar.Value = (int) progress.data;
if (progress.reportType == ReportType.Message)
if (progress.reportType == ReportType.Message || progress.reportType == ReportType.MessageInfo)
statusMessage.Text = (string)progress.data;
if (progress.reportType == ReportType.Log)
AppendLog((string)progress.data);
Expand Down

0 comments on commit 3e19e64

Please sign in to comment.