Telegram bot for downloading media from any site using yt-dlp. Supports audio/video/both, quality selection, language picker, container format selection, playlist pagination, progress updates, per-user quotas, user preferences, download history, cancel at any step, polling and webhook modes, proxy support, and SQLite persistence.
73 lines
1.5 KiB
Go
73 lines
1.5 KiB
Go
package dl
|
|
|
|
import (
|
|
"math"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseProgressLine(t *testing.T) {
|
|
tests := []struct {
|
|
line string
|
|
pct float64
|
|
speed string
|
|
eta string
|
|
hasRes bool
|
|
}{
|
|
{
|
|
line: "[download] 45.2% of 123.45MiB at 2.34MiB/s ETA 00:45",
|
|
pct: 45.2,
|
|
speed: "2.34MiB/s",
|
|
eta: "00:45",
|
|
hasRes: true,
|
|
},
|
|
{
|
|
line: "[download] 10.0% of ~500.00MiB at 1.50MiB/s ETA 05:30",
|
|
pct: 10.0,
|
|
speed: "1.50MiB/s",
|
|
eta: "05:30",
|
|
hasRes: true,
|
|
},
|
|
{
|
|
line: "[download] 100.0% of 50.00MiB at 5.00MiB/s ETA 00:00",
|
|
pct: 100.0,
|
|
speed: "5.00MiB/s",
|
|
eta: "00:00",
|
|
hasRes: true,
|
|
},
|
|
{
|
|
line: "[youtube] Extracting URL: https://example.com",
|
|
hasRes: false,
|
|
},
|
|
{
|
|
line: "",
|
|
hasRes: false,
|
|
},
|
|
{
|
|
line: "some random log line",
|
|
hasRes: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
got := parseProgressLine(tt.line)
|
|
if !tt.hasRes {
|
|
if got != nil {
|
|
t.Errorf("parseProgressLine(%q) = %+v, want nil", tt.line, got)
|
|
}
|
|
continue
|
|
}
|
|
if got == nil {
|
|
t.Errorf("parseProgressLine(%q) = nil, want result", tt.line)
|
|
continue
|
|
}
|
|
if math.Abs(got.pct-tt.pct) > 0.01 {
|
|
t.Errorf("parseProgressLine(%q).pct = %f, want %f", tt.line, got.pct, tt.pct)
|
|
}
|
|
if got.speed != tt.speed {
|
|
t.Errorf("parseProgressLine(%q).speed = %q, want %q", tt.line, got.speed, tt.speed)
|
|
}
|
|
if got.eta != tt.eta {
|
|
t.Errorf("parseProgressLine(%q).eta = %q, want %q", tt.line, got.eta, tt.eta)
|
|
}
|
|
}
|
|
}
|