-
Notifications
You must be signed in to change notification settings - Fork 41
/
main.go
59 lines (47 loc) · 1.24 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
package main
import (
"flag"
"fmt"
"log"
"os"
)
var (
root = flag.String("dir", "./", "Specifies the directory where the music files are located")
isRecursive = flag.Bool("recursive", false, "If set, Musicrepair will run recursively in the given directory")
setConfig = flag.Bool("config", false, "If set, MusicRepair will ask for credentials")
isRevert = flag.Bool("revert", false, "If set, Musicrepair will revert the files")
threads = flag.Int("threads", 1, "Specify the number of threads to use")
)
func main() {
flag.Parse()
if *setConfig {
SetConfig()
fmt.Println("Your config has been saved.")
os.Exit(1)
}
config, err := LoadConfig()
if err != nil {
log.Fatal(err)
}
client, err := SpotifyAuth(config.ID, config.Secret)
if err != nil {
log.Fatal("Invalid spotify credentials. Error : %v", err)
}
fileList := WalkDir(*root) // List of all files to work on
jobs := make(chan string)
results := make(chan string)
for w := 1; w <= *threads; w++ {
if *isRevert {
go RevertWorker(jobs, results)
} else {
go RepairWorker(client, jobs, results)
}
}
for _, job := range fileList {
jobs <- job
}
close(jobs)
for r := 1; r <= len(fileList); r++ {
fmt.Printf("[%v] %v\n", r, <-results)
}
}