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(),