From 88762d3bfc8dfed72c34fa7fb94b06c4d9c0084e Mon Sep 17 00:00:00 2001 From: Glenn Thompson Date: Wed, 1 Oct 2025 21:49:32 +0300 Subject: [PATCH] fix: Restore live stream metadata display on web interface - Fix Icecast API endpoint to use proper HTTP basic authentication - Handle both string and byte responses from drakma:http-request - Parse XML response to extract track title and listener count - Return JSON in format expected by frontend JavaScript Now Playing info now updates correctly on both front page and player page: - Shows current track (e.g. 'Vector Lovers - Boulevard') - Updates every 10 seconds automatically - Displays real-time listener counts AAC streaming feature is now complete with full live metadata integration. --- asteroid.lisp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/asteroid.lisp b/asteroid.lisp index 55da662..90da0bc 100644 --- a/asteroid.lisp +++ b/asteroid.lisp @@ -315,10 +315,32 @@ "Get live status from Icecast server" (setf (radiance:header "Content-Type") "application/json") (handler-case - (let* ((icecast-url "http://localhost:8000/status-json.xsl") - (response (drakma:http-request icecast-url :want-stream nil))) + (let* ((icecast-url "http://localhost:8000/admin/stats.xml") + (response (drakma:http-request icecast-url + :want-stream nil + :basic-authorization '("admin" "asteroid_admin_2024")))) (if response - (babel:octets-to-string response :encoding :utf-8) ; Convert response to string + (let ((xml-string (if (stringp response) + response + (babel:octets-to-string response :encoding :utf-8)))) + ;; Simple XML parsing to extract source information + ;; Look for sections and extract title, listeners, etc. + (multiple-value-bind (match-start match-end) + (cl-ppcre:scan "" xml-string) + (if match-start + (let* ((source-section (subseq xml-string match-start + (or (cl-ppcre:scan "" xml-string :start match-start) + (length xml-string)))) + (title (or (cl-ppcre:regex-replace-all ".*(.*?).*" source-section "\\1") "Unknown")) + (listeners (or (cl-ppcre:regex-replace-all ".*(.*?).*" source-section "\\1") "0"))) + ;; Return JSON in format expected by frontend + (cl-json:encode-json-to-string + `(("icestats" . (("source" . (("listenurl" . "http://localhost:8000/asteroid.mp3") + ("title" . ,title) + ("listeners" . ,(parse-integer listeners :junk-allowed t))))))))) + ;; No source found, return empty + (cl-json:encode-json-to-string + `(("icestats" . (("source" . nil)))))))) (cl-json:encode-json-to-string `(("error" . "Could not connect to Icecast server"))))) (error (e)