-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.go
52 lines (40 loc) · 1.17 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"fmt"
"os"
"strconv"
"github.com/joho/godotenv"
)
func main() {
err := godotenv.Load()
if err != nil {
panic(err)
}
downloadsDir := os.Getenv("DOWNLOADSDIR")
args := os.Args
albumURL := args[1]
finalizeWithZip := args[len(args)-1] == "-z"
pageSource := getContents(albumURL)
modelName, albumName := getAlbumInfo(pageSource)
imagesFound := crawlImages(pageSource)
fmt.Println("Found", albumName, "set from", modelName, "!")
fmt.Println("Found", len(imagesFound), "images in set. Downloading...")
albumDir := downloadsDir + "/" + modelName + " - " + albumName
checkAndCreateDir(downloadsDir)
checkAndCreateDir(albumDir)
imagesDownloaded := []string{}
for i, imageURL := range imagesFound {
imageOutput := albumDir + "/" + leftPad(strconv.Itoa(i), "0", digitsLen(len(imagesFound))-1) + ".jpg"
fmt.Println(imageURL + " -> " + imageOutput)
imagesDownloaded = append(imagesDownloaded, imageOutput)
b, _ := saveImage(imageURL, imageOutput)
fmt.Println("File size:", b)
}
if finalizeWithZip {
err := ZipFiles(albumDir+"/"+albumName+".zip", imagesDownloaded)
if err != nil {
panic(err)
}
}
fmt.Println("Done... Enjoy!")
}