diff --git a/pixiv/downloader.go b/pixiv/downloader.go index d2ac912..356979b 100644 --- a/pixiv/downloader.go +++ b/pixiv/downloader.go @@ -51,21 +51,26 @@ func (p *Pixiv) downloadIllust(i Illust) (err error) { if err != nil { return err } - outfile, err := os.Create(file.directory + file.filename) - if err != nil { - return err - } - defer outfile.Close() - //log.Printf("Downloading %s to %s", file.url, outfile.Name()) - err = p.downloadTo(file.url, outfile) - if err != nil { - return err - } - if p.setxattr { - err = syscall.Setxattr(outfile.Name(), "user.xdg.tags", []byte(i.TagsString()), 0) + if _, err = os.Stat(file.directory + file.filename); os.IsNotExist(err) { + outfile, err := os.Create(file.directory + file.filename) if err != nil { return err } + defer outfile.Close() + //log.Printf("Downloading %s to %s", file.url, outfile.Name()) + err = p.downloadTo(file.url, outfile) + if err != nil { + return err + } + if p.setxattr { + err = syscall.Setxattr(outfile.Name(), "user.xdg.tags", []byte(i.TagsString()), 0) + if err != nil { + return err + } + } + } else { + err = nil + continue } } return