From 0ccfdd70970daf9c329c512a38ca2a03ac53fa56 Mon Sep 17 00:00:00 2001 From: TJ Horner Date: Thu, 28 Feb 2019 11:57:42 -0800 Subject: [PATCH] better output --- download.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/download.go b/download.go index e894157..93011f7 100644 --- a/download.go +++ b/download.go @@ -44,15 +44,31 @@ func work(wn int, posts []Post, directory string, completed *int, total *int, wg for _, post := range posts { *completed++ - fmt.Printf("[%d/%d] [w%d] Downloading post %d (%s)...\n", *completed, *total, wn, post.ID, humanize.Bytes(uint64(post.FileSize))) + fmt.Printf( + "[%d/%d] [w%d] Downloading post %d (%s) -> %s...\n", + *completed, + *total, + wn, + post.ID, + humanize.Bytes(uint64(post.FileSize)), + getSavePath(&post, &directory), + ) downloadPost(&post, directory) } } -func downloadPost(post *Post, directory string) { +func getSavePath(post *Post, directory *string) string { pathSliced := strings.Split(post.FileURL, ".") extension := pathSliced[len(pathSliced)-1] + savePath := path.Join(*directory, strconv.Itoa(post.ID)+"."+extension) + + return savePath +} + +func downloadPost(post *Post, directory string) { + savePath := getSavePath(post, &directory) + resp, err := HTTPGet(post.FileURL) if err != nil { fmt.Println("Unable to download, skipping...") @@ -66,8 +82,6 @@ func downloadPost(post *Post, directory string) { return } - savePath := path.Join(directory, strconv.Itoa(post.ID)+"."+extension) - err = ioutil.WriteFile(savePath, body, 0755) if err != nil { fmt.Printf("Error: could not write to file: %v\n", err)