Compare commits

...

10 Commits

Author SHA1 Message Date
BitHeaven f44c3496f5 little update 2023-04-28 16:07:13 +05:00
BitHeaven fc4665fdfb
Update download.go 2022-11-10 20:19:12 +05:00
BitHeaven ae19866d59
Update download.go 2022-11-10 20:18:19 +05:00
BitHeaven 4088e2baf1
Update download.go 2022-11-10 20:16:55 +05:00
BitHeaven 0707246c77
Update download.go 2022-11-10 20:13:59 +05:00
BitHeaven 6c5c181a96
Update download.go 2022-11-10 20:13:24 +05:00
BitHeaven 3a3b768042
Update download.go 2022-11-10 20:07:10 +05:00
BitHeaven 355df543d3
Update main.go 2022-11-10 20:04:47 +05:00
BitHeaven d4d05cfb76
Update download.go 2022-11-10 20:02:37 +05:00
BitHeaven fedb967ec6
Update go.mod 2022-11-10 20:01:15 +05:00
3 changed files with 25 additions and 19 deletions

View File

@ -6,10 +6,11 @@ import (
"path" "path"
"strconv" "strconv"
"time" "time"
"os"
"github.com/dustin/go-humanize" "github.com/dustin/go-humanize"
"github.com/logrusorgru/aurora" "github.com/logrusorgru/aurora"
"github.com/tjhorner/e6dl/e621" "github.com/BitHeaven-Official/e6dl/e621"
) )
// workState stores the state of all the jobs and // workState stores the state of all the jobs and
@ -120,23 +121,28 @@ func getSavePath(post *e621.Post, directory *string) string {
func downloadPost(post *e621.Post, directory string) error { func downloadPost(post *e621.Post, directory string) error {
savePath := getSavePath(post, &directory) savePath := getSavePath(post, &directory)
if _, err := os.Stat(savePath); err == nil {
fmt.Print("File exists, skip...\n")
} else {
resp, err := e621.HTTPGet(post.File.URL)
if err != nil {
return err
}
resp, err := e621.HTTPGet(post.File.URL) defer resp.Body.Close()
if err != nil {
return err body, err := ioutil.ReadAll(resp.Body)
} if err != nil {
return err
defer resp.Body.Close() }
body, err := ioutil.ReadAll(resp.Body) err = ioutil.WriteFile(savePath, body, 0755)
if err != nil { if err != nil {
return err return err
} }
err = ioutil.WriteFile(savePath, body, 0755)
if err != nil {
return err
} }
return nil return nil
} }

2
go.mod
View File

@ -1,4 +1,4 @@
module github.com/tjhorner/e6dl module github.com/BitHeaven-Official/e6dl
go 1.14 go 1.14

View File

@ -14,7 +14,7 @@ func main() {
// define cmd line flags // define cmd line flags
tags := flag.String("tags", "", "Tags to search for") tags := flag.String("tags", "", "Tags to search for")
maxConcurrents := flag.Int("concurrents", 5, "Maximum amount of concurrent downloads") maxConcurrents := flag.Int("concurrents", 5, "Maximum amount of concurrent downloads")
postLimit := flag.Int("limit", 99999999, "Maximum amount of posts to grab from e621") postLimit := flag.Int("limit", 999999999, "Maximum amount of posts to grab from e621")
saveDirectory := flag.String("out", "e621", "The directory to write the downloaded posts to") saveDirectory := flag.String("out", "e621", "The directory to write the downloaded posts to")
sfw := flag.Bool("sfw", false, "Download posts from e926 instead of e621") sfw := flag.Bool("sfw", false, "Download posts from e926 instead of e621")
@ -26,7 +26,7 @@ func main() {
i := 1 i := 1
for { for {
fmt.Printf("Fetching page %d/%d...", i, *pages) fmt.Printf("Fetching page %d...", i)
posts, err := e621.GetPostsForTags(*tags, *postLimit, *sfw, i) posts, err := e621.GetPostsForTags(*tags, *postLimit, *sfw, i)
if err != nil { if err != nil {