-
Notifications
You must be signed in to change notification settings - Fork 7
/
configuration.go
162 lines (148 loc) · 4.87 KB
/
configuration.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package main
import (
"path/filepath"
"sort"
"strconv"
"gopkg.in/ini.v1"
)
// configuration structure
type Configuration struct {
General struct {
Target string `ini:"target"`
Categorize string `ini:"categorize"`
Success_wait_time int `ini:"success_wait_time"`
Error_wait_time int `ini:"error_wait_time"`
Debug bool `ini:"debug"`
} `ini:"GENERAL"`
Execute struct {
Passtofile bool `ini:"passtofile"`
Passtoclipboard bool `ini:"passtoclipboard"`
Nzbsavepath string `ini:"nzbsavepath"`
Dontexecute bool `ini:"dontexecute"`
Clean_up_enable bool `ini:"clean_up_enable"`
Clean_up_max_age int `ini:"clean_up_max_age"`
} `ini:"EXECUTE"`
Sabnzbd struct {
Host string `ini:"host"`
Port int `ini:"port"`
Ssl bool `ini:"ssl"`
SkipCheck bool `ini:"skip_check"`
Nzbkey string `ini:"nzbkey"`
Basicauth_username string `ini:"basicauth_username"`
Basicauth_password string `ini:"basicauth_password"`
Basepath string `ini:"basepath"`
Category string `ini:"category"`
Addpaused bool `ini:"addpaused"`
} `ini:"SABNZBD"`
Nzbget struct {
Host string `ini:"host"`
Port int `ini:"port"`
Ssl bool `ini:"ssl"`
SkipCheck bool `ini:"skip_check"`
Basicauth_username string `ini:"user"`
Basicauth_password string `ini:"pass"`
Basepath string `ini:"basepath"`
Category string `ini:"category"`
Addpaused bool `ini:"addpaused"`
} `ini:"NZBGET"`
Synologyds struct {
Host string `ini:"host"`
Port int `ini:"port"`
Ssl bool `ini:"ssl"`
SkipCheck bool `ini:"skip_check"`
Username string `ini:"user"`
Password string `ini:"pass"`
Basicauth_username string
Basicauth_password string
Basepath string `ini:"basepath"`
} `ini:"SYNOLOGYDLS"`
Nzbcheck struct {
Skip_failed bool `ini:"skip_failed"`
Max_missing_segments_percent float64 `ini:"max_missing_segments_percent"`
Max_missing_files int `ini:"max_missing_files"`
Best_nzb bool `ini:"best_nzb"`
} `ini:"NZBCheck"`
Categories map[string]string `ini:"-"` // will hold the categories regex patterns
Searchengines []string `ini:"-"` // will hold the search engines
Directsearch struct {
Host string `ini:"host"`
Port int `ini:"port"`
SSL bool `ini:"ssl"`
Username string `ini:"username"`
Password string `ini:"password"`
Connections int `ini:"connections"`
Hours int `ini:"hours"`
Forward_hours int `ini:"forward_hours"`
Step int `ini:"step"`
Scans int `ini:"scans"`
Skip bool `ini:"skip"`
First_group_only bool `ini:"first_group_only"`
} `ini:"DIRECTSEARCH"`
}
// global configuration variable
var (
conf Configuration
)
func loadConfig() {
conf = Configuration{}
var configFile string
if args.Config != "" {
configFile = filepath.Clean(args.Config)
} else {
configFile = filepath.Join(appPath, confFile)
}
iniOption := ini.LoadOptions{
IgnoreInlineComment: true,
}
cfg, err := ini.LoadSources(iniOption, configFile)
if err != nil {
Log.Error("Unable to load configuration file '%s': %s", configFile, err.Error())
exit(1)
}
err = cfg.MapTo(&conf)
if err != nil {
Log.Error("Unable to parse configuration file: %s", err.Error())
exit(1)
}
// load categories
conf.Categories = make(map[string]string)
if cfg.HasSection("CATEGORIZER") {
for _, key := range cfg.Section("CATEGORIZER").Keys() {
conf.Categories[key.Name()] = key.Value()
}
}
// load searchengines
searchengines := make(map[string]int)
if cfg.HasSection("SEARCHENGINES") {
for _, key := range cfg.Section("SEARCHENGINES").Keys() {
if _, ok := searchEngines[key.Name()]; ok {
value, err := strconv.Atoi(key.Value())
if err != nil {
Log.Error("Unknown value for searchengine '%s' in configuration file: %s", key.Name(), key.Value())
exit(1)
}
// only load the available searchengines to be used
if _, ok := searchEngines[key.Name()]; ok && value != 0 {
searchengines[key.Name()] = value
}
} else {
Log.Error("Unknown searchengine '%s' in configuration file", key.Name())
exit(1)
}
}
// sort the searchengines
engines := make([]string, 0, len(searchengines))
for engine := range searchengines {
engines = append(engines, engine)
}
sort.SliceStable(engines, func(i, j int) bool {
return searchengines[engines[i]] < searchengines[engines[j]]
})
// add the searchengines to the config
conf.Searchengines = engines
}
// check debug parameter
if !args.Debug {
args.Debug = conf.General.Debug
}
}