diff --git a/src/N_m3u8DL-RE/Column/DownloadSpeedColumn.cs b/src/N_m3u8DL-RE/Column/DownloadSpeedColumn.cs index 848ff9c..0fa0903 100644 --- a/src/N_m3u8DL-RE/Column/DownloadSpeedColumn.cs +++ b/src/N_m3u8DL-RE/Column/DownloadSpeedColumn.cs @@ -27,6 +27,13 @@ namespace N_m3u8DL_RE.Column public override IRenderable Render(RenderContext context, ProgressTask task, TimeSpan deltaTime) { var now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + var flag = task.IsFinished || !task.IsStarted; + //单文件下载汇报进度 + if (!flag && SpeedContainer.SingleSegment && SpeedContainer.ResponseLength != null) + { + task.MaxValue = (double)SpeedContainer.ResponseLength; + task.Value = SpeedContainer.RDownloaded; + } //一秒汇报一次即可 if (DateTimeString != now) { @@ -34,7 +41,6 @@ namespace N_m3u8DL_RE.Column SpeedContainer.Reset(); DateTimeString = now; } - var flag = task.IsFinished || !task.IsStarted; var style = flag ? Style.Plain : MyStyle; return flag ? new Text("-", style).Centered() : new Text(Speed, style).Centered(); } diff --git a/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs b/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs index b8e6697..442f847 100644 --- a/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs +++ b/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs @@ -112,11 +112,13 @@ namespace N_m3u8DL_RE.DownloadManager private async Task DownloadStreamAsync(StreamSpec streamSpec, ProgressTask task, SpeedContainer speedContainer) { + speedContainer.ResetVars(); bool useAACFilter = false; //ffmpeg合并flag ConcurrentDictionary FileDic = new(); var segments = streamSpec.Playlist?.MediaParts.SelectMany(m => m.MediaSegments); if (segments == null) return false; + if (segments.Count() == 1) speedContainer.SingleSegment = true; var type = streamSpec.MediaType ?? Common.Enum.MediaType.VIDEO; var dirName = $"{DownloaderConfig.SaveName ?? NowDateTime.ToString("yyyy-MM-dd_HH-mm-ss")}_{streamSpec.GroupId}_{streamSpec.Codecs}_{streamSpec.Bandwidth}_{streamSpec.Language}"; diff --git a/src/N_m3u8DL-RE/Entity/SpeedContainer.cs b/src/N_m3u8DL-RE/Entity/SpeedContainer.cs index 16815d8..66aaa41 100644 --- a/src/N_m3u8DL-RE/Entity/SpeedContainer.cs +++ b/src/N_m3u8DL-RE/Entity/SpeedContainer.cs @@ -11,11 +11,18 @@ namespace N_m3u8DL_RE.Entity { internal class SpeedContainer { + public bool SingleSegment { get; set; } = false; + public long? ResponseLength { get; set; } + public long RDownloaded { get; set; } = 0L; + + /////////////////////////////////////////////////// + private long _downloaded = 0; public long Downloaded { get => _downloaded; } public long Add(long size) { + if (SingleSegment) RDownloaded += size; return Interlocked.Add(ref _downloaded, size); } @@ -23,5 +30,13 @@ namespace N_m3u8DL_RE.Entity { Interlocked.Exchange(ref _downloaded, 0); } + + public void ResetVars() + { + Reset(); + SingleSegment = false; + ResponseLength = null; + RDownloaded = 0L; + } } } diff --git a/src/N_m3u8DL-RE/Util/DownloadUtil.cs b/src/N_m3u8DL-RE/Util/DownloadUtil.cs index be518b5..8d1a4ea 100644 --- a/src/N_m3u8DL-RE/Util/DownloadUtil.cs +++ b/src/N_m3u8DL-RE/Util/DownloadUtil.cs @@ -51,6 +51,8 @@ namespace N_m3u8DL_RE.Util } response.EnsureSuccessStatusCode(); var contentLength = response.Content.Headers.ContentLength; + if (speedContainer.SingleSegment) speedContainer.ResponseLength = contentLength; + using var stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None); using var responseStream = await response.Content.ReadAsStreamAsync(); var buffer = new byte[16 * 1024];