forked from riptl/fma-scraper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
args.go
69 lines (58 loc) · 1.34 KB
/
args.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
package main
import (
"fmt"
"github.com/spf13/pflag"
"os"
)
var genre = pflag.StringP("genre", "g", "", "Genre to archive")
var listGenres = pflag.Bool("list-genres", false, "Print a list of genres")
var concurrency = pflag.UintP("concurrency", "c", 4, "Number of concurrent downloads")
var minPage = pflag.Uint("min-page", 1, "Starting page")
var pageSize = pflag.Uint("page-size", 500, "Page size")
var dir = pflag.StringP("out-dir", "o", "Downloads", "Output directory")
var verbose = pflag.BoolP("verbose", "v", false, "More output")
var availableGenres = [...]string{
"Blues",
"Classical",
"Country",
"Electronic",
"Experimental",
"Folk",
"Hip-Hop",
"Instrumental",
"International",
"Jazz",
"Novelty",
"Old-Time__Historic",
"Pop",
"Rock",
"Soul-RB",
"Spoken",
}
func parseArgs() error {
pflag.Usage = func() {
fmt.Fprintln(os.Stderr,
`Free Music Archive Scraper by terorie 2018
<< https://github.com/terorie/fma-scraper >>
Usage:`)
pflag.PrintDefaults()
}
pflag.Parse()
if *listGenres {
fmt.Println("Available Genres:")
for _, g := range availableGenres {
fmt.Println(g)
}
os.Exit(1)
}
if *genre == "" {
return fmt.Errorf("-g/--genre flag required")
}
if *concurrency <= 0 {
return fmt.Errorf("invalid value for --concurrency")
}
if err := os.MkdirAll(*dir, 0777); err != nil {
return err
}
return nil
}