-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (48 loc) · 1.02 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
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"flag"
"fmt"
"os"
"regexp"
)
var REGEXP = regexp.MustCompile(`public/(\S+/\S+)`)
var (
help = flag.Bool("help", false, "Display this message")
h = flag.Bool("h", false, "Display this message (shorthand)")
output = flag.String("output", ".", "Output folder")
o = flag.String("o", ".", "Output folder (shorthand)")
compress = flag.Bool("compress", false, "Compress downloads")
c = flag.Bool("c", false, "Compress downloads (shorthand)")
)
func main() {
flag.Parse()
if *help || *h {
flag.Usage()
os.Exit(0)
}
arg := flag.Arg(0)
match := REGEXP.FindStringSubmatch(arg)
if match == nil {
fmt.Println("URL is incorrect")
os.Exit(1)
}
tree, err := GetFiles(match[1])
if err != nil {
panic(err)
}
var path string
if *output != "." {
path = *output
tree.Folder = *output
}
if *o != "." {
path = *o
tree.Folder = *o
}
DownloadFiles(path, tree)
if *compress || *c {
fmt.Println("Archiving...")
ArchiveFiles(path, tree)
RemoveFiles(path, tree)
}
}