From c6e74fe11c2ce20537340e530374722fd390ca49 Mon Sep 17 00:00:00 2001 From: marmei <43099631+mar-mei@users.noreply.github.com> Date: Wed, 4 Sep 2019 20:12:26 +0200 Subject: [PATCH] Interception of repeated save --- src/data.go | 36 ++++++++++++++++++++-- src/internal/m3u-parser/xteve_m3uParser.go | 24 +++++++++++++-- src/struct-system.go | 1 + 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/data.go b/src/data.go index c053819..df88bb6 100644 --- a/src/data.go +++ b/src/data.go @@ -454,8 +454,40 @@ func saveXEpgMapping(request RequestStruct) (err error) { Data.XEPG.Channels = request.EpgMapping - cleanupXEPG() - buildXEPG(true) + 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 } diff --git a/src/internal/m3u-parser/xteve_m3uParser.go b/src/internal/m3u-parser/xteve_m3uParser.go index fa191cd..476d05e 100755 --- a/src/internal/m3u-parser/xteve_m3uParser.go +++ b/src/internal/m3u-parser/xteve_m3uParser.go @@ -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 +} diff --git a/src/struct-system.go b/src/struct-system.go index d180ff8..b246700 100644 --- a/src/struct-system.go +++ b/src/struct-system.go @@ -11,6 +11,7 @@ type SystemStruct struct { APIVersion string AppName string ARCH string + BackgroundProcess bool Branch string Build string Compatibility string