<?php
header('Content-Type: application/json');

// URL XML du flux Shoutcast
$url = 'https://studio.simbacast.com:1180/stats?sid=1';

// Récupération des données XML
$xml = @simplexml_load_file($url);

if ($xml === false) {
    echo json_encode(['error' => 'Impossible de lire les métadonnées Shoutcast']);
    exit;
}

// Conversion XML → JSON
$data = [
    'current_listeners' => (int) $xml->CURRENTLISTENERS,
    'song_title'        => (string) $xml->SONGTITLE,
    'server_title'      => (string) $xml->SERVERTITLE,
    'bitrate'           => (int) $xml->BITRATE,
    'status'            => (int) $xml->STREAMSTATUS
];

echo json_encode($data);
?>
