|
|
@ -103,7 +103,7 @@ |
|
|
|
<script> |
|
|
|
<script> |
|
|
|
function loadStreamChoices(data) { |
|
|
|
function loadStreamChoices(data) { |
|
|
|
var selectItem = document.getElementById('streamSelection') |
|
|
|
var selectItem = document.getElementById('streamSelection') |
|
|
|
streams = data["streams"] |
|
|
|
var streams = data["streams"] |
|
|
|
for(let i in streams) { |
|
|
|
for(let i in streams) { |
|
|
|
var opt = document.createElement('option') |
|
|
|
var opt = document.createElement('option') |
|
|
|
if(data.https_streams == true) { |
|
|
|
if(data.https_streams == true) { |
|
|
@ -133,8 +133,8 @@ |
|
|
|
|
|
|
|
|
|
|
|
function buildTitleLine(width, title) { |
|
|
|
function buildTitleLine(width, title) { |
|
|
|
width = width - 2 // Subtracting 2 here to account for "|" |
|
|
|
width = width - 2 // Subtracting 2 here to account for "|" |
|
|
|
spacing = Math.floor((width - title.length)/2) |
|
|
|
var spacing = Math.floor((width - title.length)/2) |
|
|
|
line = "|" + " ".repeat(spacing) + title + " ".repeat(spacing) |
|
|
|
var line = "|" + " ".repeat(spacing) + title + " ".repeat(spacing) |
|
|
|
if(spacing + title.length + spacing != width) { |
|
|
|
if(spacing + title.length + spacing != width) { |
|
|
|
line = line + " |" // Handle title not being even |
|
|
|
line = line + " |" // Handle title not being even |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -144,10 +144,10 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getSourceInfo(data) { |
|
|
|
function getSourceInfo(data) { |
|
|
|
sources = data["icestats"]["source"] |
|
|
|
var sources = data["icestats"]["source"] |
|
|
|
for(let i in sources) { |
|
|
|
for(let i in sources) { |
|
|
|
selectedStream = document.getElementById('streamSelection').value.replace(/^.*[\\\/]/, '') |
|
|
|
var selectedStream = document.getElementById('streamSelection').value.replace(/^.*[\\\/]/, '') |
|
|
|
icecastStream = sources[i]["listenurl"].replace(/^.*[\\\/]/, '') |
|
|
|
var icecastStream = sources[i]["listenurl"].replace(/^.*[\\\/]/, '') |
|
|
|
if(selectedStream == icecastStream) { |
|
|
|
if(selectedStream == icecastStream) { |
|
|
|
sources[i]["streamurl"] = document.getElementById('streamSelection').value |
|
|
|
sources[i]["streamurl"] = document.getElementById('streamSelection').value |
|
|
|
return sources[i] |
|
|
|
return sources[i] |
|
|
@ -156,8 +156,8 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function fetchText(statusData, key) { |
|
|
|
function fetchText(statusData, key) { |
|
|
|
text = "" |
|
|
|
var text = "" |
|
|
|
streamInfo = getSourceInfo(statusData) |
|
|
|
var streamInfo = getSourceInfo(statusData) |
|
|
|
if(streamInfo && streamInfo[key]) { |
|
|
|
if(streamInfo && streamInfo[key]) { |
|
|
|
text = String(streamInfo[key]) |
|
|
|
text = String(streamInfo[key]) |
|
|
|
} |
|
|
|
} |
|
|
@ -165,54 +165,54 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function renderedLength(text) { |
|
|
|
function renderedLength(text) { |
|
|
|
regEx = /&#\d+;/g |
|
|
|
var regEx = /&#\d+;/g |
|
|
|
if (text.match(regEx) !== null) { |
|
|
|
if (text.match(regEx) !== null) { |
|
|
|
return text.match(/&#\d+;|./g).length |
|
|
|
return text.match(/&#\d+;|./g).length |
|
|
|
} |
|
|
|
} |
|
|
|
return text.length |
|
|
|
return text.length |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function trimLine(text, width) { |
|
|
|
function trimLine(line, width) { |
|
|
|
// If text has unicode char, a different trim is needed due to rendering |
|
|
|
// If line has unicode char, a different trim is needed due to rendering |
|
|
|
// unicode characters like "面" as one "character". |
|
|
|
// unicode characters like "面" as one "character". |
|
|
|
containsUnicode = text.match(/&#\d+;/) |
|
|
|
var unicodeChars = line.match(/&#\d+;/) |
|
|
|
if (containsUnicode !== null) { |
|
|
|
if (unicodeChars !== null) { |
|
|
|
chars = text.match(/&#\d+;|./g) |
|
|
|
var chars = line.match(/&#\d+;|./g) |
|
|
|
numUnicodes = text.match(/&#\d+;/g).length |
|
|
|
var numUnicodes = line.match(/&#\d+;/g).length |
|
|
|
chars.splice(-1, 1) // Remove "|" |
|
|
|
chars.splice(-1, 1) // Remove "|" |
|
|
|
text = chars.join("") |
|
|
|
var text = chars.join("") |
|
|
|
fudge = 0.69 // TODO: Fix this...non-monospaced fonts may kill me |
|
|
|
var fudge = 0.69 // TODO: Fix this...non-monospaced fonts may kill me |
|
|
|
spacing = width - renderedLength(text) - (numUnicodes * fudge) |
|
|
|
var spacing = width - renderedLength(text) - (numUnicodes * fudge) |
|
|
|
if (spacing < 0) { |
|
|
|
if (spacing < 0) { |
|
|
|
spacing = 0 |
|
|
|
spacing = 0 |
|
|
|
} |
|
|
|
} |
|
|
|
text = text + " ".repeat(spacing) + "|" |
|
|
|
return text + " ".repeat(spacing) + "|" |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (text.length > width) { |
|
|
|
if (line.length > width) { |
|
|
|
end = (width - text.length) |
|
|
|
var end = (width - line.length) |
|
|
|
start = width - 2 // Subtract 2 for " |" |
|
|
|
var start = width - 2 // Subtract 2 for " |" |
|
|
|
text = text.substring(end, start) + " |" |
|
|
|
return line.substring(end, start) + " |" |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return text |
|
|
|
return line |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function buildLine(width, text, prefix) { |
|
|
|
function buildLine(width, text, prefix) { |
|
|
|
prefix = "|" + prefix |
|
|
|
prefix = "|" + prefix |
|
|
|
|
|
|
|
|
|
|
|
// Subtract 2 for " |" |
|
|
|
// Subtract 2 for " |" |
|
|
|
spacing = (width - prefix.length - text.length - 2) |
|
|
|
var spacing = (width - prefix.length - text.length - 2) |
|
|
|
if(spacing < 0) { |
|
|
|
if(spacing < 0) { |
|
|
|
spacing = 0 |
|
|
|
spacing = 0 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
line = prefix + text + " ".repeat(spacing) + " |" |
|
|
|
var line = prefix + text + " ".repeat(spacing) + " |" |
|
|
|
|
|
|
|
|
|
|
|
return trimLine(line, width) |
|
|
|
return trimLine(line, width) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function buildDownloadLine(width, url) { |
|
|
|
function buildDownloadLine(width, url) { |
|
|
|
line = "| Download: " |
|
|
|
var line = "| Download: " |
|
|
|
if (url != "") { |
|
|
|
if (url != "") { |
|
|
|
line = line + "<a href='" + url + ".m3u" + "'>M3U</a>" |
|
|
|
line = line + "<a href='" + url + ".m3u" + "'>M3U</a>" |
|
|
|
line = line + "/" |
|
|
|
line = line + "/" |
|
|
@ -229,9 +229,9 @@ |
|
|
|
statusXMLHTTP.onreadystatechange = function() { |
|
|
|
statusXMLHTTP.onreadystatechange = function() { |
|
|
|
if (this.readyState == 4 && this.status == 200) { |
|
|
|
if (this.readyState == 4 && this.status == 200) { |
|
|
|
var streamData = JSON.parse(this.responseText); |
|
|
|
var streamData = JSON.parse(this.responseText); |
|
|
|
songName = fetchText(streamData, "title") |
|
|
|
var songName = fetchText(streamData, "title") |
|
|
|
listeners = fetchText(streamData, "listeners") |
|
|
|
var listeners = fetchText(streamData, "listeners") |
|
|
|
streamURL = fetchText(streamData, "streamurl") |
|
|
|
var streamURL = fetchText(streamData, "streamurl") |
|
|
|
renderStreamInfo(songName, listeners, streamURL) |
|
|
|
renderStreamInfo(songName, listeners, streamURL) |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
@ -240,18 +240,18 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function renderStreamInfo(songName="", listeners="", streamURL="") { |
|
|
|
function renderStreamInfo(songName="", listeners="", streamURL="") { |
|
|
|
width = 60 |
|
|
|
var width = 60 |
|
|
|
|
|
|
|
|
|
|
|
// Use an empty title while config.json is being loaded |
|
|
|
// Use an empty title while config.json is being loaded |
|
|
|
if (typeof CONFIG_DATA !== 'undefined') { |
|
|
|
if (typeof CONFIG_DATA !== 'undefined') { |
|
|
|
titleLine = buildTitleLine(width, CONFIG_DATA["title"]) |
|
|
|
var titleLine = buildTitleLine(width, CONFIG_DATA["title"]) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
titleLine = buildTitleLine(width, "") |
|
|
|
var titleLine = buildTitleLine(width, "") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
songNameLine = buildLine(width, songName, " Song Title: ") |
|
|
|
var songNameLine = buildLine(width, songName, " Song Title: ") |
|
|
|
listenersLine = buildLine(width, listeners, " Listeners: ") |
|
|
|
var listenersLine = buildLine(width, listeners, " Listeners: ") |
|
|
|
downloadLine = buildDownloadLine(width, streamURL) |
|
|
|
var downloadLine = buildDownloadLine(width, streamURL) |
|
|
|
|
|
|
|
|
|
|
|
var streamLines = [] |
|
|
|
var streamLines = [] |
|
|
|
streamLines.push("/" + "-".repeat(width - 2) + "\\") |
|
|
|
streamLines.push("/" + "-".repeat(width - 2) + "\\") |
|
|
|