fix: remove --progress-template, parse default [download] output instead
All checks were successful
CI / build (push) Successful in 40s

--progress-template output is suppressed in non-TTY subprocesses
(yt-dlp issue #13649). The default [download] progress format
works reliably in pipes. Changes:

- Remove --progress-template from yt-dlp args entirely
- Keep --newline for newline-delimited output in pipe
- Fix progressRE regex to handle HLS format: ~ with leading
  spaces before size (e.g. '~   1.00KiB')
- Fix speed parsing in [download] fallback to handle multiple
  leading spaces (e.g. 'at    976.20B/s')
- Fix ETA parsing to strip (frag n/m) suffix
- Filter Unknown/N/A speed/eta in [download] fallback
- Add test cases for real HLS fragment output format
This commit is contained in:
2026-06-26 00:01:35 +03:30
parent 7c02cd3d89
commit 959b7e388d
3 changed files with 42 additions and 6 deletions

View File

@@ -11,7 +11,7 @@ import (
"uptodownBot/internal/domain" "uptodownBot/internal/domain"
) )
var progressRE = regexp.MustCompile(`\[\w+\]\s+([\d.]+)%\s+of\s+~?([\d.]+)(\w+)`) var progressRE = regexp.MustCompile(`\[\w+\]\s+([\d.]+)%\s+of\s+~?\s*([\d.]+)(\w+)`)
var progressTemplateRE = regexp.MustCompile(`^DLPROG\|\s*([\d.]+)%\|\s*(.*?)\s*\|(.*)$`) var progressTemplateRE = regexp.MustCompile(`^DLPROG\|\s*([\d.]+)%\|\s*(.*?)\s*\|(.*)$`)
type progressUpdate struct { type progressUpdate struct {
@@ -71,16 +71,29 @@ func parseProgressLine(line string) *progressUpdate {
rest = rest[idx+1:] rest = rest[idx+1:]
} }
if atIdx := strings.Index(rest, " at "); atIdx >= 0 { if atIdx := strings.Index(rest, " at "); atIdx >= 0 {
afterAt := rest[atIdx+4:] afterAt := strings.TrimSpace(rest[atIdx+4:])
if spaceIdx := strings.Index(afterAt, " "); spaceIdx >= 0 { if spaceIdx := strings.Index(afterAt, " "); spaceIdx >= 0 {
u.speed = strings.TrimSpace(afterAt[:spaceIdx]) speedVal := afterAt[:spaceIdx]
if !strings.EqualFold(speedVal, "unknown") && speedVal != "N/A" {
u.speed = speedVal
}
rest = afterAt[spaceIdx:] rest = afterAt[spaceIdx:]
} else {
if !strings.EqualFold(afterAt, "unknown") && afterAt != "N/A" {
u.speed = afterAt
}
rest = ""
} }
} }
if etaIdx := strings.Index(rest, "ETA "); etaIdx >= 0 { if etaIdx := strings.Index(rest, "ETA "); etaIdx >= 0 {
etaStr := strings.TrimSpace(rest[etaIdx+4:]) etaStr := strings.TrimSpace(rest[etaIdx+4:])
if parenPos := strings.Index(etaStr, "("); parenPos > 0 {
etaStr = strings.TrimSpace(etaStr[:parenPos])
}
if !strings.EqualFold(etaStr, "unknown") && etaStr != "N/A" {
u.eta = etaStr u.eta = etaStr
} }
}
return u return u
} }

View File

@@ -67,6 +67,27 @@ func TestParseProgressLine(t *testing.T) {
eta: "00:02", eta: "00:02",
hasRes: true, hasRes: true,
}, },
{
line: "[download] 100.0% of ~ 1.00KiB at 976.20B/s ETA Unknown (frag 0/18)",
pct: 100.0,
speed: "976.20B/s",
eta: "",
hasRes: true,
},
{
line: "[download] 16.7% of ~ 18.00KiB at 976.20B/s ETA Unknown (frag 0/18)",
pct: 16.7,
speed: "976.20B/s",
eta: "",
hasRes: true,
},
{
line: "[download] 11.1% of ~ 8.34MiB at 716.47KiB/s ETA 00:08 (frag 1/18)",
pct: 11.1,
speed: "716.47KiB/s",
eta: "00:08",
hasRes: true,
},
{ {
line: "[download] 1.2% of unknown size at 0.00B/s ETA Unknown", line: "[download] 1.2% of unknown size at 0.00B/s ETA Unknown",
hasRes: false, hasRes: false,
@@ -196,6 +217,9 @@ func TestParseProgressLineEdgeCases(t *testing.T) {
{"[download] 0.0% of 1.00GiB at 0.00B/s ETA 00:00", "multiple spaces", true}, {"[download] 0.0% of 1.00GiB at 0.00B/s ETA 00:00", "multiple spaces", true},
{"[download] 100.0% of 1.00GiB at 999.99MiB/s ETA 00:00", "high speed", true}, {"[download] 100.0% of 1.00GiB at 999.99MiB/s ETA 00:00", "high speed", true},
{"[download] 100.0% of 999.99TiB at 1.00TiB/s ETA 00:00", "large numbers", true}, {"[download] 100.0% of 999.99TiB at 1.00TiB/s ETA 00:00", "large numbers", true},
{"[download] 100.0% of ~ 1.00KiB at 976.20B/s ETA Unknown (frag 0/18)", "hls frag first", true},
{"[download] 16.7% of ~ 18.00KiB at 976.20B/s ETA Unknown (frag 0/18)", "hls frag", true},
{"[download] 11.1% of ~ 8.34MiB at 716.47KiB/s ETA 00:08 (frag 1/18)", "hls frag with eta", true},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {

View File

@@ -283,9 +283,8 @@ func (c *Client) StartDownload(job *domain.DownloadJob, downloadDir string) (<-c
outputPath := filepath.Join(downloadDir, job.ID+"_%(id)s.%(ext)s") outputPath := filepath.Join(downloadDir, job.ID+"_%(id)s.%(ext)s")
args = append(args, "--output", outputPath) args = append(args, "--output", outputPath)
// Progress reporting using progress-template for machine-readable output // Use --newline so each progress line is newline-delimited in pipe
args = append(args, "--newline") args = append(args, "--newline")
args = append(args, "--progress-template", "DLPROG|%(progress._percent_str)s|%(progress._speed_str)s|%(progress._eta_str)s")
// Language selection if specified // Language selection if specified
if job.Language != "" { if job.Language != "" {