You've already forked RadioPlayer
mirror of
https://github.com/radio95-rnt/RadioPlayer.git
synced 2026-02-26 21:53:54 +01:00
485 lines
25 KiB
HTML
485 lines
25 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
<title>Radio95 Track Monitor</title>
|
|
<style>
|
|
:root{
|
|
--bg:#0f1620; --panel:#11161c; --muted:#98a0a8; --accent:#3ea6ff; --card:#0b1014;
|
|
--success:#47d18b; --danger:#ff6b6b; --glass: rgba(255,255,255,0.03);
|
|
font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
|
|
}
|
|
html,body{height:100%; margin:0; background:linear-gradient(180deg,#071018,#0b1220 60%); color:#e6eef6; overflow: hidden;}
|
|
.container{max-width:1400px; margin:18px auto; padding:18px; display:flex; flex-direction:column; gap:12px}
|
|
h1{margin:0; font-size:22px; font-weight:700}
|
|
.layout{display:flex; gap:14px; height:calc(100vh - 140px);}
|
|
.panel{background:var(--panel); border-radius:10px; padding:12px; box-shadow: 0 6px 18px rgba(2,8,16,0.6); display:flex; flex-direction:column; overflow:hidden}
|
|
.left{flex:1.2; min-width:420px}
|
|
.right{flex:1; display:flex; flex-direction:column; gap:12px}
|
|
.frame-title{font-size:16px; color:var(--muted); margin-bottom:8px}
|
|
.now, .next {margin-bottom:12px}
|
|
.now .track, .next .track {font-weight:600; font-size:14px; word-break:break-all}
|
|
.progress-wrap{display:flex; gap:10px; align-items:center}
|
|
.progress-bar{flex:1; height:9px; background:var(--glass); border-radius:8px; overflow:hidden; position:relative}
|
|
.progress-fill{height:100%; width:0%; background:linear-gradient(90deg,var(--accent), #6cc7ff); transition:width 0.2s linear}
|
|
button, .btn{background:transparent;border:1px solid rgba(255,255,255,0.06); padding:8px 12px;border-radius:8px;color:inherit;cursor:pointer; transition: background-color 0.12s ease}
|
|
button:hover, .btn:hover {background-color: var(--glass);}
|
|
.btn.activated { background:linear-gradient(90deg, #9ed3ff46, #5bbbff2a); }
|
|
.btn.primary{background:linear-gradient(90deg,var(--accent), #6cc7ff); color:#001; border:none; font-weight:600}
|
|
.btn.primary:hover { background:linear-gradient(90deg, #3399ee, #5bbaff); }
|
|
.list{background:#07121a; border-radius:8px; padding:8px; overflow:auto; border:1px solid rgba(255,255,255,0.02)}
|
|
ul.playlist{list-style:none; padding:6px; margin:0; font-family: "Consolas",monospace; font-size:13px;}
|
|
ul.playlist li{padding:6px 8px; border-radius:6px; display:flex; justify-content:space-between; gap:8px; transition: background-color 0.12s ease;}
|
|
ul.playlist li:hover{background:rgba(255,255,255,0.02)}
|
|
ul.playlist li.current{background:rgba(62,166,255,0.08)}
|
|
ul.playlist li.selected{background:rgba(62, 165, 255, 0.305)}
|
|
ul.playlist li.pointer{background:rgba(255,255,255,0.04)}
|
|
.controls{display:flex; gap:8px; margin-top:8px}
|
|
.two-col{display:flex; gap:8px; align-items:flex-start; height:100%}
|
|
.box{display:flex; flex-direction:column; gap:8px; flex-grow: 1; overflow: hidden;}
|
|
.listbox{height:100%; min-height:220px; overflow:auto; border-radius:6px; background:var(--card); padding:8px; font-size:14px; scrollbar-width: none;}
|
|
.listbox div.item{padding:6px; border-radius:6px; transition: background-color 0.12s ease;}
|
|
.listbox div.item:hover{background:rgba(255,255,255,0.02); cursor:pointer}
|
|
.listbox div.item.selected{background:rgba(62, 165, 255, 0.305)}
|
|
.small{font-size:12px; color:var(--muted)}
|
|
.row{display:flex; gap:8px; align-items:center}
|
|
.muted{color:var(--muted); font-size:13px}
|
|
.footer{display:flex; justify-content:space-between; gap:8px; align-items:center; margin-top:8px}
|
|
.directory-grid{display:grid; grid-template-columns:1fr 1fr; gap:12px; flex-grow:1; overflow:hidden}
|
|
#keybinds {display: flex; gap: 10px; align-items: center; white-space: nowrap; }
|
|
#keybinds kbd {background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.12); border-radius: 4px; padding: 2px 6px; font-family: "Consolas", monospace; font-size: 12px; color: #e6eef6; }
|
|
@media (max-width:800px){
|
|
html, body{overflow: auto; height: auto}
|
|
.container{padding: 10px; margin: 0}
|
|
.layout{flex-direction: column; height: auto}
|
|
.left{min-width:auto}
|
|
.directory-grid {grid-template-columns: 1fr}
|
|
.listbox {min-height: 250px}
|
|
button, .btn {padding: 10px 14px}
|
|
#playlist-box {display: none;}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div style="display:flex;align-items:center;justify-content:space-between">
|
|
<h1>RadioPlayer status</h1>
|
|
</div>
|
|
|
|
<div class="layout">
|
|
<div class="panel left">
|
|
<div class="now">
|
|
<div class="frame-title">Now Playing</div>
|
|
<div class="track" id="now-track">Loading...</div>
|
|
<div class="progress-wrap" style="margin-top:8px">
|
|
<div class="progress-bar" title="progress"><div class="progress-fill" id="prog-fill"></div></div>
|
|
<div class="small" id="time-label">00:00 / 00:00 (00:00)</div>
|
|
</div>
|
|
<div class="controls" style="margin-top:10px">
|
|
<button id="skip-btn" class="btn">⏭ Skip Track</button>
|
|
<button id="readd-btn" class="btn">↺ Re-add Selected</button>
|
|
<button id="clear-btn" class="btn">✖ Clear the Queue</button>
|
|
<button id="skpn-btn" class="btn">⏭? Toggle skip next</button>
|
|
<button id="jingle-btn" class="btn">🕭 Add Jingle</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="next" style="margin-top:12px">
|
|
<div class="frame-title">Next Track</div>
|
|
<div class="track" id="next-track">Loading...</div>
|
|
</div>
|
|
|
|
<div style="margin-top:12px; display:flex; flex-direction: column; flex-grow: 1; overflow: hidden;">
|
|
<div class="box" style="flex-grow: 1;">
|
|
<div class="frame-title">Playlist Queue</div>
|
|
<div class="list listbox" id="playlist-box">
|
|
<ul class="playlist" id="playlist-ul"></ul>
|
|
</div>
|
|
</div>
|
|
<div class="box" style="margin-top: 12px; flex-shrink: 0;">
|
|
<div class="frame-title">Queue</div>
|
|
<div class="list listbox" id="queue-box" style="min-height: 80px; max-height: 200px;">
|
|
<ul class="playlist" id="queue-ul"></ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="panel right">
|
|
<div class="directory-grid">
|
|
<div class="box" style="padding:8px">
|
|
<div class="frame-title">Directory Browser</div>
|
|
<div class="listbox" id="dirs-box"></div>
|
|
</div>
|
|
|
|
<div class="box" style="padding:8px">
|
|
<div class="frame-title">Subdirectory Files</div>
|
|
<div class="listbox" id="subdir-box"></div>
|
|
</div>
|
|
</div>
|
|
<div style="margin-top:8px">
|
|
<button id="add-to-queue-btn" class="btn primary" style="width:100%">Add Selected File to Queue</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="footer">
|
|
<div class="muted">
|
|
Server: <span id="server-status">connecting...</span>
|
|
</div>
|
|
<div class="muted small" id="keybinds">
|
|
<b>Keys:</b>
|
|
<span><kbd>S</kbd> skip</span>
|
|
<span><kbd>N</kbd> skip next</span>
|
|
<span><kbd>J</kbd> jingle</span>
|
|
<span><kbd>ENTER</kbd> add file</span>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
|
|
let ws = null;
|
|
let reconnectDelay = 1000;
|
|
let playlist = [];
|
|
let Queue = [];
|
|
let currentTrackPath = "";
|
|
let currentTrackIndex = 0;
|
|
let selectedPlaylistIndex = null;
|
|
let selectedDir = null;
|
|
let selectedSubFile = null;
|
|
let basePath = "";
|
|
let subbasePath = "";
|
|
let skipNext = false;
|
|
|
|
function connectWs(){
|
|
document.getElementById("server-status").textContent = "connecting...";
|
|
ws = new WebSocket("ws://192.168.1.93:3001");
|
|
|
|
ws.addEventListener("open", () => {
|
|
document.getElementById("server-status").textContent = "connected";
|
|
reconnectDelay = 1000;
|
|
ws.send(JSON.stringify({action:"get_toplay"}));
|
|
ws.send(JSON.stringify({action:"skip_next",set:false}));
|
|
});
|
|
|
|
ws.addEventListener("close", () => {
|
|
document.getElementById("server-status").textContent = "disconnected — reconnecting...";
|
|
setTimeout(connectWs, reconnectDelay);
|
|
reconnectDelay = Math.min(10000, reconnectDelay + 1000);
|
|
});
|
|
|
|
ws.addEventListener("error", (e) => {
|
|
console.warn("WS error", e);
|
|
document.getElementById("server-status").textContent = "error";
|
|
});
|
|
|
|
ws.addEventListener("message", (evt) => {
|
|
try {
|
|
handleMessage(JSON.parse(evt.data));
|
|
} catch (e) {
|
|
console.warn("Bad msg", evt.data, e);
|
|
}
|
|
});
|
|
}
|
|
|
|
function handleMessage(msg){
|
|
if(msg.event === "state"){
|
|
const d = msg.data || {};
|
|
applyProgressState(d.track);
|
|
updateDirs(d.dirs);
|
|
if(d.playlist) { playlist = d.playlist; renderPlaylist(); }
|
|
} else if(msg.event === "playlist"){
|
|
playlist = msg.data || [];
|
|
renderPlaylist();
|
|
} else if(msg.event === "new_track"){
|
|
applyTrackState(msg.data);
|
|
ws.send(JSON.stringify({action:"get_toplay"}));
|
|
ws.send(JSON.stringify({action:"skip_next",set:false}));
|
|
} else if(msg.event === "progress"){
|
|
applyProgressState(msg.data);
|
|
} else if(msg.event === "toplay") {
|
|
Queue = msg.data.data || [];
|
|
renderQueue();
|
|
} else if(msg.event === "request_dir") {
|
|
applySubdir(msg.data || {})
|
|
} else if(msg.event === "skip_next") {
|
|
skipNext = msg.data?.data === true;
|
|
if(!skipNext && document.getElementById("skpn-btn").classList.contains("activated")) document.getElementById("skpn-btn").classList.remove("activated")
|
|
else if(skipNext) document.getElementById("skpn-btn").classList.add("activated")
|
|
renderPlaylist();
|
|
renderQueue();
|
|
} else if(msg.status || msg.response || msg.error) {
|
|
console.debug("ws ack", msg);
|
|
}
|
|
}
|
|
|
|
function applyTrackState(payload){
|
|
const track = payload.track || {};
|
|
const next = payload.next_track || {};
|
|
currentTrackPath = (track.official ? "" : "!") + (track.path||"<none>");
|
|
currentTrackIndex = payload.index;
|
|
document.getElementById("now-track").textContent = `${track.official ? "(official) " : "(unofficial)"}${track.path||"<none>"}`;
|
|
document.getElementById("next-track").textContent = `${next.official ? "(official) " : "(unofficial)"}${next.path||"<none>"}`;
|
|
renderPlaylist();
|
|
}
|
|
|
|
function applyProgressState(payload){
|
|
const track = payload.track || {};
|
|
const next_track = payload.next_track || {};
|
|
const elapsed = Number(payload.elapsed || 0);
|
|
const total = Number(payload.total || payload.real_total || 1) || 1;
|
|
const realtotal = Number(payload.real_total || payload.total || 1) || 1;
|
|
const percent = Math.max(0, Math.min(100, (elapsed/realtotal)*100));
|
|
document.getElementById("prog-fill").style.width = percent + "%";
|
|
document.getElementById("time-label").textContent = formatTime(elapsed) + " / " + formatTime(total) + ` (${formatTime(total-elapsed)})`;
|
|
currentTrackIndex = payload.index;
|
|
|
|
if(track.path){
|
|
currentTrackPath = (track.official ? "" : "!") + track.path;
|
|
document.getElementById("now-track").textContent = `${track.official ? "(official) " : ""}${track.path}`;
|
|
}
|
|
if(next_track.path){
|
|
document.getElementById("next-track").textContent = `${next_track.official ? "(official) " : ""}${next_track.path}`;
|
|
}
|
|
}
|
|
|
|
function applySubdir(payload) {
|
|
if(payload.dir !== selectedDir) return;
|
|
|
|
const dirsBox = document.getElementById("subdir-box");
|
|
dirsBox.innerHTML = "Loading...";
|
|
try {
|
|
subbasePath = payload.base || "";
|
|
const files = payload.files || [];
|
|
dirsBox.innerHTML = "";
|
|
files.sort().forEach(f => {
|
|
const node = document.createElement("div");
|
|
node.className = "item";
|
|
node.textContent = f;
|
|
node.addEventListener("click", () => {
|
|
if(node.classList.contains("selected")) {
|
|
node.classList.remove("selected");
|
|
selectedSubFile = null;
|
|
return;
|
|
}
|
|
Array.from(dirsBox.children).forEach(c=>c.classList.remove("selected"));
|
|
node.classList.add("selected"); selectedSubFile = f;
|
|
});
|
|
dirsBox.appendChild(node);
|
|
});
|
|
} catch(e) {
|
|
dirsBox.innerHTML = "Error fetching dirs: "+e.message;
|
|
}
|
|
}
|
|
|
|
function formatTime(s){
|
|
s = Number(s||0);
|
|
const h = Math.floor(s/3600), m = Math.floor((s%3600)/60), sec = Math.floor(s%60);
|
|
if(h != 0) return [h,m,sec].map(x => String(x).padStart(2,'0')).join(":");
|
|
else return [m,sec].map(x => String(x).padStart(2,'0')).join(":");
|
|
}
|
|
|
|
function renderPlaylist(){
|
|
const ul = document.getElementById("playlist-ul");
|
|
ul.innerHTML = "";
|
|
let currentIndex = null;
|
|
|
|
playlist.forEach((t, i) => {
|
|
const li = document.createElement("li");
|
|
const idx = i+1;
|
|
const path = t.path || "<no path>";
|
|
const official = t.official || false;
|
|
const displayPath = (official ? "" : "!") + path;
|
|
li.dataset.path = path;
|
|
li.dataset.idx = i;
|
|
li.addEventListener("click", () => { selectPlaylistItem(i, li); });
|
|
|
|
const p = li.dataset.path;
|
|
const currentPath = currentTrackPath.replace(/^!/, "");
|
|
if (p === currentPath && i === currentTrackIndex) {
|
|
li.classList.add("current");
|
|
currentIndex = i;
|
|
}
|
|
else if (i === currentTrackIndex) {
|
|
li.classList.add("pointer");
|
|
currentIndex = i - 1;
|
|
}
|
|
if(currentIndex !== null && (currentIndex+1 === i) && skipNext && Queue.length === 0) li.style.textDecoration = "line-through";
|
|
|
|
li.textContent = ` ${String(idx).padStart(2,'0')}: `;
|
|
li.textContent = li.textContent + (i === currentTrackIndex ? "▶ " : " ") + displayPath;
|
|
ul.appendChild(li);
|
|
});
|
|
|
|
if(currentIndex !== null){
|
|
const el = ul.children[currentIndex];
|
|
if(el) el.scrollIntoView({block:'center', behavior: 'smooth'});
|
|
}
|
|
updateControls();
|
|
}
|
|
|
|
function renderQueue() {
|
|
const ul = document.getElementById("queue-ul");
|
|
ul.innerHTML = "";
|
|
Queue.forEach((element, i) => {
|
|
const li = document.createElement("li");
|
|
li.textContent = element;
|
|
if(i === 0 && skipNext) li.style.textDecoration = "line-through";
|
|
ul.appendChild(li);
|
|
});
|
|
updateControls()
|
|
}
|
|
|
|
function selectPlaylistItem(i, el){
|
|
if(el.classList.contains("selected")) {
|
|
el.classList.remove("selected");
|
|
selectedPlaylistIndex = null;
|
|
return;
|
|
}
|
|
const ul = document.getElementById("playlist-ul");
|
|
Array.from(ul.children).forEach(c => c.classList.remove("selected"));
|
|
Array.from(document.getElementById("dirs-box").children).forEach(c => c.classList.remove("selected"));
|
|
el.classList.add("selected");
|
|
selectedPlaylistIndex = i;
|
|
updateControls()
|
|
}
|
|
|
|
async function updateDirs(payload){
|
|
const dirsBox = document.getElementById("dirs-box");
|
|
dirsBox.innerHTML = "Loading...";
|
|
try {
|
|
basePath = payload.base || "";
|
|
const files = payload.files || [];
|
|
const dirs = payload.dirs || [];
|
|
dirsBox.innerHTML = "";
|
|
dirs.sort().forEach(f => {
|
|
const node = document.createElement("div");
|
|
node.className = "item";
|
|
node.textContent = f;
|
|
node.addEventListener("click", () => onDirClicked(f, node));
|
|
dirsBox.appendChild(node);
|
|
});
|
|
files.sort().forEach(f => {
|
|
const node = document.createElement("div");
|
|
node.className = "item";
|
|
node.textContent = f;
|
|
node.addEventListener("click", () => {
|
|
if(node.classList.contains("selected")) {
|
|
node.classList.remove("selected");
|
|
selectedDir = null;
|
|
selectedSubFile = null;
|
|
return;
|
|
}
|
|
Array.from(dirsBox.children).forEach(c=>c.classList.remove("selected"));
|
|
Array.from(document.getElementById("playlist-ul").children).forEach(c => c.classList.remove("selected"));
|
|
node.classList.add("selected");
|
|
selectedDir = null;
|
|
selectedSubFile = null;
|
|
document.getElementById("subdir-box").innerHTML = "";
|
|
});
|
|
node.dataset.type = "file";
|
|
dirsBox.appendChild(node);
|
|
});
|
|
} catch(e) {
|
|
dirsBox.innerHTML = "Error fetching dirs: "+e.message;
|
|
}
|
|
}
|
|
|
|
function onDirClicked(name, node){
|
|
if(node.classList.contains("selected")) {
|
|
node.classList.remove("selected");
|
|
selectedDir = null;
|
|
selectedSubFile = null;
|
|
document.getElementById("subdir-box").innerHTML = "";
|
|
return;
|
|
}
|
|
Array.from(document.getElementById("dirs-box").children).forEach(c => c.classList.remove("selected"));
|
|
Array.from(document.getElementById("playlist-ul").children).forEach(c => c.classList.remove("selected"));
|
|
node.classList.add("selected");
|
|
selectedDir = name;
|
|
selectedSubFile = null;
|
|
ws.send(JSON.stringify({action:"request_dir", what: selectedDir}))
|
|
}
|
|
|
|
document.getElementById("skip-btn").addEventListener("click", () => {
|
|
if(ws && ws.readyState === WebSocket.OPEN) ws.send(JSON.stringify({action:"skip"}));
|
|
else console.error("WebSocket not connected.");
|
|
});
|
|
document.getElementById("skpn-btn").addEventListener("click", () => {
|
|
if(ws && ws.readyState === WebSocket.OPEN) ws.send(JSON.stringify({action:"skip_next"}));
|
|
else console.error("WebSocket not connected.");
|
|
});
|
|
document.getElementById("jingle-btn").addEventListener("click", () => {
|
|
if(ws && ws.readyState === WebSocket.OPEN) ws.send(JSON.stringify({action:"jingle"}));
|
|
else console.error("WebSocket not connected.");
|
|
});
|
|
|
|
document.getElementById("readd-btn").addEventListener("click", () => {
|
|
if(selectedPlaylistIndex == null){
|
|
alert("Select a playlist item to re-add.");
|
|
return;
|
|
}
|
|
const selected = playlist[selectedPlaylistIndex];
|
|
if(!selected) { alert("Invalid selection"); return; }
|
|
const path = (selected.official ? "" : "!") + selected.path;
|
|
ws.send(JSON.stringify({action:"add_to_toplay", songs: [path]}))
|
|
Array.from(document.getElementById("playlist-ul").children).forEach(c => c.classList.remove("selected"));
|
|
selectedPlaylistIndex = null;
|
|
});
|
|
document.getElementById("clear-btn").addEventListener("click", () => {ws.send(JSON.stringify({action:"clear_toplay"}))});
|
|
|
|
function addSelectedFileToQueue() {
|
|
let fullPath = null;
|
|
|
|
// Priority 1: selected subdirectory file
|
|
if (selectedSubFile && selectedDir) {
|
|
fullPath = subbasePath.replace(/\/$/, '') + '/' + selectedSubFile;
|
|
Array.from(document.getElementById("subdir-box").children).forEach(c => c.classList.remove("selected"));
|
|
selectedSubFile = null;
|
|
}
|
|
// Priority 2: selected main directory file
|
|
else {
|
|
const dirEls = document.getElementById("dirs-box").children;
|
|
const selectedItem = Array.from(dirEls).find(el => el.classList.contains("selected"));
|
|
|
|
if (selectedItem && selectedItem.dataset.type === "file") {
|
|
fullPath = basePath.replace(/\/$/, '') + '/' + selectedItem.textContent;
|
|
Array.from(dirEls).forEach(c => c.classList.remove("selected"));
|
|
selectedDir = null;
|
|
}
|
|
}
|
|
|
|
if (fullPath && ws && ws.readyState === WebSocket.OPEN) {
|
|
ws.send(JSON.stringify({ action:"add_to_toplay", songs:[fullPath] }));
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
document.getElementById("add-to-queue-btn").addEventListener("click", addSelectedFileToQueue);
|
|
|
|
function updateControls() {
|
|
document.getElementById("readd-btn").disabled =
|
|
selectedPlaylistIndex === null;
|
|
|
|
document.getElementById("clear-btn").disabled =
|
|
Queue.length === 0;
|
|
}
|
|
|
|
document.addEventListener("keydown", e => {
|
|
if (e.target.tagName === "INPUT") return;
|
|
|
|
if (e.key === "Enter") {
|
|
const added = addSelectedFileToQueue();
|
|
if (added) e.preventDefault();
|
|
}
|
|
if (e.key === "s") ws.send(JSON.stringify({action:"skip"}));
|
|
if (e.key === "n") ws.send(JSON.stringify({action:"skip_next"}));
|
|
if (e.key === "j") ws.send(JSON.stringify({action:"jingle"}));
|
|
});
|
|
|
|
setTimeout(connectWs, 100)
|
|
</script>
|
|
</body>
|
|
</html> |