From ef94ab0adfb277efdbfe30b448102cc7297e7c10 Mon Sep 17 00:00:00 2001 From: nilaoda Date: Fri, 9 Dec 2022 22:17:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E4=B8=BA=E6=AF=8F=E7=A7=92=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E4=B8=80=E6=AC=A1=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/N_m3u8DL-RE/Column/DownloadStatusColumn.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/N_m3u8DL-RE/Column/DownloadStatusColumn.cs b/src/N_m3u8DL-RE/Column/DownloadStatusColumn.cs index 9383efc..2fa70f8 100644 --- a/src/N_m3u8DL-RE/Column/DownloadStatusColumn.cs +++ b/src/N_m3u8DL-RE/Column/DownloadStatusColumn.cs @@ -14,6 +14,8 @@ namespace N_m3u8DL_RE.Column internal class DownloadStatusColumn : ProgressColumn { private ConcurrentDictionary SpeedContainerDic { get; set; } + private ConcurrentDictionary DateTimeStringDic = new(); + private ConcurrentDictionary SizeDic = new(); public Style MyStyle { get; set; } = new Style(foreground: Color.DarkCyan); public Style FinishedStyle { get; set; } = new Style(foreground: Color.Green); @@ -25,15 +27,23 @@ namespace N_m3u8DL_RE.Column public override IRenderable Render(RenderContext context, ProgressTask task, TimeSpan deltaTime) { if (task.Value == 0) return new Text("-", MyStyle).RightAligned(); + var now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); var speedContainer = SpeedContainerDic[task.Id]; - var size = speedContainer.RDownloaded; - var totalSize = speedContainer.SingleSegment ? (speedContainer.ResponseLength ?? 0) : (long)(size / (task.Value / task.MaxValue)); - var sizeStr = $"{GlobalUtil.FormatFileSize(size)}/{GlobalUtil.FormatFileSize(totalSize)}"; + //一秒汇报一次即可 + if (DateTimeStringDic.TryGetValue(task.Id, out var oldTime) && oldTime != now) + { + var totalSize = speedContainer.SingleSegment ? (speedContainer.ResponseLength ?? 0) : (long)(size / (task.Value / task.MaxValue)); + SizeDic[task.Id] = $"{GlobalUtil.FormatFileSize(size)}/{GlobalUtil.FormatFileSize(totalSize)}"; + } + DateTimeStringDic[task.Id] = now; + SizeDic.TryGetValue(task.Id, out var sizeStr); + if (task.IsFinished) sizeStr = GlobalUtil.FormatFileSize(size); - return new Text(sizeStr, MyStyle).RightAligned(); + + return new Text(sizeStr ?? "-", MyStyle).RightAligned(); } } }