Compare commits

..

5 Commits

  1. 3
      Dockerfile
  2. 2
      entrypoint.sh
  3. 80
      player.html

@ -2,8 +2,9 @@ FROM alpine:latest
LABEL maintainer "jerryaldrichiii@gmail.com" LABEL maintainer "jerryaldrichiii@gmail.com"
# https://pkgs.alpinelinux.org/packages?name=icecast&branch=edge&repo=&arch=&maintainer=
RUN apk add --update \ RUN apk add --update \
icecast \ icecast=2.4.4-r7 \
mailcap \ mailcap \
jq \ jq \
&& rm -rf /var/cache/apk/* && rm -rf /var/cache/apk/*

@ -28,7 +28,7 @@ set_val fileserve ${ICECAST_FILESERVE:-1}
set_val source-password ${AUTHENTICATION_SOURCE_PASSWORD:-changeorbehacked} set_val source-password ${AUTHENTICATION_SOURCE_PASSWORD:-changeorbehacked}
set_val relay-password ${AUTHENTICATION_RELAY_PASSWORD:-changeorbehacked} set_val relay-password ${AUTHENTICATION_RELAY_PASSWORD:-changeorbehacked}
set_val admin-user ${AUTHENTICATION_ADMIN_USER:-changeorbehacked} set_val admin-user ${AUTHENTICATION_ADMIN_USERNAME:-changeorbehacked}
set_val admin-password ${AUTHENTICATION_ADMIN_PASSWORD:-changeorbehacked} set_val admin-password ${AUTHENTICATION_ADMIN_PASSWORD:-changeorbehacked}
set_val relays-on-demand ${RELAYS_ON_DEMAND:-1} set_val relays-on-demand ${RELAYS_ON_DEMAND:-1}

@ -89,7 +89,7 @@
<pre id="stream-info"></pre> <pre id="stream-info"></pre>
<div id="controls"> <div id="controls">
<select id="streamSelection"> <select id="streamSelection">
<option value="" disabled selected style="display:none;">Select a Stream</option> <option value="" disabled selected style="display:none;">Select a Station</option>
</select> </select>
<button id="playButton">Play</button> <button id="playButton">Play</button>
<div id="volume-container"> <div id="volume-container">
@ -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 "&#38754;" as one "character". // unicode characters like "&#38754;" 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,26 +240,26 @@
} }
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) + "\\")
streamLines.push(titleLine) streamLines.push(titleLine)
if (songName == "" && listeners == "" && streamURL != "") { if (songName == "" && listeners == "" && streamURL != "") {
songNameLine = buildLine(width, "Loading...", " Song Title: ") songNameLine = buildLine(width, "Fetching...", " Song Title: ")
listenersLine = buildLine(width, "Loading...", " Listeners: ") listenersLine = buildLine(width, "Fetching...", " Listeners: ")
streamLines.push("|" + " ".repeat(width - 2) + "|") streamLines.push("|" + " ".repeat(width - 2) + "|")
streamLines.push(songNameLine) streamLines.push(songNameLine)
@ -273,7 +273,7 @@
if (songName == "" && listeners != "") { if (songName == "" && listeners != "") {
streamLines.push("|" + " ".repeat(width - 2) + "|") streamLines.push("|" + " ".repeat(width - 2) + "|")
songNameLine = buildLine(width, "Loading...", " Song Title: ") songNameLine = buildLine(width, "Fetching...", " Song Title: ")
streamLines.push(songNameLine) streamLines.push(songNameLine)
streamLines.push(listenersLine) streamLines.push(listenersLine)
} else if (listeners != "") { } else if (listeners != "") {

Loading…
Cancel
Save