diff --git a/internal/dl/progress.go b/internal/dl/progress.go index 0dc7d03..8bd482c 100644 --- a/internal/dl/progress.go +++ b/internal/dl/progress.go @@ -12,7 +12,7 @@ import ( ) var progressRE = regexp.MustCompile(`\[\w+\]\s+([\d.]+)%\s+of\s+~?([\d.]+)(\w+)`) -var progressTemplateRE = regexp.MustCompile(`^DLPROG\|([\d.]+)\|(.*?)\|(.*)$`) +var progressTemplateRE = regexp.MustCompile(`^DLPROG\|\s*([\d.]+)%\|\s*(.*?)\s*\|(.*)$`) type progressUpdate struct { pct float64 diff --git a/internal/dl/progress_test.go b/internal/dl/progress_test.go index f3b0b2a..f512d31 100644 --- a/internal/dl/progress_test.go +++ b/internal/dl/progress_test.go @@ -109,21 +109,21 @@ func TestParseProgressTemplate(t *testing.T) { hasRes bool }{ { - line: "DLPROG|45.2|2.34MiB/s|00:45", + 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", + 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||", + line: "DLPROG| 0.0%||", pct: 0.0, speed: "", eta: "", @@ -142,12 +142,26 @@ func TestParseProgressTemplate(t *testing.T) { hasRes: false, }, { - line: "DLPROG|50.0|Unknown|Unknown", + line: "DLPROG| 50.0%| Unknown|Unknown", pct: 50.0, speed: "", eta: "", hasRes: true, }, + { + line: "DLPROG| 16.7%| 1.05KiB/s|Unknown", + pct: 16.7, + speed: "1.05KiB/s", + eta: "", + hasRes: true, + }, + { + line: "DLPROG| 11.1%| 754.59KiB/s|00:08", + pct: 11.1, + speed: "754.59KiB/s", + eta: "00:08", + hasRes: true, + }, } for _, tt := range tests { got := parseProgressTemplate(tt.line) diff --git a/internal/dl/ytdlp.go b/internal/dl/ytdlp.go index 2ed2314..a34dd9f 100644 --- a/internal/dl/ytdlp.go +++ b/internal/dl/ytdlp.go @@ -285,7 +285,7 @@ func (c *Client) StartDownload(job *domain.DownloadJob, downloadDir string) (<-c // Progress reporting using progress-template for machine-readable output args = append(args, "--newline") - args = append(args, "--progress-template", "stderr:DLPROG|%(progress.percent)s|%(progress.speed)s|%(progress.eta)s") + args = append(args, "--progress-template", "DLPROG|%(progress._percent_str)s|%(progress._speed_str)s|%(progress._eta_str)s") // Language selection if specified if job.Language != "" { diff --git a/internal/handler/download.go b/internal/handler/download.go index 51c299c..1989a2a 100644 --- a/internal/handler/download.go +++ b/internal/handler/download.go @@ -400,11 +400,11 @@ func (h *Handler) runDownload(ctx context.Context, job *domain.DownloadJob) { h.trackDownloadProgress(ctx, job, updates) - h.clearActiveJob(job.UserID) - if job.Status == domain.StatusCompleted { h.handleDownloadCompletion(ctx, job) } + + h.clearActiveJob(job.UserID) } // trackDownloadProgress reads progress updates from yt-dlp and updates the Telegram message.