refactor: modularize downloader architecture
This commit is contained in:
@@ -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))
|
||||
}
|
||||
Reference in New Issue
Block a user