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

Commit

Permalink
Add updating of channel by name based on regex. Closes #38
Browse files Browse the repository at this point in the history
  • Loading branch information
SCP002 committed May 1, 2022
1 parent d4be1ce commit d29330c
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 59 deletions.
3 changes: 2 additions & 1 deletion html/css/screen.css
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ tbody {
width: 100%;
z-index: 100;
height: 100%;
overflow: scroll;
}

#mapping-detail, #user-detail, #file-detail, #popup-custom {
Expand All @@ -364,7 +365,7 @@ tbody {
margin-left: auto;
margin-right: auto;

max-width: 600px;
max-width: 800px;
background-color: #222;
padding: 10px;
overflow:auto;
Expand Down
2 changes: 1 addition & 1 deletion html/js/base_ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ function createSearchObj() {
SEARCH_MAPPING = new Object();
var data = SERVER["xepg"]["epgMapping"];
var channels = getOwnObjProps(data);
var channelKeys = ["x-active", "x-channelID", "x-name", "_file.m3u.name", "x-group-title", "x-xmltv-file"];
var channelKeys = ["x-active", "x-channelID", "x-name", "updateChannelNameRegex", "_file.m3u.name", "x-group-title", "x-xmltv-file"];
channels.forEach(id => {
channelKeys.forEach(key => {
if (key == "x-active") {
Expand Down
48 changes: 39 additions & 9 deletions html/js/menu_ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class MainMenuItem extends MainMenu {
this.tableHeader = ["{{.users.table.username}}", "{{.users.table.password}}", "{{.users.table.web}}", "{{.users.table.pms}}", "{{.users.table.m3u}}", "{{.users.table.xml}}", "{{.users.table.api}}"];
break;
case "mapping":
this.tableHeader = ["BULK", "{{.mapping.table.chNo}}", "{{.mapping.table.logo}}", "{{.mapping.table.channelName}}", "{{.mapping.table.playlist}}", "{{.mapping.table.groupTitle}}", "{{.mapping.table.xmltvFile}}", "{{.mapping.table.xmltvID}}", "{{.mapping.table.timeshift}}"];
this.tableHeader = ["BULK", "{{.mapping.table.chNo}}", "{{.mapping.table.logo}}", "{{.mapping.table.channelName}}", "{{.mapping.table.updateChannelNameRegex}}", "{{.mapping.table.playlist}}", "{{.mapping.table.groupTitle}}", "{{.mapping.table.xmltvFile}}", "{{.mapping.table.xmltvID}}", "{{.mapping.table.timeshift}}"];
break;
}
}
Expand Down Expand Up @@ -354,6 +354,15 @@ class Content {
td.setAttribute('onclick', 'javascript: openPopUp("mapping", this)');
td.id = key;
tr.appendChild(td);
// Update channel name regex
var cell = new Cell();
cell.child = true;
cell.childType = "P";
cell.value = data[key]["update-channel-name-regex"];
var td = cell.createCell();
td.setAttribute('onclick', 'javascript: openPopUp("mapping", this)');
td.id = key;
tr.appendChild(td);
// Playlist
var cell = new Cell();
cell.child = true;
Expand Down Expand Up @@ -614,17 +623,21 @@ class ShowContent extends Content {
cell.onclick = true;
cell.onclickFunction = "javascript: sortTable(3);";
}
if (element == "{{.mapping.table.playlist}}") {
if (element == "{{.mapping.table.updateChannelNameRegex}}") {
cell.onclick = true;
cell.onclickFunction = "javascript: sortTable(4);";
}
if (element == "{{.mapping.table.groupTitle}}") {
if (element == "{{.mapping.table.playlist}}") {
cell.onclick = true;
cell.onclickFunction = "javascript: sortTable(5);";
}
if (element == "{{.mapping.table.groupTitle}}") {
cell.onclick = true;
cell.onclickFunction = "javascript: sortTable(6);";
}
if (element == "{{.mapping.table.timeshift}}") {
cell.onclick = true;
cell.onclickFunction = "javascript: sortTable(8);";
cell.onclickFunction = "javascript: sortTable(9);";
}
}
if (menuKey == "filter") {
Expand Down Expand Up @@ -1292,7 +1305,7 @@ function openPopUp(dataType, element) {
input.setAttribute("placeholder", "{{.mapping.description.placeholder}}");
input.setAttribute("onchange", "javascript: this.className = 'changed'");
content.appendRow("{{.mapping.description.title}}", input);
// Update the channel name
// Update the channel x-name
if (data.hasOwnProperty("_uuid.key")) {
if (data["_uuid.key"] != "") {
var dbKey = "x-update-channel-name";
Expand All @@ -1302,6 +1315,20 @@ function openPopUp(dataType, element) {
content.appendRow("{{.mapping.updateChannelName.title}}", input);
}
}
// Channel name regex for updating the channel name
var dbKey = "update-channel-name-regex";
var input = content.createInput("text", dbKey, data[dbKey]);
input.setAttribute("placeholder", "{{.mapping.updateChannelNameRegex.placeholder}}");
input.setAttribute("onchange", "javascript: this.className = 'changed'");
content.appendRow("{{.mapping.updateChannelNameRegex.title}}", input);
content.description("{{.mapping.updateChannelNameRegex.description}}");
// Channel group regex for updating the channel name
var dbKey = "update-channel-name-by-group-regex";
var input = content.createInput("text", dbKey, data[dbKey]);
input.setAttribute("placeholder", "{{.mapping.updateChannelNameByGroupRegex.placeholder}}");
input.setAttribute("onchange", "javascript: this.className = 'changed'");
content.appendRow("{{.mapping.updateChannelNameByGroupRegex.title}}", input);
content.description("{{.mapping.updateChannelNameByGroupRegex.description}}");
// Logo URL (Channel)
var dbKey = "tvg-logo";
var input = content.createInput("text", dbKey, data[dbKey]);
Expand Down Expand Up @@ -1735,8 +1762,11 @@ function donePopupData(dataType, idsStr) {
case "x-category":
document.getElementById(id).childNodes[3].firstChild.className = value;
break;
case "update-channel-name-regex":
document.getElementById(id).childNodes[4].firstChild.innerHTML = value;
break;
case "x-group-title":
document.getElementById(id).childNodes[5].firstChild.innerHTML = value;
document.getElementById(id).childNodes[6].firstChild.innerHTML = value;
break;
case "x-xmltv-file":
if (value != "xTeVe Dummy" && value != "-") {
Expand All @@ -1745,16 +1775,16 @@ function donePopupData(dataType, idsStr) {
if (value == "-") {
input["x-active"] = false;
}
document.getElementById(id).childNodes[6].firstChild.innerHTML = value;
document.getElementById(id).childNodes[7].firstChild.innerHTML = value;
break;
case "x-mapping":
if (value == "-") {
input["x-active"] = false;
}
document.getElementById(id).childNodes[7].firstChild.innerHTML = value;
document.getElementById(id).childNodes[8].firstChild.innerHTML = value;
break;
case "x-timeshift":
document.getElementById(id).childNodes[8].firstChild.innerHTML = value;
document.getElementById(id).childNodes[9].firstChild.innerHTML = value;
break;
default:
}
Expand Down
13 changes: 13 additions & 0 deletions html/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
"chNo": "Ch. No.",
"logo": "Logo",
"channelName": "Channel Name",
"updateChannelNameRegex": "Upd. Rx.",
"playlist": "Playlist",
"groupTitle": "Group Title",
"xmltvFile": "XMLTV File",
Expand Down Expand Up @@ -256,6 +257,18 @@
"placeholder": "",
"description": ""
},
"updateChannelNameRegex":
{
"title": "Channel name update regex",
"placeholder": "For example ^PPV.?1.*",
"description": "On update, if any new channel name matches this regex, rename current channel to the first matching name"
},
"updateChannelNameByGroupRegex":
{
"title": "Only by group regex",
"placeholder": "",
"description": "Rename this channel only if current user-defined group matches this regex"
},
"updateChannelGroup":
{
"title": "Update Channel Group",
Expand Down
2 changes: 2 additions & 0 deletions src/screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ func getErrMsg(errCode int) (errMsg string) {
errMsg = fmt.Sprintf("Web server could not be stopped.")
case 1017:
errMsg = fmt.Sprintf("Web server could not be started in TLS mode, fallback to default.")
case 1018:
errMsg = fmt.Sprintf("Failed to compile channel name update regex")

case 1020:
errMsg = fmt.Sprintf("Data could not be saved, invalid keyword")
Expand Down
56 changes: 29 additions & 27 deletions src/struct-system.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,33 +183,35 @@ type Filter struct {

// XEPGChannelStruct : XEPG Structure
type XEPGChannelStruct struct {
FileM3UID string `json:"_file.m3u.id,required"`
FileM3UName string `json:"_file.m3u.name,required"`
FileM3UPath string `json:"_file.m3u.path,required"`
GroupTitle string `json:"group-title,required"`
Name string `json:"name,required"`
TvgID string `json:"tvg-id,required"`
TvgLogo string `json:"tvg-logo,required"`
TvgName string `json:"tvg-name,required"`
TvgShift string `json:"tvg-shift,required"`
URL string `json:"url,required"`
UUIDKey string `json:"_uuid.key,required"`
UUIDValue string `json:"_uuid.value,omitempty"`
Values string `json:"_values,required"`
XActive bool `json:"x-active,required"`
XCategory string `json:"x-category,required"`
XChannelID string `json:"x-channelID,required"`
XEPG string `json:"x-epg,required"`
XGroupTitle string `json:"x-group-title,required"`
XMapping string `json:"x-mapping,required"`
XmltvFile string `json:"x-xmltv-file,required"`
XName string `json:"x-name,required"`
XUpdateChannelIcon bool `json:"x-update-channel-icon,required"`
XUpdateChannelName bool `json:"x-update-channel-name,required"`
XUpdateChannelGroup bool `json:"x-update-channel-group,required"`
XDescription string `json:"x-description,required"`
XTimeshift string `json:"x-timeshift,required"`
DefaultMissingEPG string `json:"x-default-missing-epg,required"`
FileM3UID string `json:"_file.m3u.id,required"`
FileM3UName string `json:"_file.m3u.name,required"`
FileM3UPath string `json:"_file.m3u.path,required"`
GroupTitle string `json:"group-title,required"`
Name string `json:"name,required"`
TvgID string `json:"tvg-id,required"`
TvgLogo string `json:"tvg-logo,required"`
TvgName string `json:"tvg-name,required"`
TvgShift string `json:"tvg-shift,required"`
UpdateChannelNameRegex string `json:"update-channel-name-regex,required"`
UpdateChannelNameByGroupRegex string `json:"update-channel-name-by-group-regex,required"`
URL string `json:"url,required"`
UUIDKey string `json:"_uuid.key,required"`
UUIDValue string `json:"_uuid.value,omitempty"`
Values string `json:"_values,required"`
XActive bool `json:"x-active,required"`
XCategory string `json:"x-category,required"`
XChannelID string `json:"x-channelID,required"`
XEPG string `json:"x-epg,required"`
XGroupTitle string `json:"x-group-title,required"`
XMapping string `json:"x-mapping,required"`
XmltvFile string `json:"x-xmltv-file,required"`
XName string `json:"x-name,required"`
XUpdateChannelIcon bool `json:"x-update-channel-icon,required"`
XUpdateChannelName bool `json:"x-update-channel-name,required"`
XUpdateChannelGroup bool `json:"x-update-channel-group,required"`
XDescription string `json:"x-description,required"`
XTimeshift string `json:"x-timeshift,required"`
DefaultMissingEPG string `json:"x-default-missing-epg,required"`
}

// M3UChannelStructXEPG : M3U Structure for XEPG
Expand Down
Loading

0 comments on commit d29330c

Please sign in to comment.