From 898b52edcb47bcb3e9d6106e74ca73e74ea01e70 Mon Sep 17 00:00:00 2001 From: sillylaird Date: Thu, 3 Sep 2026 00:33:59 +0000 Subject: import live www.sillylaird.ca webroot --- api/nowplaying.php | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 api/nowplaying.php (limited to 'api/nowplaying.php') diff --git a/api/nowplaying.php b/api/nowplaying.php new file mode 100644 index 0000000..1faf016 --- /dev/null +++ b/api/nowplaying.php @@ -0,0 +1,47 @@ + 'rate limited']); + exit; +} + +$ctx = stream_context_create(['http' => [ + 'timeout' => 4, + 'header' => "User-Agent: sillylaird-nowplaying/1.0\r\n", +]]); + +$raw = @file_get_contents('https://radio.sillylaird.ca/status-json.xsl', false, $ctx); +if ($raw === false) { + if (is_file($cacheFile)) { readfile($cacheFile); exit; } + http_response_code(502); + echo json_encode(['error' => 'upstream']); + exit; +} + +$data = json_decode($raw, true); +$src = $data['icestats']['source'] ?? null; +if (is_array($src) && isset($src[0])) $src = $src[0]; + +$out = json_encode([ + 'title' => $src['title'] ?? ($src['yp_currently_playing'] ?? null), + 'name' => $src['server_name'] ?? null, + 'online' => isset($src['title']) || isset($src['yp_currently_playing']), + 'fetched' => time(), +]); + +@file_put_contents($cacheFile . '.tmp', $out, LOCK_EX); +@rename($cacheFile . '.tmp', $cacheFile); +echo $out; -- cgit v1.2.3