Interception of repeated save

This commit is contained in:
marmei
2019-09-04 20:12:26 +02:00
parent 18dba46c02
commit c6e74fe11c
3 changed files with 57 additions and 4 deletions

View File

@@ -454,8 +454,40 @@ func saveXEpgMapping(request RequestStruct) (err error) {
Data.XEPG.Channels = request.EpgMapping
if System.ScanInProgress == 0 {
cleanupXEPG()
buildXEPG(true)
} else {
// Wenn während des erstellen der Datanbank das Mapping erneut gespeichert wird, wird die Datenbank erst später erneut aktualisiert.
go func() {
if System.BackgroundProcess == true {
return
}
System.BackgroundProcess = true
for {
time.Sleep(time.Duration(1) * time.Second)
fmt.Println("Scan", System.ScanInProgress)
if System.ScanInProgress == 0 {
break
}
}
cleanupXEPG()
buildXEPG(false)
System.BackgroundProcess = false
}()
}
return
}

View File

@@ -2,6 +2,8 @@ package m3u
import (
"errors"
"fmt"
"log"
"net/url"
"regexp"
"strings"
@@ -12,6 +14,7 @@ func MakeInterfaceFromM3U(byteStream []byte) (allChannels []interface{}, err err
var content = string(byteStream)
var channelName string
var uuids []string
var parseMetaData = func(channel string) (stream map[string]string) {
@@ -53,7 +56,7 @@ func MakeInterfaceFromM3U(byteStream []byte) (allChannels []interface{}, err err
line = strings.Replace(line, p, "", 1)
p = strings.Replace(p, `"`, "", -1)
var parameter = strings.Split(p, "=")
var parameter = strings.SplitN(p, "=", 2)
if len(parameter) == 2 {
@@ -120,9 +123,15 @@ func MakeInterfaceFromM3U(byteStream []byte) (allChannels []interface{}, err err
if strings.Contains(strings.ToLower(key), "id") {
if indexOfString(value, uuids) != -1 {
log.Println(fmt.Sprintf("Channel: %s - %s = %s ", stream["name"], key, value))
break
}
uuids = append(uuids, value)
stream["_uuid.key"] = key
stream["_uuid.value"] = value
//os.Exit(0)
break
}
@@ -160,3 +169,14 @@ func MakeInterfaceFromM3U(byteStream []byte) (allChannels []interface{}, err err
return
}
func indexOfString(element string, data []string) int {
for k, v := range data {
if element == v {
return k
}
}
return -1
}

View File

@@ -11,6 +11,7 @@ type SystemStruct struct {
APIVersion string
AppName string
ARCH string
BackgroundProcess bool
Branch string
Build string
Compatibility string