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
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:
@@ -100,6 +100,79 @@ func TestParseProgressLine(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseProgressTemplate(t *testing.T) {
|
||||
tests := []struct {
|
||||
line string
|
||||
pct float64
|
||||
speed string
|
||||
eta string
|
||||
hasRes bool
|
||||
}{
|
||||
{
|
||||
line: "DLPROG|45.2|2.34MiB/s|00:45",
|
||||
pct: 45.2,
|
||||
speed: "2.34MiB/s",
|
||||
eta: "00:45",
|
||||
hasRes: true,
|
||||
},
|
||||
{
|
||||
line: "DLPROG|100.0|5.00MiB/s|00:00",
|
||||
pct: 100.0,
|
||||
speed: "5.00MiB/s",
|
||||
eta: "00:00",
|
||||
hasRes: true,
|
||||
},
|
||||
{
|
||||
line: "DLPROG|0.0||",
|
||||
pct: 0.0,
|
||||
speed: "",
|
||||
eta: "",
|
||||
hasRes: true,
|
||||
},
|
||||
{
|
||||
line: "not a progress line",
|
||||
hasRes: false,
|
||||
},
|
||||
{
|
||||
line: "",
|
||||
hasRes: false,
|
||||
},
|
||||
{
|
||||
line: "[download] 45.2% of 123.45MiB at 2.34MiB/s ETA 00:45",
|
||||
hasRes: false,
|
||||
},
|
||||
{
|
||||
line: "DLPROG|50.0|Unknown|Unknown",
|
||||
pct: 50.0,
|
||||
speed: "",
|
||||
eta: "",
|
||||
hasRes: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
got := parseProgressTemplate(tt.line)
|
||||
if !tt.hasRes {
|
||||
if got != nil {
|
||||
t.Errorf("parseProgressTemplate(%q) = %+v, want nil", tt.line, got)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if got == nil {
|
||||
t.Errorf("parseProgressTemplate(%q) = nil, want result", tt.line)
|
||||
continue
|
||||
}
|
||||
if math.Abs(got.pct-tt.pct) > 0.01 {
|
||||
t.Errorf("parseProgressTemplate(%q).pct = %f, want %f", tt.line, got.pct, tt.pct)
|
||||
}
|
||||
if got.speed != tt.speed {
|
||||
t.Errorf("parseProgressTemplate(%q).speed = %q, want %q", tt.line, got.speed, tt.speed)
|
||||
}
|
||||
if got.eta != tt.eta {
|
||||
t.Errorf("parseProgressTemplate(%q).eta = %q, want %q", tt.line, got.eta, tt.eta)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseProgressLineEdgeCases(t *testing.T) {
|
||||
tests := []struct {
|
||||
line string
|
||||
|
||||
Reference in New Issue
Block a user