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 // Live stream informatio update
async function updateLiveStream() { async function updateNowPlaying() {
try { try {
const response = await fetch('/api/asteroid/icecast-status') const response = await fetch('/api/asteroid/partial/now-playing')
if (!response.ok) { const contentType = response.headers.get("content-type")
throw new Error(`HTTP ${response.status}`); 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 data = await response.text()
const titleParts = mainStream.title.split(' - '); document.getElementById('now-playing').innerHTML = data
const artist = titleParts.length > 1 ? titleParts[0] : 'Unknown Artist';
const track = titleParts.length > 1 ? titleParts.slice(1).join(' - ') : mainStream.title;
const nowPlayingEl = document.getElementById('live-now-playing'); } catch(error) {
const listenersEl = document.getElementById('live-listeners'); console.log('Could not fetch stream status:', error);
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';
} }
} }
// Initial update after 1 second
setTimeout(updateNowPlaying, 1000);
// Update live stream info every 10 seconds // Update live stream info every 10 seconds
setTimeout(updateLiveStream, 1000); // Initial update after 1 second setInterval(updateNowPlaying, 10000);
setInterval(updateLiveStream, 10000);

View File

@ -25,8 +25,6 @@
<h2 style="color: #00ff00;">🟢 Live Radio Stream</h2> <h2 style="color: #00ff00;">🟢 Live Radio Stream</h2>
<div class="live-stream"> <div class="live-stream">
<input type="hidden" id="stream-base-url" lquery="(val stream-base-url)"> <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 --> <!-- Stream Quality Selector -->
<div class="live-stream-quality"> <div class="live-stream-quality">
<label for="live-stream-quality"><strong>Quality:</strong></label> <label for="live-stream-quality"><strong>Quality:</strong></label>
@ -45,6 +43,8 @@
</div> </div>
</div> </div>
<div id="now-playing" class="now-playing"></div>
<!-- Track Browser --> <!-- Track Browser -->
<div class="player-section"> <div class="player-section">
<h2>Personal Track Library</h2> <h2>Personal Track Library</h2>