fix: resolve back step, audio labels, progress parsing, file size pre-check, and stale job cleanup
All checks were successful
CI / build (push) Successful in 36s

- Fix handleBackStep to redirect to download prompt when step state is nil
  (previously silent no-op after container selection cleared the state)
- Improve formatLabel for audio-only entries without bitrate: use ID + extension
  instead of generic 'audio', fixing duplicate entries in format list
- Add yt-dlp --progress-template for reliable JSON progress parsing across all
  sites (fixes 0.0% progress on sites like xnxx.com where [download] lines
  are absent); keep regex parser as fallback for older yt-dlp versions
- Add file size pre-check in handleContainerSelection before download starts
  (previously checked only after download completed, wasting bandwidth)
- Clear stale active jobs and step state on /start for a clean slate
This commit is contained in:
2026-06-25 22:45:25 +03:30
parent 8bcb0094b2
commit 66a8cd1128
6 changed files with 125 additions and 6 deletions

View File

@@ -12,6 +12,7 @@ import (
)
var progressRE = regexp.MustCompile(`\[\w+\]\s+([\d.]+)%\s+of\s+~?([\d.]+)(\w+)`)
var progressTemplateRE = regexp.MustCompile(`^DLPROG\|([\d.]+)\|(.*?)\|(.*)$`)
type progressUpdate struct {
pct float64
@@ -19,11 +20,39 @@ type progressUpdate struct {
eta string
}
// parseProgressTemplate parses a DLPROG-prefixed line from yt-dlp's --progress-template.
func parseProgressTemplate(line string) *progressUpdate {
m := progressTemplateRE.FindStringSubmatch(line)
if m == nil {
return nil
}
pct, err := strconv.ParseFloat(m[1], 64)
if err != nil {
return nil
}
u := &progressUpdate{pct: pct}
speed := strings.TrimSpace(m[2])
eta := strings.TrimSpace(m[3])
if speed != "" && !strings.EqualFold(speed, "unknown") && speed != "N/A" {
u.speed = speed
}
if eta != "" && !strings.EqualFold(eta, "unknown") && eta != "N/A" {
u.eta = eta
}
return u
}
// parseProgressLine parses a single yt-dlp stderr progress line.
// Returns nil if the line doesn't contain progress info.
func parseProgressLine(line string) *progressUpdate {
line = strings.TrimSpace(line)
if line == "" || !strings.HasPrefix(line, "[download]") {
if line == "" {
return nil
}
if u := parseProgressTemplate(line); u != nil {
return u
}
if !strings.HasPrefix(line, "[download]") {
return nil
}
m := progressRE.FindStringSubmatch(line)