From 17f5acde5a44830eb5d8c3747bc5ad9f2a95979e Mon Sep 17 00:00:00 2001 From: nilaoda Date: Sat, 3 Dec 2022 23:59:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8D=95=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F=E8=BF=9B=E5=BA=A6=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Column/DownloadStatusColumn.cs | 26 +++++++++++++++---- .../DownloadManager/SimpleDownloadManager.cs | 4 +-- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/N_m3u8DL-RE/Column/DownloadStatusColumn.cs b/src/N_m3u8DL-RE/Column/DownloadStatusColumn.cs index 7c22b57..f98c44e 100644 --- a/src/N_m3u8DL-RE/Column/DownloadStatusColumn.cs +++ b/src/N_m3u8DL-RE/Column/DownloadStatusColumn.cs @@ -1,4 +1,5 @@ using N_m3u8DL_RE.Common.Util; +using N_m3u8DL_RE.Entity; using Spectre.Console; using Spectre.Console.Rendering; using System; @@ -12,25 +13,40 @@ namespace N_m3u8DL_RE.Column { internal class DownloadStatusColumn : ProgressColumn { - protected override bool NoWrap => true; private ConcurrentDictionary DownloadedSizeDic = new(); + private ConcurrentDictionary SpeedContainerDic { get; set; } public Style MyStyle { get; set; } = new Style(foreground: Color.DarkCyan); public Style FinishedStyle { get; set; } = new Style(foreground: Color.Green); - public DownloadStatusColumn(ConcurrentDictionary downloadedSizeDic) + public DownloadStatusColumn(ConcurrentDictionary downloadedSizeDic, ConcurrentDictionary speedContainerDic) { this.DownloadedSizeDic = downloadedSizeDic; + this.SpeedContainerDic = speedContainerDic; } public override IRenderable Render(RenderContext context, ProgressTask task, TimeSpan deltaTime) { + if (task.Value == 0) return new Text("", MyStyle).RightAligned(); + var done = task.IsFinished; + + var flag = DownloadedSizeDic.TryGetValue(task.Id, out var size); var totalSize = flag ? (size / (task.Value / task.MaxValue)) : 0; - var sizeStr = size == 0 ? "" : $"{GlobalUtil.FormatFileSize(flag ? size : 0)}/{GlobalUtil.FormatFileSize(totalSize)}"; - if (done) sizeStr = GlobalUtil.FormatFileSize(totalSize); - return new Markup(sizeStr, MyStyle).RightAligned(); + //单文件下载汇报进度 + var speedContainer = SpeedContainerDic[task.Id]; + if (!done && speedContainer.SingleSegment && speedContainer.ResponseLength != null) + { + task.MaxValue = (double)speedContainer.ResponseLength; + task.Value = speedContainer.RDownloaded; + size = speedContainer.RDownloaded; + totalSize = (double)speedContainer.ResponseLength; + } + + var sizeStr = $"{GlobalUtil.FormatFileSize(flag ? size : 0)}/{GlobalUtil.FormatFileSize(totalSize)}"; + if (done) sizeStr = GlobalUtil.FormatFileSize(totalSize); + return new Text(sizeStr, MyStyle).RightAligned(); } } } diff --git a/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs b/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs index 073ad55..c189c8c 100644 --- a/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs +++ b/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs @@ -643,9 +643,9 @@ namespace N_m3u8DL_RE.DownloadManager progress.Columns(new ProgressColumn[] { new TaskDescriptionColumn() { Alignment = Justify.Left }, - new ProgressBarColumn() { Width = 30 }, + new ProgressBarColumn(), new PercentageColumn(), - new DownloadStatusColumn(DownloadedSizeDic), + new DownloadStatusColumn(DownloadedSizeDic, SpeedContainerDic), new DownloadSpeedColumn(SpeedContainerDic), //速度计算 new RemainingTimeColumn(), new SpinnerColumn(),