From 16bff5391d4bd88b1cfcf72d899016442addc860 Mon Sep 17 00:00:00 2001 From: nilaoda Date: Fri, 19 Aug 2022 23:15:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=80=9F=E5=BA=A6=E8=AE=A1?= =?UTF-8?q?=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/N_m3u8DL-RE/Column/DownloadSpeedColumn.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/N_m3u8DL-RE/Column/DownloadSpeedColumn.cs b/src/N_m3u8DL-RE/Column/DownloadSpeedColumn.cs index c53f571..6acc75c 100644 --- a/src/N_m3u8DL-RE/Column/DownloadSpeedColumn.cs +++ b/src/N_m3u8DL-RE/Column/DownloadSpeedColumn.cs @@ -1,4 +1,5 @@ -using N_m3u8DL_RE.Entity; +using N_m3u8DL_RE.Common.Log; +using N_m3u8DL_RE.Entity; using Spectre.Console; using Spectre.Console.Rendering; using System; @@ -11,7 +12,7 @@ namespace N_m3u8DL_RE.Column { internal sealed class DownloadSpeedColumn : ProgressColumn { - private TimeSpan CalcTimeSpan = TimeSpan.FromSeconds(0); + private string DateTimeString = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); private string Speed = "0Bps"; protected override bool NoWrap => true; public SpeedContainer SpeedContainer { get; set; } @@ -25,13 +26,13 @@ namespace N_m3u8DL_RE.Column public override IRenderable Render(RenderContext context, ProgressTask task, TimeSpan deltaTime) { - CalcTimeSpan = CalcTimeSpan.Add(deltaTime); + var now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //一秒汇报一次即可 - if (CalcTimeSpan.TotalSeconds > 1) + if (DateTimeString != now) { - Speed = FormatFileSize(SpeedContainer.Downloaded / CalcTimeSpan.TotalSeconds); + Speed = FormatFileSize(SpeedContainer.Downloaded); SpeedContainer.Reset(); - CalcTimeSpan = TimeSpan.FromSeconds(0); + DateTimeString = now; } var percentage = (int)task.Percentage; var flag = percentage == 100 || percentage == 0; @@ -47,7 +48,7 @@ namespace N_m3u8DL_RE.Column >= 1024 * 1024 * 1024 => string.Format("{0:########0.00}GBps", (double)fileSize / (1024 * 1024 * 1024)), >= 1024 * 1024 => string.Format("{0:####0.00}MBps", (double)fileSize / (1024 * 1024)), >= 1024 => string.Format("{0:####0.00}KBps", (double)fileSize / 1024), - _ => string.Format("{0}Bps", fileSize) + _ => string.Format("{0:####0.00}Bps", fileSize) }; } }