-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
80 lines (71 loc) · 2.15 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 (
"github.com/mzinin/tagger/logic"
"github.com/mzinin/tagger/utils"
"fmt"
"os"
"strings"
)
var (
version string
source string
destination string = ""
filter string = "ALL"
useExistingTag bool = true
)
func parseCommandLineArguments() bool {
if len(os.Args) < 2 {
return false
}
if len(os.Args) == 2 && os.Args[1][0] != '-' {
source = os.Args[1]
return true
}
i := 1
for i < len(os.Args) {
switch os.Args[i] {
case "-h", "--help":
return false
case "-s", "--source":
source = os.Args[i+1]
i += 2
case "-d", "--destination":
destination = os.Args[i+1]
i += 2
case "-f", "--filter":
filter = strings.ToUpper(os.Args[i+1])
i += 2
case "-n", "--no-existing-tag":
useExistingTag = false
i += 1
default:
fmt.Fprintf(os.Stderr, "Unexpected argument '%v'\n", os.Args[i])
return false
}
}
return true
}
func printUsage() {
fmt.Printf("Usage of %v %v:\n", os.Args[0], version)
fmt.Println("\t-h, --help Print this message.")
fmt.Println("\t-s, --source Input file or directory.")
fmt.Println("\t-d, --destination Output file or directory, same as input by default.")
fmt.Println("\t-f, --filter File filter: ALL | NO_TAG | NO_TITLE | NO_TITLE_ARTIST | NO_TITLE_ARTIST_ALBUM | NO_COVER. NO_COVER by default.")
fmt.Println("\t-n, --no-existing-tag Do not use existing tags to choose recognized tag. False by default.")
}
func main() {
utils.Log(utils.INFO, "Starting Go Music Tagger %v", version)
if !parseCommandLineArguments() {
printUsage()
return
}
tagger, err := logic.NewTagger(source, destination, filter, useExistingTag)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
if err = tagger.Run(); err != nil {
fmt.Fprintln(os.Stderr, err)
}
tagger.PrintReport()
}