Update download.go

This commit is contained in:
BitHeaven 2022-11-10 20:16:55 +05:00 committed by GitHub
parent 0707246c77
commit 4088e2baf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 15 deletions

View File

@ -121,25 +121,28 @@ func getSavePath(post *e621.Post, directory *string) string {
func downloadPost(post *e621.Post, directory string) error {
savePath := getSavePath(post, &directory)
fmt.Print(post.File.URL)
fmt.Print(savePath)
resp, err := e621.HTTPGet(post.File.URL)
if err != nil {
return err
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
}
defer resp.Body.Close()
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
err = ioutil.WriteFile(savePath, body, 0755)
if err != nil {
return err
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
err = ioutil.WriteFile(savePath, body, 0755)
if err != nil {
return err
}
}
return nil
}