aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2026-02-18 18:52:20 -0800
committerPinapelz <yukais@pinapelz.com>2026-02-18 18:52:20 -0800
commit0f30b59146f1ee8b7784a14dce70e7645d26359c (patch)
tree14f61f4426c12dfb8ca84a1e2c36e68a73b213b9
parent18dc91fe547b47913333266c891ae0b5ed70fbfc (diff)
re-add static non-streamed m3u route
-rw-r--r--yt_radio.py32
1 files changed, 26 insertions, 6 deletions
diff --git a/yt_radio.py b/yt_radio.py
index 40937e5..f4bd9a0 100644
--- a/yt_radio.py
+++ b/yt_radio.py
@@ -23,6 +23,7 @@ BURST_SECONDS = int(os.environ.get("BURST_SECONDS", "10")) # allow pre-buffering
BASE_URL = os.environ.get("BASE_URL", "http://localhost:8000")
PLAYLIST_URL = os.environ.get("PLAYLIST_URL")
CACHE_FILE = os.environ.get("CACHE_FILE", "cache.json")
+RANDOMIZE_PLAYLIST = bool(os.environ.get("RANDOMIZE_PLAYLIST", "false"))
# optional / page
SITE_TITLE = os.environ.get("SITE_TITLE", "yt_radio.py")
@@ -296,12 +297,31 @@ def home():
@app.route("/playlist.m3u")
def playlist_route():
- lines = [
- "#EXTM3U",
- f"#EXTINF:-1,Infinite Radio",
- f"{BASE_URL}/stream",
- ]
- return Response("\n".join(lines), mimetype="audio/x-mpegurl")
+ if not PLAYLIST:
+ return Response("#EXTM3U\n", mimetype="audio/x-mpegurl")
+ indices = list(range(len(PLAYLIST)))
+ if RANDOMIZE_PLAYLIST:
+ random.shuffle(indices)
+
+ lines = ["#EXTM3U"]
+ for i in indices:
+ try:
+ _ensure_metadata(i)
+ except Exception:
+ logger.debug("Failed to ensure metadata for index %s", i)
+
+ meta = METADATA.get(i, {})
+ title = meta.get("title", f"Track {i+1}")
+ artist = meta.get("artist", "Unknown")
+ duration = meta.get("duration", -1)
+ try:
+ duration_int = int(duration) if isinstance(duration, (int, float, str)) and str(duration).isdigit() else int(duration) if isinstance(duration, int) else -1
+ except Exception:
+ duration_int = -1
+ lines.append(f"#EXTINF:{duration_int},{artist} - {title}")
+ lines.append(PLAYLIST[i])
+ body = "\n".join(lines) + "\n"
+ return Response(body, mimetype="audio/x-mpegurl")
@app.route("/stream")
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage