Skip to content
This repository has been archived by the owner on May 8, 2022. It is now read-only.

Commit

Permalink
Implement automatic playlist to EPG mapping. Closes #16
Browse files Browse the repository at this point in the history
  • Loading branch information
SCP002 committed Apr 9, 2022
1 parent bdbbea8 commit 51869e8
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 27 deletions.
10 changes: 5 additions & 5 deletions html/js/menu_ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -1391,15 +1391,15 @@ class XMLTVFile {
//var fileIDs:string[] = getObjKeys(SERVER["xepg"]["xmltvMap"])
let values = getObjKeys(SERVER["xepg"]["xmltvMap"][file]);
let text = [];
let displayName;
let friendlyName;
for (let i = 0; i < values.length; i++) {
if (SERVER["xepg"]["xmltvMap"][file][values[i]].hasOwnProperty('display-name') == true) {
displayName = SERVER["xepg"]["xmltvMap"][file][values[i]]["display-name"];
if (SERVER["xepg"]["xmltvMap"][file][values[i]].hasOwnProperty('friendly-name') == true) {
friendlyName = SERVER["xepg"]["xmltvMap"][file][values[i]]["friendly-name"];
}
else {
displayName = "-";
friendlyName = "-";
}
text[i] = displayName + " (" + values[i] + ")";
text[i] = friendlyName + " (" + values[i] + ")";
}
text.unshift("-");
values.unshift("-");
Expand Down
6 changes: 3 additions & 3 deletions src/struct-xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ type XMLTV struct {

// Channel : Channels
type Channel struct {
ID string `xml:"id,attr"`
DisplayName []DisplayName `xml:"display-name"`
Icon Icon `xml:"icon"`
ID string `xml:"id,attr"`
DisplayNames []DisplayName `xml:"display-name"`
Icon Icon `xml:"icon"`
}

// DisplayName : Channel Name
Expand Down
2 changes: 1 addition & 1 deletion src/webUI.go

Large diffs are not rendered by default.

56 changes: 44 additions & 12 deletions src/xepg.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,12 @@ func createXEPGMapping() {

var tmpMap = make(map[string]interface{})

var friendlyDisplayName = func(channel Channel) (displayName string) {
var dn = channel.DisplayName
displayName = dn[0].Value

switch len(dn) {
var getFriendlyName = func(channel Channel) (friendlyName string) {
switch len(channel.DisplayNames) {
case 1:
displayName = dn[0].Value
friendlyName = channel.DisplayNames[0].Value
default:
displayName = fmt.Sprintf("%s (%s)", dn[1].Value, dn[0].Value)
friendlyName = fmt.Sprintf("%s (%s)", channel.DisplayNames[1].Value, channel.DisplayNames[0].Value)
}

return
Expand Down Expand Up @@ -209,7 +206,8 @@ func createXEPGMapping() {
var channel = make(map[string]interface{})

channel["id"] = c.ID
channel["display-name"] = friendlyDisplayName(*c)
channel["display-names"] = c.DisplayNames
channel["friendly-name"] = getFriendlyName(*c)
channel["icon"] = c.Icon.Src

xmltvMap[c.ID] = channel
Expand Down Expand Up @@ -240,12 +238,13 @@ func createXEPGMapping() {

for _, i := range times {

var dummyChannel = make(map[string]string)
dummyChannel["display-name"] = i + " Minutes"
var dummyChannel = make(map[string]interface{})
dummyChannel["friendly-name"] = i + " Minutes"
dummyChannel["display-names"] = []DisplayName{{Value: i + " Minutes"}}
dummyChannel["id"] = i + "_Minutes"
dummyChannel["icon"] = ""

dummy[dummyChannel["id"]] = dummyChannel
dummy[dummyChannel["id"].(string)] = dummyChannel

}

Expand Down Expand Up @@ -526,6 +525,7 @@ func mapping() (err error) {

Data.XEPG.Channels[xepg] = xepgChannel

xmltvMapLoop:
for file, xmltvChannels := range Data.XMLTV.Mapping {

if channel, ok := xmltvChannels.(map[string]interface{})[tvgID]; ok {
Expand All @@ -548,10 +548,42 @@ func mapping() (err error) {

}

} else {

// Search for the proper XEPG channel ID by comparing it's name with every alias in XML file
for _, xmltvChannel := range xmltvChannels.(map[string]interface{}) {
xmltvNames := xmltvChannel.(map[string]interface{})["display-names"].([]DisplayName)

for _, xmltvName := range xmltvNames {
xmltvNameSolid := strings.ReplaceAll(xmltvName.Value, " ", "")
xepgNameSolid := strings.ReplaceAll(xepgChannel.Name, " ", "")

if strings.EqualFold(xmltvNameSolid, xepgNameSolid) {
xepgChannel.XmltvFile = file
xepgChannel.XMapping = xmltvChannel.(map[string]interface{})["id"].(string)
// xepgChannel.XActive = true

// If there is a Logo in the XMLTV file, this will be used.
// If not, then the Logo from the M3U file.
if icon, ok := xmltvChannel.(map[string]interface{})["icon"].(string); ok {
if len(icon) > 0 {
xepgChannel.TvgLogo = icon
}
}

break xmltvMapLoop
}

}

}

}

}

Data.XEPG.Channels[xepg] = xepgChannel

}

}
Expand Down Expand Up @@ -682,7 +714,7 @@ func createXMLTVFile() (err error) {
var channel Channel
channel.ID = xepgChannel.XChannelID
channel.Icon = Icon{Src: imgc.Image.GetURL(xepgChannel.TvgLogo)}
channel.DisplayName = append(channel.DisplayName, DisplayName{Value: xepgChannel.XName})
channel.DisplayNames = append(channel.DisplayNames, DisplayName{Value: xepgChannel.XName})

xepgXML.Channel = append(xepgXML.Channel, &channel)

Expand Down
10 changes: 5 additions & 5 deletions ts/menu_ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1731,16 +1731,16 @@ class XMLTVFile {
//var fileIDs:string[] = getObjKeys(SERVER["xepg"]["xmltvMap"])
let values = getObjKeys(SERVER["xepg"]["xmltvMap"][file]);
let text = []
let displayName:string
let friendlyName:string

for (let i = 0; i < values.length; i++) {
if (SERVER["xepg"]["xmltvMap"][file][values[i]].hasOwnProperty('display-name') == true) {
displayName = SERVER["xepg"]["xmltvMap"][file][values[i]]["display-name"];
if (SERVER["xepg"]["xmltvMap"][file][values[i]].hasOwnProperty('friendly-name') == true) {
friendlyName = SERVER["xepg"]["xmltvMap"][file][values[i]]["friendly-name"];
} else {
displayName = "-"
friendlyName = "-"
}

text[i] = displayName + " (" + values[i] + ")";
text[i] = friendlyName + " (" + values[i] + ")";
}

text.unshift("-");
Expand Down
2 changes: 1 addition & 1 deletion xteve.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var GitHub = GitHubStruct{Branch: "master", User: "SCP002", Repo: "xTeVe", Updat
const Name = "xTeVe"

// Version : Version, the Build Number is parsed in the main func
const Version = "2.2.4.0000"
const Version = "2.2.5.0000"

// DBVersion : Database Version
const DBVersion = "2.2.0"
Expand Down

0 comments on commit 51869e8

Please sign in to comment.