feat: move player to use now-playing partial

This commit is contained in:
Luis Pereira 2025-10-13 21:56:47 +01:00 committed by Brian O'Reilly
parent f3d012cbc6
commit 4d0b54f7d6
2 changed files with 15 additions and 32 deletions

View File

@ -566,41 +566,24 @@ function changeLiveStreamQuality() {
}
}
// Live stream functionality
async function updateLiveStream() {
// Live stream informatio update
async function updateNowPlaying() {
try {
const response = await fetch('/api/asteroid/icecast-status')
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
const response = await fetch('/api/asteroid/partial/now-playing')
const contentType = response.headers.get("content-type")
if (!contentType.includes('text/html')) {
throw new Error('Error connecting to stream')
}
const result = await response.json();
// Handle RADIANCE API wrapper format
const data = result.data || result;
if (data.icestats && data.icestats.source) {
const sources = Array.isArray(data.icestats.source) ? data.icestats.source : [data.icestats.source];
const mainStream = sources.find(s => s.listenurl && s.listenurl.includes('asteroid.mp3'));
if (mainStream && mainStream.title) {
const titleParts = mainStream.title.split(' - ');
const artist = titleParts.length > 1 ? titleParts[0] : 'Unknown Artist';
const track = titleParts.length > 1 ? titleParts.slice(1).join(' - ') : mainStream.title;
const data = await response.text()
document.getElementById('now-playing').innerHTML = data
const nowPlayingEl = document.getElementById('live-now-playing');
const listenersEl = document.getElementById('live-listeners');
if (nowPlayingEl) nowPlayingEl.textContent = `${artist} - ${track}`;
if (listenersEl) listenersEl.textContent = mainStream.listeners || '0';
} else {
}
}
} catch (error) {
console.error('Live stream update error:', error);
const nowPlayingEl = document.getElementById('live-now-playing');
if (nowPlayingEl) nowPlayingEl.textContent = 'Stream unavailable';
} catch(error) {
console.log('Could not fetch stream status:', error);
}
}
// Initial update after 1 second
setTimeout(updateNowPlaying, 1000);
// Update live stream info every 10 seconds
setTimeout(updateLiveStream, 1000); // Initial update after 1 second
setInterval(updateLiveStream, 10000);
setInterval(updateNowPlaying, 10000);

View File

@ -25,8 +25,6 @@
<h2 style="color: #00ff00;">🟢 Live Radio Stream</h2>
<div class="live-stream">
<input type="hidden" id="stream-base-url" lquery="(val stream-base-url)">
<p><strong>Now Playing:</strong> <span id="live-now-playing">Loading...</span></p>
<p><strong>Listeners:</strong> <span id="live-listeners">0</span></p>
<!-- Stream Quality Selector -->
<div class="live-stream-quality">
<label for="live-stream-quality"><strong>Quality:</strong></label>
@ -45,6 +43,8 @@
</div>
</div>
<div id="now-playing" class="now-playing"></div>
<!-- Track Browser -->
<div class="player-section">
<h2>Personal Track Library</h2>