<script>
import { onMount } from 'svelte';
console.log("With love, Sony AK <sony@sony-ak.com> GitHub https://github.com/sonyarianto");
let currentSong = '';
let currentArtist = '';
let streamUrl = 'https://api.zeno.fm/mounts/metadata/subscribe/vbyq86vnsp8uv';
onMount(() => {
const eventSource = new EventSource(streamUrl);
eventSource.onmessage = (event) => {
const data = JSON.parse(event.data);
const parts = data.streamTitle.split(" - ");
if (parts.length === 2) {
currentArtist = parts[0].trim();
currentSong = parts[1].trim();
} else {
// Handle cases where the delimiter is not found
console.warn("Unexpected format in streamTitle:", data.streamTitle);
currentSong = data.streamTitle;
currentArtist = '';
}
};
eventSource.onerror = (error) => {
console.error('SSE Error:', error);
};
return () => {
eventSource.close();
};
});
</script>