Fixed empty line crash; Download status
This commit is contained in:
21
download.go
21
download.go
@@ -6,6 +6,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
//"path/filepath"
|
//"path/filepath"
|
||||||
|
|
||||||
@@ -41,18 +42,23 @@ func (b *Batch) Start() {
|
|||||||
//Call download
|
//Call download
|
||||||
log.Println(scanner.Text())
|
log.Println(scanner.Text())
|
||||||
//add go routine to wait for
|
//add go routine to wait for
|
||||||
wg.Add(1)
|
if strings.TrimSpace(scanner.Text()) != "" {
|
||||||
go downloadVideo(b.destDir, scanner.Text(), wg)
|
wg.Add(1)
|
||||||
|
go downloadVideo(b.destDir, scanner.Text(), &wg)
|
||||||
|
} else {
|
||||||
|
log.Println("Ignoring blank line")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//wait for all go routines to finish
|
//wait for all go routines to finish
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
log.Println("All downloads finished")
|
||||||
if err := scanner.Err(); err != nil {
|
if err := scanner.Err(); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func downloadVideo(destDir, url string, wg sync.WaitGroup) {
|
func downloadVideo(destDir, url string, wg *sync.WaitGroup) {
|
||||||
// NewYoutube(debug) if debug parameter will set true we can log of messages
|
// NewYoutube(debug) if debug parameter will set true we can log of messages
|
||||||
//defer Done() so that WaitGroup knows when the routine finishes
|
//defer Done() so that WaitGroup knows when the routine finishes
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
@@ -63,6 +69,15 @@ func downloadVideo(destDir, url string, wg sync.WaitGroup) {
|
|||||||
filename := fmt.Sprintf("%s/%s.%s", destDir, y.StreamList[0]["title"], fileext)
|
filename := fmt.Sprintf("%s/%s.%s", destDir, y.StreamList[0]["title"], fileext)
|
||||||
|
|
||||||
log.Println("Start downloading:", filename)
|
log.Println("Start downloading:", filename)
|
||||||
|
go func() {
|
||||||
|
var i int64 = 0
|
||||||
|
for i < 100 {
|
||||||
|
i = <-y.DownloadPercent
|
||||||
|
if i%10 == 0 {
|
||||||
|
log.Println("Status: ", i, "%", y.StreamList[0]["title"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
y.StartDownload(filename)
|
y.StartDownload(filename)
|
||||||
log.Println("Finished downloading:", filename)
|
log.Println("Finished downloading:", filename)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user