diff --git a/asteroid.lisp b/asteroid.lisp
index 296a2bf..3f88e20 100644
--- a/asteroid.lisp
+++ b/asteroid.lisp
@@ -19,6 +19,7 @@
(merge-pathnames "music/library/"
(asdf:system-source-directory :asteroid)))
(defparameter *supported-formats* '("mp3" "flac" "ogg" "wav"))
+(defparameter *stream-base-url* "http://localhost:8000")
;; Configure JSON as the default API format
(define-api-format json (data)
@@ -444,6 +445,10 @@
:status-message "🟢 LIVE - Broadcasting asteroid music for hackers"
:listeners "0"
:stream-quality "128kbps MP3"
+ :stream-base-url *stream-base-url*
+ :default-stream-url (concatenate 'string *stream-base-url* "/asteroid.aac")
+ :default-stream-encoding "audio/aac"
+ :default-stream-encoding-desc "AAC 96kbps Stereo"
:now-playing-artist "The Void"
:now-playing-track "Silence"
:now-playing-album "Startup Sounds"
@@ -458,7 +463,7 @@
(defun check-icecast-status ()
"Check if Icecast server is running and accessible"
(handler-case
- (let ((response (drakma:http-request "http://localhost:8000/status-json.xsl"
+ (let ((response (drakma:http-request (concatenate 'string *stream-base-url* "/status-json.xsl")
:want-stream nil
:connection-timeout 2)))
(if response "🟢 Running" "🔴 Not Running"))
@@ -739,7 +744,8 @@
(clip:process-to-string
(plump:parse (alexandria:read-file-into-string template-path))
:title "Asteroid Radio - Web Player"
- :stream-url "http://localhost:8000/asteroid"
+ :stream-base-url *stream-base-url*
+ :default-stream-url (concatenate 'string *stream-base-url* "/asteroid.aac")
:bitrate "128kbps MP3"
:now-playing-artist "The Void"
:now-playing-track "Silence"
@@ -756,14 +762,14 @@
("artist" . "The Void")
("album" . "Startup Sounds")))
("listeners" . 0)
- ("stream-url" . "http://localhost:8000/asteroid.mp3")
+ ("stream-url" . ,(concatenate 'string *stream-base-url* "/asteroid.mp3"))
("stream-status" . "live"))))
;; Live stream status from Icecast
(define-api asteroid/icecast-status () ()
"Get live status from Icecast server"
(handler-case
- (let* ((icecast-url "http://localhost:8000/admin/stats.xml")
+ (let* ((icecast-url (concatenate 'string *stream-base-url* "/admin/stats.xml"))
(response (drakma:http-request icecast-url
:want-stream nil
:basic-authorization '("admin" "asteroid_admin_2024"))))
@@ -783,7 +789,7 @@
(listeners (or (cl-ppcre:regex-replace-all ".*(.*?).*" source-section "\\1") "0")))
;; Return JSON in format expected by frontend
(api-output
- `(("icestats" . (("source" . (("listenurl" . "http://localhost:8000/asteroid.mp3")
+ `(("icestats" . (("source" . (("listenurl" . ,(concatenate 'string *stream-base-url* "/asteroid.mp3"))
("title" . ,title)
("listeners" . ,(parse-integer listeners :junk-allowed t)))))))))
;; No source found, return empty
@@ -842,8 +848,12 @@
(defun -main (&optional args (debug t))
(declare (ignorable args))
+ (when (uiop:getenvp "ASTEROID_STREAM_URL")
+ (setf *stream-base-url* (uiop:getenv "ASTEROID_STREAM_URL")))
(format t "~&args of asteroid: ~A~%" args)
(format t "~%🎵 ASTEROID RADIO - Music for Hackers 🎵~%")
+ (format t "Using stream server at ~a~%" *stream-base-url*)
+
(format t "Starting RADIANCE web server...~%")
(when debug
(slynk:create-server :port 4009 :dont-close t))
diff --git a/static/js/front-page.js b/static/js/front-page.js
index b3eb531..b2917b3 100644
--- a/static/js/front-page.js
+++ b/static/js/front-page.js
@@ -1,29 +1,34 @@
// Stream quality configuration
-const streamConfig = {
- aac: {
- url: 'http://localhost:8000/asteroid.aac',
- format: 'AAC 96kbps Stereo',
- type: 'audio/aac',
- mount: 'asteroid.aac'
- },
- mp3: {
- url: 'http://localhost:8000/asteroid.mp3',
- format: 'MP3 128kbps Stereo',
- type: 'audio/mpeg',
- mount: 'asteroid.mp3'
- },
- low: {
- url: 'http://localhost:8000/asteroid-low.mp3',
- format: 'MP3 64kbps Stereo',
- type: 'audio/mpeg',
- mount: 'asteroid-low.mp3'
- }
+function getStreamConfig(streamBaseUrl, encoding) {
+ const config = {
+ aac: {
+ url: `${streamBaseUrl}/asteroid.aac`,
+ format: 'AAC 96kbps Stereo',
+ type: 'audio/aac',
+ mount: 'asteroid.aac'
+ },
+ mp3: {
+ url: `${streamBaseUrl}/asteroid.mp3`,
+ format: 'MP3 128kbps Stereo',
+ type: 'audio/mpeg',
+ mount: 'asteroid.mp3'
+ },
+ low: {
+ url: `${streamBaseUrl}/asteroid-low.mp3`,
+ format: 'MP3 64kbps Stereo',
+ type: 'audio/mpeg',
+ mount: 'asteroid-low.mp3'
+ }
+ };
+
+ return config[encoding]
};
// Change stream quality
function changeStreamQuality() {
const selector = document.getElementById('stream-quality');
- const config = streamConfig[selector.value];
+ const streamBaseUrl = document.getElementById('stream-base-url');
+ const config = getStreamConfig(streamBaseUrl.value, selector.value);
// Update UI elements
document.getElementById('stream-url').textContent = config.url;
@@ -91,7 +96,8 @@ async function updateNowPlaying() {
window.addEventListener('DOMContentLoaded', function() {
// Set initial quality display to match the selected stream
const selector = document.getElementById('stream-quality');
- const config = streamConfig[selector.value];
+ const streamBaseUrl = document.getElementById('stream-base-url');
+ const config = getStreamConfig(streamBaseUrl.value, selector.value);
document.getElementById('stream-url').textContent = config.url;
document.getElementById('stream-format').textContent = config.format;
diff --git a/static/js/player.js b/static/js/player.js
index e8f76f8..72d4ed7 100644
--- a/static/js/player.js
+++ b/static/js/player.js
@@ -525,28 +525,33 @@ async function loadPlaylist(playlistId) {
}
// Stream quality configuration (same as front page)
-const liveStreamConfig = {
- aac: {
- url: 'http://localhost:8000/asteroid.aac',
- type: 'audio/aac',
- mount: 'asteroid.aac'
- },
- mp3: {
- url: 'http://localhost:8000/asteroid.mp3',
- type: 'audio/mpeg',
- mount: 'asteroid.mp3'
- },
- low: {
- url: 'http://localhost:8000/asteroid-low.mp3',
- type: 'audio/mpeg',
- mount: 'asteroid-low.mp3'
- }
+function getLiveStreamConfig(streamBaseUrl, quality) {
+ const config = {
+ aac: {
+ url: `${streamBaseUrl}/asteroid.aac`,
+ type: 'audio/aac',
+ mount: 'asteroid.aac'
+ },
+ mp3: {
+ url: `${streamBaseUrl}/asteroid.mp3`,
+ type: 'audio/mpeg',
+ mount: 'asteroid.mp3'
+ },
+ low: {
+ url: `${streamBaseUrl}/asteroid-low.mp3`,
+ type: 'audio/mpeg',
+ mount: 'asteroid-low.mp3'
+ }
+ };
+
+ return config[quality];
};
// Change live stream quality
function changeLiveStreamQuality() {
+ const streamBaseUrl = document.getElementById('stream-base-url');
const selector = document.getElementById('live-stream-quality');
- const config = liveStreamConfig[selector.value];
+ const config = getLiveStreamConfig(streamBaseUrl.value, selector.value);
// Update audio player
const audioElement = document.getElementById('live-stream-audio');
diff --git a/template/front-page.chtml b/template/front-page.chtml
index 2864a43..923013e 100644
--- a/template/front-page.chtml
+++ b/template/front-page.chtml
@@ -37,6 +37,7 @@
+
- Stream URL: http://localhost:8000/asteroid.aac
- Format: AAC 96kbps Stereo
+ Stream URL:
+ Format:
Status: ● BROADCASTING
diff --git a/template/player.chtml b/template/player.chtml
index 8c08528..cbf6d89 100644
--- a/template/player.chtml
+++ b/template/player.chtml
@@ -24,6 +24,7 @@
🟢 Live Radio Stream
+
Now Playing: Loading...
Listeners: 0
@@ -37,7 +38,7 @@
Listen to the live Asteroid Radio stream