refactor: modularize downloader architecture

This commit is contained in:
OpenClaw Agent
2026-09-16 06:41:45 +08:00
parent 6c585ff835
commit 285064d144
11 changed files with 766 additions and 558 deletions
+37
View File
@@ -0,0 +1,37 @@
package main
import (
"errors"
"os"
"regexp"
"strings"
"path/filepath"
)
func (a *App) fail(t *Task, err error) {
if t.LocalPath != "" {
_ = os.Remove(t.LocalPath + ".part")
}
if err == nil {
err = errors.New("unknown download error")
}
t.Status, t.Error = "error", err.Error()
a.db.Save(t)
}
var bad = regexp.MustCompile(`[/\\:*?"<>|]+`)
func safe(s string) string {
s = strings.TrimSpace(s)
s = bad.ReplaceAllString(s, "_")
s = strings.Trim(s, ". ")
if s == "" {
return "Unknown"
}
return s
}
func audioPath(dir, artist, title, format string) string {
return filepath.Join(dir, safe(artist)+" - "+safe(title)+"."+normalizedFormat(format))
}