-
Notifications
You must be signed in to change notification settings - Fork 15
/
configure.go
296 lines (211 loc) · 5.1 KB
/
configure.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
package main
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"gopkg.in/yaml.v3"
)
// Configure : Configure config file
func Configure(filename string) (err error) {
var menu Menu
var entry Entry
var sd SD
Config.File = strings.TrimSuffix(filename, filepath.Ext(filename))
err = Config.Open()
if err != nil {
return
}
sd.Init()
if len(Config.Account.Username) != 0 || len(Config.Account.Password) != 0 {
sd.Login()
sd.Status()
}
for {
menu.Entry = make(map[int]Entry)
menu.Headline = fmt.Sprintf("%s [%s.yaml]", getMsg(0000), Config.File)
menu.Select = getMsg(0001)
// Exit
entry.Key = 0
entry.Value = getMsg(0010)
menu.Entry[0] = entry
// Account
entry.Key = 1
entry.Value = getMsg(0011)
menu.Entry[1] = entry
if len(Config.Account.Username) == 0 || len(Config.Account.Password) == 0 {
entry.account()
err = sd.Login()
if err != nil {
os.RemoveAll(Config.File + ".yaml")
os.Exit(0)
}
sd.Status()
}
// Add Lineup
entry.Key = 2
entry.Value = getMsg(0012)
menu.Entry[2] = entry
// Remove Lineup
entry.Key = 3
entry.Value = getMsg(0013)
menu.Entry[3] = entry
// Manage Channels
entry.Key = 4
entry.Value = getMsg(0014)
menu.Entry[4] = entry
// Create XMLTV file
entry.Key = 5
entry.Value = fmt.Sprintf("%s [%s]", getMsg(0016), Config.Files.XMLTV)
menu.Entry[5] = entry
var selection = menu.Show()
entry = menu.Entry[selection]
switch selection {
case 0:
Config.Save()
os.Exit(0)
case 1:
entry.account()
sd.Login()
sd.Status()
case 2:
entry.addLineup(&sd)
sd.Status()
case 3:
entry.removeLineup(&sd)
sd.Status()
case 4:
entry.manageChannels(&sd)
sd.Status()
case 5:
sd.Update(filename)
}
}
}
func (c *config) Open() (err error) {
data, err := ioutil.ReadFile(fmt.Sprintf("%s.yaml", c.File))
var rmCacheFile, newOptions bool
if err != nil {
// File is missing, create new config file (YAML)
c.InitConfig()
err = c.Save()
if err != nil {
return
}
return nil
}
// Open config file and convert Yaml to Struct (config)
err = yaml.Unmarshal(data, &c)
if err != nil {
return
}
/*
New config options
*/
// Credits tag
if !bytes.Contains(data, []byte("credits tag")) {
rmCacheFile = true
newOptions = true
Config.Options.Credits = true
showInfo("G2G", fmt.Sprintf("%s (credits) [%s]", getMsg(0300), Config.File))
}
// Rating tag
if !bytes.Contains(data, []byte("Rating:")) {
newOptions = true
Config.Options.Rating.Guidelines = true
Config.Options.Rating.Countries = []string{}
Config.Options.Rating.CountryCodeAsSystem = false
Config.Options.Rating.MaxEntries = 1
showInfo("G2G", fmt.Sprintf("%s (rating) [%s]", getMsg(0300), Config.File))
}
// Download Images from TV Shows
if !bytes.Contains(data, []byte("Local Images Cache:")) {
newOptions = true
Config.Options.TVShowImages = false
showInfo("G2G", fmt.Sprintf("%s (Local Images Cache) [%s]", getMsg(401), Config.File))
}
// Download Images from TV Shows
if !bytes.Contains(data, []byte("Images Path:")) {
newOptions = true
Config.Options.ImagesPath = "${images_path}"
showInfo("G2G", fmt.Sprintf("%s (TVShows images Path) [%s]", getMsg(403), Config.File))
}
// Proxy scheduledirect images url
if !bytes.Contains(data, []byte("Proxy Images")) {
newOptions = true
Config.Options.ProxyImages = false
}
// Hostname
if !bytes.Contains(data, []byte("Hostname")) {
newOptions = true
Config.Options.Hostname = "localhost:8080"
}
// SD errors
if !bytes.Contains(data, []byte("download errors")) {
newOptions = true
Config.Options.SDDownloadErrors = false
showInfo("G2G", fmt.Sprintf("%s (SD errors) [%s]", getMsg(0300), Config.File))
}
if newOptions {
err = c.Save()
if err != nil {
return
}
}
if rmCacheFile {
Cache.Remove()
}
return
}
func (c *config) Save() (err error) {
data, err := yaml.Marshal(&c)
if err != nil {
return err
}
err = ioutil.WriteFile(fmt.Sprintf("%s.yaml", c.File), data, 0644)
if err != nil {
return
}
return
}
func (c *config) InitConfig() {
// Files
c.Files.Cache = fmt.Sprintf("%s_cache.json", c.File)
c.Files.XMLTV = fmt.Sprintf("%s.xml", c.File)
// Options
c.Options.PosterAspect = "all"
c.Options.TVShowImages = false
c.Options.Schedule = 7
c.Options.SubtitleIntoDescription = false
c.Options.Credits = false
c.Options.ImagesPath = "/data/images/"
c.Options.ProxyImages = false
Config.Options.Rating.Guidelines = true
Config.Options.Rating.Countries = []string{"USA", "CHE", "DE"}
Config.Options.Rating.CountryCodeAsSystem = false
Config.Options.Rating.MaxEntries = 1
}
func (c *config) GetChannelList(lineup string) (list []string) {
for _, channel := range c.Station {
switch len(lineup) {
case 0:
list = append(list, channel.ID)
default:
if lineup == channel.Lineup {
list = append(list, channel.ID)
}
}
}
return
}
func (c *config) GetLineupCountry(id string) (countryCode string) {
for _, channel := range c.Station {
if id == channel.ID {
countryCode = strings.Split(channel.Lineup, "-")[0]
return
}
}
return
}