some fixes
This commit is contained in:
parent
52c8d838a5
commit
e418e89e7b
|
@ -5,6 +5,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/dustin/go-humanize"
|
"github.com/dustin/go-humanize"
|
||||||
"github.com/logrusorgru/aurora"
|
"github.com/logrusorgru/aurora"
|
||||||
|
@ -27,9 +28,9 @@ func BeginDownload(posts *[]e621.Post, saveDirectory *string, maxConcurrents *in
|
||||||
var completed int
|
var completed int
|
||||||
var successes int
|
var successes int
|
||||||
var failures int
|
var failures int
|
||||||
|
var current int
|
||||||
|
|
||||||
total := len(*posts)
|
total := len(*posts)
|
||||||
current := 0
|
|
||||||
|
|
||||||
// If we have more workers than posts, then we don't need all of them
|
// If we have more workers than posts, then we don't need all of them
|
||||||
if *maxConcurrents > total {
|
if *maxConcurrents > total {
|
||||||
|
@ -43,6 +44,8 @@ func BeginDownload(posts *[]e621.Post, saveDirectory *string, maxConcurrents *in
|
||||||
// Give them their initial posts
|
// Give them their initial posts
|
||||||
pc <- &(*posts)[current]
|
pc <- &(*posts)[current]
|
||||||
current++
|
current++
|
||||||
|
|
||||||
|
time.Sleep(time.Millisecond * 50)
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
@ -55,14 +58,14 @@ func BeginDownload(posts *[]e621.Post, saveDirectory *string, maxConcurrents *in
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there's no more posts to give, stop the worker
|
// If there's no more posts to give, stop the worker
|
||||||
if current >= total-1 {
|
if current >= total {
|
||||||
pc <- nil
|
pc <- nil
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Give the worker the next post in the array
|
// Give the worker the next post in the array
|
||||||
current++
|
|
||||||
pc <- &(*posts)[current]
|
pc <- &(*posts)[current]
|
||||||
|
current++
|
||||||
}
|
}
|
||||||
|
|
||||||
return &successes, &failures, &total
|
return &successes, &failures, &total
|
||||||
|
@ -72,8 +75,9 @@ func work(wn int, directory string, completed *int, total *int, successes *int,
|
||||||
for {
|
for {
|
||||||
*completed++
|
*completed++
|
||||||
|
|
||||||
|
// Wait for a post from main
|
||||||
post := <-pc
|
post := <-pc
|
||||||
if post == nil {
|
if post == nil { // nil means there aren't any more posts, so we're OK to break
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +107,6 @@ func work(wn int, directory string, completed *int, total *int, successes *int,
|
||||||
|
|
||||||
func getSavePath(post *e621.Post, directory *string) string {
|
func getSavePath(post *e621.Post, directory *string) string {
|
||||||
savePath := path.Join(*directory, strconv.Itoa(post.ID)+"."+post.FileExt)
|
savePath := path.Join(*directory, strconv.Itoa(post.ID)+"."+post.FileExt)
|
||||||
|
|
||||||
return savePath
|
return savePath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue