Files
live-radio/tests/test_web_playlist.py
ozan 6e92841352 Fix generation JSON/Lyria errors, add Winamp player, and ship Echoes of the Sahel.
Harden DeepSeek JSON parsing with retry, pre-sanitize Lyria prompts, and instrumental fallback. Add pure HTML Winamp skin at /winamp with playlist export support.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-07 16:38:52 +01:00

56 lines
1.8 KiB
Python

from __future__ import annotations
import json
from pathlib import Path
from ozan_radio.web_playlist import (
PLAYLIST_MARKER,
build_playlist_payload,
embed_playlist_in_html,
export_gateway_playlist,
)
def test_build_playlist_payload_excludes_skip(songs_dir: Path):
payload = build_playlist_payload(songs_dir)
ids = [t["id"] for t in payload["tracks"]]
assert "11111111" in ids
assert "22222222" not in ids
assert payload["tracks"][0]["url"].startswith("https://tinqs.com/tinqs/live-radio/media/")
def test_embed_playlist_in_html_replaces_marker():
html = f"<script>{PLAYLIST_MARKER}\n{{}}\n{PLAYLIST_MARKER}</script>"
out = embed_playlist_in_html(html, {"tracks": [{"id": "abc"}]})
assert '"abc"' in out
assert PLAYLIST_MARKER in out
def test_export_gateway_playlist_writes_json_and_embeds(tmp_path: Path, songs_dir: Path):
gateway = tmp_path / "gateway"
gateway.mkdir()
index = gateway / "index.html"
index.write_text(
f"<script>\n{PLAYLIST_MARKER}\n{{}}\n{PLAYLIST_MARKER}\n</script>\n",
encoding="utf-8",
)
winamp = gateway / "winamp.html"
winamp.write_text(
f"<script>\n{PLAYLIST_MARKER}\n{{}}\n{PLAYLIST_MARKER}\n</script>\n",
encoding="utf-8",
)
(tmp_path / "songs").mkdir(exist_ok=True)
for f in songs_dir.iterdir():
dest = tmp_path / "songs" / f.name
dest.write_bytes(f.read_bytes())
result = export_gateway_playlist(tmp_path)
assert result is not None
data = json.loads((tmp_path / "gateway" / "playlist.json").read_text(encoding="utf-8"))
assert len(data["tracks"]) == 1
html = index.read_text(encoding="utf-8")
assert "11111111" in html
assert PLAYLIST_MARKER in html
whtml = winamp.read_text(encoding="utf-8")
assert "11111111" in whtml