3 Commits
v1.2 ... v1.2.1

Author SHA1 Message Date
752dce9751 Updated readme with used libraries 2018-04-28 16:20:38 +02:00
8d11b58cec Added some comments; Cleanup code 2018-04-28 16:15:33 +02:00
35694eaed2 Added progressbar 2018-04-28 16:13:03 +02:00
2 changed files with 27 additions and 7 deletions

View File

@@ -1,3 +1,11 @@
# ytbatchdownloader
A simple Youtube downloader to load multiple videos.
## Credits
Used libraries:
[youtube downloader](https://github.com/kkdai/youtube)
[uiprogress](https://github.com/gosuri/uiprogress)

View File

@@ -10,6 +10,7 @@ import (
"sync"
//"path/filepath"
"github.com/gosuri/uiprogress"
. "github.com/kkdai/youtube"
)
@@ -36,6 +37,11 @@ func (b *Batch) Start() {
//That should be enough for yt links.
scanner := bufio.NewScanner(linkfile)
//Start rendering for progressbar
//This is the initialization the actual bars
//will be instantiated in the go routines
uiprogress.Start()
var wg sync.WaitGroup
for scanner.Scan() {
@@ -67,22 +73,28 @@ func downloadVideo(destDir, url string, wg *sync.WaitGroup) {
re := regexp.MustCompile("(mp4|webm|3gpp)")
fileext := re.FindString(y.StreamList[0]["type"])
filename := fmt.Sprintf("%s/%s.%s", destDir, y.StreamList[0]["title"], fileext)
filenameRune := []rune(y.StreamList[0]["title"])
shortFilename := string(filenameRune[0:20]) + "..."
log.Println("Start downloading:", filename)
go func() {
bar := uiprogress.AddBar(100).AppendCompleted()
//Custom decorator (the short name in front of the bar)
bar.PrependFunc(func(b *uiprogress.Bar) string {
return shortFilename
})
var i int64 = 0
for i < 100 {
i = <-y.DownloadPercent
if i%10 == 0 {
log.Println(i, "%", y.StreamList[0]["title"])
}
bar.Set(int(i))
}
}()
//start the actual download
err := y.StartDownload(filename)
if err != nil {
log.Println("Failed to download", url)
log.Println("Message:", err.Error())
} else {
log.Println("Finished downloading:", filename)
}
}