cleanup errors
This commit is contained in:
parent
7784e58bae
commit
33fe018232
29
main.go
29
main.go
@ -52,7 +52,8 @@ func parse() {
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("vim-go")
|
||||
log.Print("Youtube UI")
|
||||
log.SetFlags(log.Flags() | log.Lshortfile)
|
||||
parse()
|
||||
tmpl := template.New("page")
|
||||
tmpl = tmpl.Funcs(map[string]any{
|
||||
@ -60,11 +61,11 @@ func main() {
|
||||
})
|
||||
tmpl, err := tmpl.Parse(page)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Panic(err)
|
||||
}
|
||||
d, err = db.Load(dbPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Panic(err)
|
||||
}
|
||||
defer d.Save()
|
||||
seen := map[string]struct{}{}
|
||||
@ -77,17 +78,16 @@ func main() {
|
||||
if r.Method == http.MethodGet {
|
||||
d.Run(func(d *db.Jdb) {
|
||||
if err := tmpl.Execute(w, d); err != nil {
|
||||
panic(err)
|
||||
log.Panic(err)
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
if err := r.ParseForm(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
yturl := r.PostFormValue("youtube_url")
|
||||
if yturl == "" {
|
||||
panic("yturl empty")
|
||||
log.Printf("yturl empty, postform:%v\n", r.PostForm)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if _, ok := seen[yturl]; !ok {
|
||||
seen[yturl] = struct{}{}
|
||||
@ -104,18 +104,21 @@ func main() {
|
||||
}
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
})
|
||||
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%v", port), nil))
|
||||
log.Panic(http.ListenAndServe(fmt.Sprintf(":%v", port), nil))
|
||||
}
|
||||
|
||||
func getTitle(id int, yturl string) {
|
||||
args := append(ytdlCmd, "--get-title", yturl)
|
||||
cmd := exec.Command(args[0], args[1:]...)
|
||||
op, err := cmd.Output()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
var title string
|
||||
if op, err := cmd.Output(); err != nil {
|
||||
log.Printf("command failed, cmd: %v, err: %v", cmd, err)
|
||||
title = "ERROR"
|
||||
} else {
|
||||
title = string(op)
|
||||
}
|
||||
d.Update(id, true, func(i *db.Item) {
|
||||
i.Title = string(op)
|
||||
i.Title = title
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user