From 784b82313c0c10d023c363785f54b3307aa1580d Mon Sep 17 00:00:00 2001 From: balki <3070606-balki@users.noreply.gitlab.com> Date: Wed, 29 Jun 2022 10:35:43 -0400 Subject: [PATCH] front end done --- main.go | 25 ++++++++++++++----------- templates/index.html | 24 ++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index a446bd8..ee8b82a 100644 --- a/main.go +++ b/main.go @@ -106,14 +106,15 @@ func main() { return } fmt.Println("path is", p, "id is", id) + var sc <-chan string + d.Run(func(d *db.Jdb) { + pt := d.Items[id].Pt + if pt != nil { + sc = pt.Subscribe() + } + }) var wh websocket.Handler = func(c *websocket.Conn) { defer c.Close() - log.Println("Are you here?") - var sc <-chan string - d.Run(func(d *db.Jdb) { - pt := d.Items[id].Pt - sc = pt.Subscribe() - }) if sc != nil { for update := range sc { _, err := c.Write([]byte(update)) @@ -137,7 +138,8 @@ func main() { } return } - c.Write([]byte(fname)) + alink := fmt.Sprintf(`Watch`, videosUrl, fname) + c.Write([]byte(alink)) } wh.ServeHTTP(w, r) }) @@ -171,19 +173,20 @@ func download(id int, yturl string) { log.Panic(err) } + //Log progress go func() { var sc <-chan string d.Run(func(d *db.Jdb) { pt := d.Items[id].Pt sc = pt.Subscribe() }) - log.Println("before watching") + log.Println("Watching download progress for id: ", id) if sc != nil { for update := range sc { log.Println(update) } } - log.Println("after watching") + log.Println("Done watching download progress for id: ", id) }() var status db.DownloadStatus @@ -201,8 +204,8 @@ func download(id int, yturl string) { } func downloadYt(id int, yturl string, pc chan<- string) (string, error) { - // pathTmpl := fmt.Sprintf("%s/video_%d.%%(ext)s", cachePath, id) - pathTmpl := fmt.Sprintf("%s/video_%d.mp4", cachePath, id) + pathTmpl := fmt.Sprintf("%s/video_%d.%%(ext)s", cachePath, id) + // pathTmpl := fmt.Sprintf("%s/video_%d.mp4", cachePath, id) args := append(ytdlCmd, "--newline", "--output", pathTmpl, yturl) cmd := exec.Command(args[0], args[1:]...) rc, err := cmd.StdoutPipe() diff --git a/templates/index.html b/templates/index.html index 4f4707a..d31bc90 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,9 +1,29 @@
-