forked from Threadfin/Threadfin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
282 lines (216 loc) · 7.94 KB
/
config.go
File metadata and controls
282 lines (216 loc) · 7.94 KB
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
package src
import (
"fmt"
"os"
"runtime"
"strings"
"sync"
"github.com/avfs/avfs"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
// System : Beinhaltet alle Systeminformationen
var System SystemStruct
// WebScreenLog : Logs werden im RAM gespeichert und für das Webinterface bereitgestellt
var WebScreenLog WebScreenLogStruct
// Settings : Inhalt der settings.json
var Settings SettingsStruct
// Data : Alle Daten werden hier abgelegt. (Lineup, XMLTV)
var Data DataStruct
// SystemFiles : Alle Systemdateien
var SystemFiles = []string{"authentication.json", "pms.json", "settings.json", "xepg.json", "urls.json"}
// BufferInformation : Informationen über den Buffer (aktive Streams, maximale Streams)
var BufferInformation sync.Map
// bufferVFS : Filesystem to use for the Buffer
var bufferVFS avfs.VFS
// BufferClients : Anzahl der Clients die einen Stream über den Buffer abspielen
var BufferClients sync.Map
// Lock : Lock Map
var Lock = sync.RWMutex{}
var (
xepgMutex sync.Mutex
infoMutex sync.Mutex
logMutex sync.Mutex
systemMutex sync.Mutex
)
// Init : Systeminitialisierung
func Init() (err error) {
var debug string
// System Einstellungen
System.AppName = strings.ToLower(System.Name)
System.ARCH = runtime.GOARCH
System.OS = runtime.GOOS
System.ServerProtocol.API = "http"
System.ServerProtocol.DVR = "http"
System.ServerProtocol.M3U = "http"
System.ServerProtocol.WEB = "http"
System.ServerProtocol.XML = "http"
System.PlexChannelLimit = 480
System.UnfilteredChannelLimit = 480
System.Compatibility = "0.1.0"
// FFmpeg Default Einstellungen
System.FFmpeg.DefaultOptions = "-hide_banner -loglevel error -analyzeduration 1000000 -probesize 1000000 -i [URL] -map 0:v -map 0:a:0 -c:v copy -c:a aac -b:a 192k -ac 2 -c:s copy -f mpegts -fflags +genpts -movflags +faststart -copyts pipe:1"
System.VLC.DefaultOptions = "-I dummy [URL] --sout #std{mux=ts,access=file,dst=-}"
// Default Logeinträge, wird später von denen aus der settings.json überschrieben. Muss gemacht werden, damit die ersten Einträge auch im Log (webUI aangezeigt werden)
Settings.LogEntriesRAM = 500
// Variablen für den Update Prozess
//System.Update.Git = "https://github.com/Threadfin/Threadfin/blob"
System.Update.Git = fmt.Sprintf("https://github.com/%s/%s", System.GitHub.User, System.GitHub.Repo)
System.Update.Github = fmt.Sprintf("https://api.github.com/repos/%s/%s", System.GitHub.User, System.GitHub.Repo)
System.Update.Name = "Threadfin"
// Ordnerpfade festlegen
var tempFolder = os.TempDir() + string(os.PathSeparator) + System.AppName + string(os.PathSeparator)
tempFolder = getPlatformPath(strings.Replace(tempFolder, "//", "/", -1))
if len(System.Folder.Config) == 0 {
System.Folder.Config = GetUserHomeDirectory() + string(os.PathSeparator) + "." + System.AppName + string(os.PathSeparator)
} else {
System.Folder.Config = strings.TrimRight(System.Folder.Config, string(os.PathSeparator)) + string(os.PathSeparator)
}
System.Folder.Config = getPlatformPath(System.Folder.Config)
System.Folder.Backup = System.Folder.Config + "backup" + string(os.PathSeparator)
System.Folder.Data = System.Folder.Config + "data" + string(os.PathSeparator)
System.Folder.Cache = System.Folder.Config + "cache" + string(os.PathSeparator)
System.Folder.ImagesCache = System.Folder.Cache + "images" + string(os.PathSeparator)
System.Folder.ImagesUpload = System.Folder.Data + "images" + string(os.PathSeparator)
System.Folder.Temp = tempFolder
// Dev Info
showDevInfo()
// System Ordner erstellen
err = createSystemFolders()
if err != nil {
ShowError(err, 1070)
return
}
if len(System.Flag.Restore) > 0 {
// Einstellungen werden über CLI wiederhergestellt. Weitere Initialisierung ist nicht notwendig.
return
}
System.File.XML = getPlatformFile(fmt.Sprintf("%s%s.xml", System.Folder.Data, System.AppName))
System.File.M3U = getPlatformFile(fmt.Sprintf("%s%s.m3u", System.Folder.Data, System.AppName))
System.Compressed.GZxml = getPlatformFile(fmt.Sprintf("%s%s.xml.gz", System.Folder.Data, System.AppName))
err = activatedSystemAuthentication()
if err != nil {
return
}
err = resolveHostIP()
if err != nil {
ShowError(err, 1002)
}
// Menü für das Webinterface
System.WEB.Menu = []string{"playlist", "xmltv", "filter", "mapping", "users", "settings", "log", "logout"}
fmt.Println("For help run: " + getPlatformFile(os.Args[0]) + " -h")
fmt.Println()
// Überprüfen ob Threadfin als root läuft
if os.Geteuid() == 0 {
showWarning(2110)
}
if System.Flag.Debug > 0 {
debug = fmt.Sprintf("Debug Level:%d", System.Flag.Debug)
showDebug(debug, 1)
}
showInfo(fmt.Sprintf("Version:%s Build: %s", System.Version, System.Build))
showInfo(fmt.Sprintf("Database Version:%s", System.DBVersion))
showInfo(fmt.Sprintf("System IP Addresses:IPv4: %d | IPv6: %d", len(System.IPAddressesV4), len(System.IPAddressesV6)))
showInfo("Hostname:" + System.Hostname)
showInfo(fmt.Sprintf("System Folder:%s", getPlatformPath(System.Folder.Config)))
// Systemdateien erstellen (Falls nicht vorhanden)
err = createSystemFiles()
if err != nil {
ShowError(err, 1071)
return
}
err = conditionalUpdateChanges()
if err != nil {
return
}
// Einstellungen laden (settings.json)
showInfo(fmt.Sprintf("Load Settings:%s", System.File.Settings))
_, err = loadSettings()
if err != nil {
ShowError(err, 0)
return
}
// Berechtigung aller Ordner überprüfen
err = checkFilePermission(System.Folder.Config)
if err == nil {
err = checkFilePermission(System.Folder.Temp)
}
// Separaten tmp Ordner für jede Instanz
//System.Folder.Temp = System.Folder.Temp + Settings.UUID + string(os.PathSeparator)
showInfo(fmt.Sprintf("Temporary Folder:%s", getPlatformPath(System.Folder.Temp)))
err = checkFolder(System.Folder.Temp)
if err != nil {
return
}
err = removeChildItems(getPlatformPath(System.Folder.Temp))
if err != nil {
return
}
// Branch festlegen
System.Branch = cases.Title(language.English).String(Settings.Branch)
if System.Dev {
System.Branch = cases.Title(language.English).String("development")
}
if len(System.Branch) == 0 {
System.Branch = cases.Title(language.English).String("main")
}
showInfo(fmt.Sprintf("GitHub:https://github.com/%s", System.GitHub.User))
showInfo(fmt.Sprintf("Git Branch:%s [%s]", System.Branch, System.GitHub.User))
// Set base URI
if Settings.HttpThreadfinDomain != "" {
setGlobalDomain(getBaseUrl(Settings.HttpThreadfinDomain, Settings.Port))
} else {
setGlobalDomain(fmt.Sprintf("%s:%s", System.IPAddress, Settings.Port))
}
System.URLBase = fmt.Sprintf("%s://%s:%s", System.ServerProtocol.WEB, System.IPAddress, Settings.Port)
// HTML Dateien erstellen, mit dev == true werden die lokalen HTML Dateien verwendet
if System.Dev == true {
HTMLInit("webUI", "src", "html"+string(os.PathSeparator), "src"+string(os.PathSeparator)+"webUI.go")
err = BuildGoFile()
if err != nil {
return
}
}
// DLNA Server starten
if Settings.SSDP {
err = SSDP()
if err != nil {
return
}
}
// HTML Datein laden
loadHTMLMap()
return
}
// StartSystem : System wird gestartet
func StartSystem(updateProviderFiles bool) (err error) {
setDeviceID()
if System.ScanInProgress == 1 {
return
}
// Systeminformationen in der Konsole ausgeben
showInfo(fmt.Sprintf("UUID:%s", Settings.UUID))
showInfo(fmt.Sprintf("Tuner (Plex / Emby):%d", Settings.Tuner))
showInfo(fmt.Sprintf("EPG Source:%s", Settings.EpgSource))
showInfo(fmt.Sprintf("Plex Channel Limit:%d", System.PlexChannelLimit))
showInfo(fmt.Sprintf("Unfiltered Chan. Limit:%d", System.UnfilteredChannelLimit))
// Providerdaten aktualisieren
if len(Settings.Files.M3U) > 0 && Settings.FilesUpdate == true || updateProviderFiles == true {
err = ThreadfinAutoBackup()
if err != nil {
ShowError(err, 1090)
}
getProviderData("m3u", "")
getProviderData("hdhr", "")
if Settings.EpgSource == "XEPG" {
getProviderData("xmltv", "")
}
}
err = buildDatabaseDVR()
if err != nil {
ShowError(err, 0)
return
}
buildXEPG(true)
return
}