-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
80 lines (64 loc) · 1.72 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"bufio"
"net/url"
"os"
"path/filepath"
"strings"
"time"
"github.com/The-Eye-Team/Comics-DL/pkg/idata"
"github.com/The-Eye-Team/Comics-DL/pkg/iutil"
"github.com/nektro/go-util/mbpp"
"github.com/nektro/go-util/util"
flag "github.com/spf13/pflag"
_ "github.com/The-Eye-Team/Comics-DL/pkg/sites"
)
var (
Version = "vMASTER"
)
func main() {
util.Log("Starting up Comics-DL " + Version + "...")
util.Log("Brought to you by The-Eye.eu")
flagConcur := flag.IntP("concurrency", "c", 10, "The number of files to download simultaneously.")
flagOutDir := flag.StringP("output-dir", "o", "./results/", "Output directory")
flagKeepJpg := flag.BoolP("keep-jpg", "k", false, "Flag to keep/delete .jpg files of individual pages.")
flagURL := flag.StringP("url", "u", "", "URL of comic to download.")
flagFile := flag.StringP("file", "f", "", "Path to txt file with list of links to download.")
flag.Parse()
outDir, _ := filepath.Abs(*flagOutDir)
outDir = strings.Replace(outDir, string(filepath.Separator), "/", -1)
mbpp.Init(*flagConcur)
idata.KeepJpg = *flagKeepJpg
util.RunOnClose(onClose)
if len(*flagURL) > 0 {
urlO, err := url.Parse(*flagURL)
if err != nil {
util.Log("URL parse error. Aborting!")
return
}
iutil.DoSite(urlO, outDir)
}
if len(*flagFile) > 0 {
pth, _ := filepath.Abs(*flagFile)
if !util.DoesFileExist(pth) {
util.Log("Unable to reach file!")
return
}
file, _ := os.Open(pth)
scan := bufio.NewScanner(file)
for scan.Scan() {
line := scan.Text()
urlO, err := url.Parse(line)
if err != nil {
return
}
iutil.DoSite(urlO, outDir)
}
}
mbpp.Wait()
time.Sleep(time.Second)
onClose()
}
func onClose() {
util.Log(mbpp.GetCompletionMessage())
}