fix: show first progress update immediately instead of waiting for 5%

- Always show the first nonzero progress update so users don't see 0% for
  extended periods on slow downloads or fragment-based downloads
- Keep 5% throttle for subsequent updates to avoid excessive API calls
- Add readProgress summary logging (lines, matches, stderr length)
- Fix progressKeyboard not being updated until progress >= 5%
This commit is contained in:
2026-06-25 16:23:07 +03:30
parent cd7aaeebc2
commit e8120b9529
2 changed files with 23 additions and 10 deletions

View File

@@ -3,6 +3,7 @@ package dl
import (
"bufio"
"io"
"log/slog"
"regexp"
"strconv"
"strings"
@@ -60,8 +61,11 @@ func parseProgressLine(line string) *progressUpdate {
func readProgress(stderr io.ReadCloser, updates chan<- *domain.DownloadJob, job *domain.DownloadJob) {
var stderrBuf strings.Builder
scanner := bufio.NewScanner(stderr)
lineCount := 0
matchCount := 0
for scanner.Scan() {
line := scanner.Text()
lineCount++
if stderrBuf.Len() < 4096 {
stderrBuf.WriteString(line)
@@ -72,10 +76,12 @@ func readProgress(stderr io.ReadCloser, updates chan<- *domain.DownloadJob, job
if parsed == nil {
continue
}
matchCount++
job.Progress = parsed.pct
job.Speed = parsed.speed
job.ETA = parsed.eta
updates <- job
}
job.StderrLog = stderrBuf.String()
slog.Info("readProgress finished", "url", job.URL, "lines", lineCount, "matches", matchCount, "stderr_len", len(job.StderrLog))
}