feat: move front-page to use now-playing partial
This commit is contained in:
parent
d0efc89e33
commit
f3d012cbc6
|
|
@ -60,33 +60,15 @@ function changeStreamQuality() {
|
||||||
// Update now playing info from Icecast
|
// Update now playing info from Icecast
|
||||||
async function updateNowPlaying() {
|
async function updateNowPlaying() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/asteroid/icecast-status')
|
const response = await fetch('/api/asteroid/partial/now-playing')
|
||||||
const data = await response.json()
|
const contentType = response.headers.get("content-type")
|
||||||
// Handle RADIANCE API wrapper format
|
if (!contentType.includes('text/html')) {
|
||||||
const icecastData = data.data || data;
|
throw new Error('Error connecting to stream')
|
||||||
if (icecastData.icestats && icecastData.icestats.source) {
|
|
||||||
// Find the high quality stream (asteroid.mp3)
|
|
||||||
const sources = Array.isArray(icecastData.icestats.source) ? icecastData.icestats.source : [icecastData.icestats.source];
|
|
||||||
const mainStream = sources.find(s => s.listenurl && s.listenurl.includes('asteroid.mp3'));
|
|
||||||
|
|
||||||
if (mainStream && mainStream.title) {
|
|
||||||
// Parse "Artist - Track" format
|
|
||||||
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;
|
|
||||||
|
|
||||||
document.querySelector('[data-text="now-playing-artist"]').textContent = artist;
|
|
||||||
document.querySelector('[data-text="now-playing-track"]').textContent = track;
|
|
||||||
document.querySelector('[data-text="listeners"]').textContent = mainStream.listeners || '0';
|
|
||||||
|
|
||||||
// Update stream status
|
|
||||||
const statusElement = document.querySelector('.live-stream p:nth-child(3) span');
|
|
||||||
if (statusElement) {
|
|
||||||
statusElement.textContent = '● LIVE - ' + track;
|
|
||||||
statusElement.style.color = '#00ff00';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const data = await response.text()
|
||||||
|
document.getElementById('now-playing').innerHTML = data
|
||||||
|
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
console.log('Could not fetch stream status:', error);
|
console.log('Could not fetch stream status:', error);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,12 +56,7 @@
|
||||||
</audio>
|
</audio>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="now-playing">
|
<div id="now-playing" class="now-playing"></div>
|
||||||
<h2>Now Playing</h2>
|
|
||||||
<p>Artist: <span data-text="now-playing-artist">The Void</span></p>
|
|
||||||
<p>Track: <span data-text="now-playing-track">Silence</span></p>
|
|
||||||
<p>Listeners: <span data-text="listeners">0</span></p>
|
|
||||||
</div>
|
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue