From e9b3d43b792e294a48ad496050232581afe2bb68 Mon Sep 17 00:00:00 2001 From: Patrick Geneva Date: Tue, 8 Dec 2020 18:47:13 -0500 Subject: [PATCH 1/3] For percent printing, overwrite the previous line --- TwitchDownloaderCLI/Program.cs | 17 ++++++++++++++++- TwitchDownloaderCore/ChatDownloader.cs | 2 +- TwitchDownloaderCore/ChatRenderer.cs | 4 ++-- TwitchDownloaderCore/ProgressReport.cs | 3 ++- TwitchDownloaderCore/VideoDownloader.cs | 2 +- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/TwitchDownloaderCLI/Program.cs b/TwitchDownloaderCLI/Program.cs index 3e91e8e9..ff8be870 100644 --- a/TwitchDownloaderCLI/Program.cs +++ b/TwitchDownloaderCLI/Program.cs @@ -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"))) @@ -233,17 +234,31 @@ 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) { - previousStatus = currentStatus; Console.WriteLine(currentStatus); } } 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; + } } } } diff --git a/TwitchDownloaderCore/ChatDownloader.cs b/TwitchDownloaderCore/ChatDownloader.cs index f39d2faf..0bf08cc6 100644 --- a/TwitchDownloaderCore/ChatDownloader.cs +++ b/TwitchDownloaderCore/ChatDownloader.cs @@ -99,7 +99,7 @@ public async Task DownloadAsync(IProgress 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(); diff --git a/TwitchDownloaderCore/ChatRenderer.cs b/TwitchDownloaderCore/ChatRenderer.cs index 43618fa3..78ed68a2 100644 --- a/TwitchDownloaderCore/ChatRenderer.cs +++ b/TwitchDownloaderCore/ChatRenderer.cs @@ -132,7 +132,7 @@ await Task.Run(() => } }); - 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(finalComments.ToArray()), chatJson, progress), cancellationToken); progress.Report(new ProgressReport() { reportType = ReportType.Message, data = "Cleaning up..." }); Cleanup(downloadFolder); @@ -411,7 +411,7 @@ private void RenderVideo(ChatRenderOptions renderOptions, Queue 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)" }); } } } diff --git a/TwitchDownloaderCore/ProgressReport.cs b/TwitchDownloaderCore/ProgressReport.cs index 4f08a17a..0d3c8c39 100644 --- a/TwitchDownloaderCore/ProgressReport.cs +++ b/TwitchDownloaderCore/ProgressReport.cs @@ -4,7 +4,8 @@ public enum ReportType { Log, Percent, - Message + Message, + MessageInfo } public class ProgressReport diff --git a/TwitchDownloaderCore/VideoDownloader.cs b/TwitchDownloaderCore/VideoDownloader.cs index 3b320bff..680cf787 100644 --- a/TwitchDownloaderCore/VideoDownloader.cs +++ b/TwitchDownloaderCore/VideoDownloader.cs @@ -143,7 +143,7 @@ public async Task DownloadAsync(IProgress 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; From 6aaf812ab72ecb2467843de62f7a6ddc0fcba460 Mon Sep 17 00:00:00 2001 From: Patrick Geneva Date: Tue, 8 Dec 2020 18:52:49 -0500 Subject: [PATCH 2/3] Revert, save the previous status --- TwitchDownloaderCLI/Program.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/TwitchDownloaderCLI/Program.cs b/TwitchDownloaderCLI/Program.cs index ff8be870..721187cd 100644 --- a/TwitchDownloaderCLI/Program.cs +++ b/TwitchDownloaderCLI/Program.cs @@ -242,6 +242,7 @@ private static void Progress_ProgressChanged(object sender, ProgressReport e) string currentStatus = "[STATUS] - " + e.data; if (currentStatus != previousStatus) { + previousStatus = currentStatus; Console.WriteLine(currentStatus); } } From 4bd8d05cf7ec5c3112612e0932676b994f0837bc Mon Sep 17 00:00:00 2001 From: Patrick Geneva Date: Tue, 8 Dec 2020 19:01:33 -0500 Subject: [PATCH 3/3] Properly update the UI status message --- TwitchDownloaderWPF/PageChatDownload.xaml.cs | 2 +- TwitchDownloaderWPF/PageChatRender.xaml.cs | 2 +- TwitchDownloaderWPF/PageVodDownload.xaml.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/TwitchDownloaderWPF/PageChatDownload.xaml.cs b/TwitchDownloaderWPF/PageChatDownload.xaml.cs index cd405262..cd4da4a0 100644 --- a/TwitchDownloaderWPF/PageChatDownload.xaml.cs +++ b/TwitchDownloaderWPF/PageChatDownload.xaml.cs @@ -257,7 +257,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); diff --git a/TwitchDownloaderWPF/PageChatRender.xaml.cs b/TwitchDownloaderWPF/PageChatRender.xaml.cs index a795ea16..b3aeb282 100644 --- a/TwitchDownloaderWPF/PageChatRender.xaml.cs +++ b/TwitchDownloaderWPF/PageChatRender.xaml.cs @@ -129,7 +129,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); diff --git a/TwitchDownloaderWPF/PageVodDownload.xaml.cs b/TwitchDownloaderWPF/PageVodDownload.xaml.cs index 07af8e19..a62bb60b 100644 --- a/TwitchDownloaderWPF/PageVodDownload.xaml.cs +++ b/TwitchDownloaderWPF/PageVodDownload.xaml.cs @@ -196,7 +196,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);