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 @@ - Srinidhi Youtube videos + Youtube Downloader UI +
@@ -30,7 +50,7 @@ {{ if eq .Status "Done" }} Watch {{ else if eq .Status "InProgress" }} - In Progress + In Progress {{ else }} {{ .Status }} {{ end }}