Fixed: undefined playlist

This commit is contained in:
xteve-project
2020-10-16 16:43:56 +02:00
parent 410cc3648f
commit 6d890cfd33

View File

@@ -8,6 +8,7 @@ import (
"io/ioutil" "io/ioutil"
"path" "path"
"runtime" "runtime"
"sort"
"crypto/md5" "crypto/md5"
"encoding/hex" "encoding/hex"
@@ -330,21 +331,20 @@ func createXEPGDatabase() (err error) {
var getFreeChannelNumber = func() (xChannelID string) { var getFreeChannelNumber = func() (xChannelID string) {
sort.Float64s(allChannelNumbers)
var firstFreeNumber float64 = Settings.MappingFirstChannel var firstFreeNumber float64 = Settings.MappingFirstChannel
if len(allChannelNumbers) > 0 && indexOfFloat64(firstFreeNumber, allChannelNumbers) >= 0 { //channels exist and first channel number is taken for {
firstFreeNumber = allChannelNumbers[len(allChannelNumbers)-1] //Start with last assigned channel number. Avoids checking from the beginning each time
firstFreeNumber++
}
newNumber: if indexOfFloat64(firstFreeNumber, allChannelNumbers) == -1 {
xChannelID = fmt.Sprintf("%g", firstFreeNumber)
allChannelNumbers = append(allChannelNumbers, firstFreeNumber)
return
}
if indexOfFloat64(firstFreeNumber, allChannelNumbers) == -1 {
xChannelID = fmt.Sprintf("%g", firstFreeNumber)
allChannelNumbers = append(allChannelNumbers, firstFreeNumber)
} else {
firstFreeNumber++ firstFreeNumber++
goto newNumber
} }
return return
@@ -401,7 +401,7 @@ func createXEPGDatabase() (err error) {
return return
} }
Data.Cache.Streams.Active = append(Data.Cache.Streams.Active, m3uChannel.Name) Data.Cache.Streams.Active = append(Data.Cache.Streams.Active, m3uChannel.Name+m3uChannel.FileM3UID)
// Try to find the channel based on matching all known values. If that fails, then move to full channel scan // Try to find the channel based on matching all known values. If that fails, then move to full channel scan
m3uChannelHash := generateHashForChannel(m3uChannel.FileM3UID, m3uChannel.GroupTitle, m3uChannel.TvgID, m3uChannel.TvgName, m3uChannel.UUIDKey, m3uChannel.UUIDValue) m3uChannelHash := generateHashForChannel(m3uChannel.FileM3UID, m3uChannel.GroupTitle, m3uChannel.TvgID, m3uChannel.TvgName, m3uChannel.UUIDKey, m3uChannel.UUIDValue)
@@ -416,24 +416,31 @@ func createXEPGDatabase() (err error) {
// XEPG Datenbank durchlaufen um nach dem Kanal zu suchen. Run through the XEPG database to search for the channel (full scan) // XEPG Datenbank durchlaufen um nach dem Kanal zu suchen. Run through the XEPG database to search for the channel (full scan)
for _, dxc := range xepgChannelsValuesMap { for _, dxc := range xepgChannelsValuesMap {
// Vergleichen des Streams anhand einer UUID in der M3U mit dem Kanal in der Databank. Compare the stream using a UUID in the M3U with the channel in the database if m3uChannel.FileM3UID == dxc.FileM3UID {
if len(dxc.UUIDValue) > 0 && len(m3uChannel.UUIDValue) > 0 {
if dxc.UUIDValue == m3uChannel.UUIDValue && dxc.UUIDKey == m3uChannel.UUIDKey { dxc.FileM3UID = m3uChannel.FileM3UID
dxc.FileM3UName = m3uChannel.FileM3UName
channelExists = true // Vergleichen des Streams anhand einer UUID in der M3U mit dem Kanal in der Databank. Compare the stream using a UUID in the M3U with the channel in the database
channelHasUUID = true if len(dxc.UUIDValue) > 0 && len(m3uChannel.UUIDValue) > 0 {
currentXEPGID = dxc.XEPG
break
} if dxc.UUIDValue == m3uChannel.UUIDValue && dxc.UUIDKey == m3uChannel.UUIDKey {
channelExists = true
channelHasUUID = true
currentXEPGID = dxc.XEPG
break
}
} else {
// Vergleichen des Streams mit dem Kanal in der Databank anhand des Kanalnamens. Compare the stream to the channel in the database using the channel name
if dxc.Name == m3uChannel.Name {
channelExists = true
currentXEPGID = dxc.XEPG
break
}
} else {
// Vergleichen des Streams mit dem Kanal in der Databank anhand des Kanalnamens. Compare the stream to the channel in the database using the channel name
if dxc.Name == m3uChannel.Name {
channelExists = true
currentXEPGID = dxc.XEPG
break
} }
} }
@@ -1024,6 +1031,18 @@ func createM3UFile() {
// XEPG Datenbank bereinigen // XEPG Datenbank bereinigen
func cleanupXEPG() { func cleanupXEPG() {
//fmt.Println(Settings.Files.M3U)
var sourceIDs []string
for source := range Settings.Files.M3U {
sourceIDs = append(sourceIDs, source)
}
for source := range Settings.Files.HDHR {
sourceIDs = append(sourceIDs, source)
}
showInfo("XEPG:" + fmt.Sprintf("Cleanup database")) showInfo("XEPG:" + fmt.Sprintf("Cleanup database"))
Data.XEPG.XEPGCount = 0 Data.XEPG.XEPGCount = 0
@@ -1033,7 +1052,7 @@ func cleanupXEPG() {
err := json.Unmarshal([]byte(mapToJSON(dxc)), &xepgChannel) err := json.Unmarshal([]byte(mapToJSON(dxc)), &xepgChannel)
if err == nil { if err == nil {
if indexOfString(xepgChannel.Name, Data.Cache.Streams.Active) == -1 { if indexOfString(xepgChannel.Name+xepgChannel.FileM3UID, Data.Cache.Streams.Active) == -1 {
delete(Data.XEPG.Channels, id) delete(Data.XEPG.Channels, id)
} else { } else {
if xepgChannel.XActive == true { if xepgChannel.XActive == true {
@@ -1041,6 +1060,10 @@ func cleanupXEPG() {
} }
} }
if indexOfString(xepgChannel.FileM3UID, sourceIDs) == -1 {
delete(Data.XEPG.Channels, id)
}
} }
} }