6843ecd6b0
Robust candidate-part parsing, quota-aware errors, live composing feedback, and two new desert dub tracks in the library. Co-authored-by: Cursor <cursoragent@cursor.com>
871 lines
26 KiB
HTML
871 lines
26 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Live Ozan Radio</title>
|
|
<style>
|
|
:root {
|
|
--bg: #0a0a0f;
|
|
--panel: #14141f;
|
|
--accent: #ff6b35;
|
|
--accent2: #7b5cff;
|
|
--text: #f0f0f5;
|
|
--muted: #8888a0;
|
|
--glow: rgba(255, 107, 53, 0.35);
|
|
}
|
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
body {
|
|
font-family: "Segoe UI", system-ui, sans-serif;
|
|
background: var(--bg);
|
|
color: var(--text);
|
|
min-height: 100vh;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
background-image:
|
|
radial-gradient(ellipse 80% 50% at 50% -10%, var(--glow), transparent),
|
|
radial-gradient(ellipse 60% 40% at 100% 100%, rgba(123,92,255,0.15), transparent);
|
|
}
|
|
.radio {
|
|
width: min(440px, 92vw);
|
|
background: var(--panel);
|
|
border: 1px solid #2a2a3a;
|
|
border-radius: 20px;
|
|
padding: 2rem;
|
|
box-shadow: 0 24px 80px rgba(0,0,0,0.5);
|
|
}
|
|
.header-row {
|
|
display: flex;
|
|
align-items: flex-start;
|
|
justify-content: space-between;
|
|
gap: 0.75rem;
|
|
margin-bottom: 0.25rem;
|
|
}
|
|
.header-row h1 { margin-bottom: 0; }
|
|
.icon-btn {
|
|
flex: 0 0 auto;
|
|
width: 40px;
|
|
height: 40px;
|
|
min-width: 40px;
|
|
padding: 0;
|
|
border-radius: 10px;
|
|
background: #2a2a3a;
|
|
border: 1px solid #3a3a50;
|
|
color: var(--text);
|
|
font-size: 1.1rem;
|
|
cursor: pointer;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
transition: border-color 0.15s, background 0.15s;
|
|
}
|
|
.icon-btn:hover { border-color: var(--accent); background: #32324a; }
|
|
.icon-btn.active { border-color: var(--accent); color: var(--accent); }
|
|
.badge {
|
|
display: inline-block;
|
|
font-size: 0.7rem;
|
|
font-weight: 700;
|
|
letter-spacing: 0.12em;
|
|
text-transform: uppercase;
|
|
color: var(--accent);
|
|
border: 1px solid var(--accent);
|
|
border-radius: 4px;
|
|
padding: 0.2rem 0.5rem;
|
|
margin-bottom: 0.75rem;
|
|
}
|
|
h1 {
|
|
font-size: 1.6rem;
|
|
font-weight: 700;
|
|
margin-bottom: 0.25rem;
|
|
}
|
|
.tagline {
|
|
color: var(--muted);
|
|
font-size: 0.85rem;
|
|
margin-bottom: 1rem;
|
|
line-height: 1.4;
|
|
}
|
|
.dashboard {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr;
|
|
gap: 0.5rem;
|
|
margin-bottom: 1.25rem;
|
|
}
|
|
.stat-card {
|
|
background: #1a1a28;
|
|
border: 1px solid #2a2a3a;
|
|
border-radius: 12px;
|
|
padding: 0.65rem 0.75rem;
|
|
}
|
|
.stat-card.wide { grid-column: 1 / -1; }
|
|
.stat-label {
|
|
font-size: 0.65rem;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.06em;
|
|
color: var(--muted);
|
|
margin-bottom: 0.2rem;
|
|
}
|
|
.stat-value {
|
|
font-size: 1rem;
|
|
font-weight: 700;
|
|
color: var(--text);
|
|
}
|
|
.stat-value.accent { color: var(--accent); }
|
|
.stat-sub {
|
|
font-size: 0.7rem;
|
|
color: var(--muted);
|
|
margin-top: 0.15rem;
|
|
}
|
|
.settings-panel {
|
|
display: none;
|
|
background: #1a1a28;
|
|
border: 1px solid #3a3a50;
|
|
border-radius: 14px;
|
|
padding: 1rem;
|
|
margin-bottom: 1.25rem;
|
|
}
|
|
.settings-panel.open { display: block; }
|
|
.settings-panel h2 {
|
|
font-size: 0.75rem;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.08em;
|
|
color: var(--muted);
|
|
margin-bottom: 0.75rem;
|
|
}
|
|
.setting-row {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
gap: 0.75rem;
|
|
padding: 0.5rem 0;
|
|
border-bottom: 1px solid #2a2a3a;
|
|
font-size: 0.85rem;
|
|
}
|
|
.setting-row:last-child { border-bottom: none; }
|
|
.setting-row label { flex: 1; color: var(--text); }
|
|
.setting-row .hint {
|
|
display: block;
|
|
font-size: 0.7rem;
|
|
color: var(--muted);
|
|
margin-top: 0.15rem;
|
|
}
|
|
.toggle {
|
|
position: relative;
|
|
width: 44px;
|
|
height: 24px;
|
|
flex-shrink: 0;
|
|
}
|
|
.toggle input { opacity: 0; width: 0; height: 0; }
|
|
.toggle span {
|
|
position: absolute;
|
|
inset: 0;
|
|
background: #3a3a50;
|
|
border-radius: 12px;
|
|
cursor: pointer;
|
|
transition: background 0.2s;
|
|
}
|
|
.toggle span::before {
|
|
content: "";
|
|
position: absolute;
|
|
width: 18px;
|
|
height: 18px;
|
|
left: 3px;
|
|
top: 3px;
|
|
background: #fff;
|
|
border-radius: 50%;
|
|
transition: transform 0.2s;
|
|
}
|
|
.toggle input:checked + span { background: var(--accent); }
|
|
.toggle input:checked + span::before { transform: translateX(20px); }
|
|
.num-input {
|
|
width: 64px;
|
|
background: #14141f;
|
|
border: 1px solid #3a3a50;
|
|
border-radius: 8px;
|
|
padding: 0.35rem 0.5rem;
|
|
color: var(--text);
|
|
font-size: 0.85rem;
|
|
text-align: center;
|
|
}
|
|
.num-input:focus { outline: none; border-color: var(--accent); }
|
|
.range-input {
|
|
width: 100px;
|
|
accent-color: var(--accent);
|
|
}
|
|
.viz {
|
|
height: 64px;
|
|
display: flex;
|
|
align-items: flex-end;
|
|
justify-content: center;
|
|
gap: 4px;
|
|
margin-bottom: 1.25rem;
|
|
}
|
|
.bar {
|
|
width: 6px;
|
|
background: linear-gradient(to top, var(--accent), var(--accent2));
|
|
border-radius: 3px;
|
|
animation: bounce 0.8s ease-in-out infinite alternate;
|
|
}
|
|
.bar:nth-child(1) { height: 20px; animation-delay: 0s; }
|
|
.bar:nth-child(2) { height: 36px; animation-delay: 0.1s; }
|
|
.bar:nth-child(3) { height: 52px; animation-delay: 0.2s; }
|
|
.bar:nth-child(4) { height: 40px; animation-delay: 0.15s; }
|
|
.bar:nth-child(5) { height: 28px; animation-delay: 0.05s; }
|
|
.bar:nth-child(6) { height: 44px; animation-delay: 0.25s; }
|
|
.bar:nth-child(7) { height: 32px; animation-delay: 0.12s; }
|
|
.viz.paused .bar { animation-play-state: paused; opacity: 0.35; }
|
|
@keyframes bounce {
|
|
from { transform: scaleY(0.4); opacity: 0.6; }
|
|
to { transform: scaleY(1); opacity: 1; }
|
|
}
|
|
.now-title {
|
|
font-size: 1.15rem;
|
|
font-weight: 600;
|
|
margin-bottom: 0.35rem;
|
|
}
|
|
.now-mood, .dj-line {
|
|
font-size: 0.85rem;
|
|
color: var(--muted);
|
|
margin-bottom: 0.5rem;
|
|
}
|
|
.dj-line { font-style: italic; color: #b0b0c8; }
|
|
audio {
|
|
width: 100%;
|
|
margin: 1rem 0;
|
|
border-radius: 8px;
|
|
}
|
|
.controls {
|
|
display: flex;
|
|
gap: 0.5rem;
|
|
flex-wrap: wrap;
|
|
}
|
|
button {
|
|
flex: 1;
|
|
min-width: 100px;
|
|
padding: 0.65rem 1rem;
|
|
border: none;
|
|
border-radius: 10px;
|
|
font-size: 0.85rem;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
transition: transform 0.15s, opacity 0.15s;
|
|
}
|
|
button:hover { transform: translateY(-1px); }
|
|
button:active { transform: translateY(0); }
|
|
button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
|
|
.primary {
|
|
background: linear-gradient(135deg, var(--accent), #ff8f65);
|
|
color: #fff;
|
|
}
|
|
.secondary {
|
|
background: #2a2a3a;
|
|
color: var(--text);
|
|
border: 1px solid #3a3a50;
|
|
}
|
|
.status {
|
|
margin-top: 1rem;
|
|
font-size: 0.75rem;
|
|
color: var(--muted);
|
|
text-align: center;
|
|
line-height: 1.4;
|
|
}
|
|
.status.generating { color: var(--accent); }
|
|
.status.error { color: #ff5c7a; }
|
|
.stack {
|
|
font-size: 0.7rem;
|
|
color: #555568;
|
|
margin-top: 1.25rem;
|
|
padding-top: 1rem;
|
|
border-top: 1px solid #2a2a3a;
|
|
line-height: 1.6;
|
|
}
|
|
.chat {
|
|
margin-top: 1.25rem;
|
|
border-top: 1px solid #2a2a3a;
|
|
padding-top: 1rem;
|
|
}
|
|
.chat h2 {
|
|
font-size: 0.8rem;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.08em;
|
|
color: var(--muted);
|
|
margin-bottom: 0.65rem;
|
|
}
|
|
.chat-log {
|
|
height: 160px;
|
|
overflow-y: auto;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.5rem;
|
|
margin-bottom: 0.65rem;
|
|
padding-right: 0.25rem;
|
|
}
|
|
.chat-log::-webkit-scrollbar { width: 4px; }
|
|
.chat-log::-webkit-scrollbar-thumb { background: #3a3a50; border-radius: 2px; }
|
|
.bubble {
|
|
max-width: 88%;
|
|
padding: 0.55rem 0.75rem;
|
|
border-radius: 12px;
|
|
font-size: 0.82rem;
|
|
line-height: 1.4;
|
|
}
|
|
.bubble.user {
|
|
align-self: flex-end;
|
|
background: #2a2a3a;
|
|
color: var(--text);
|
|
border-bottom-right-radius: 4px;
|
|
}
|
|
.bubble.dj {
|
|
align-self: flex-start;
|
|
background: linear-gradient(135deg, rgba(255,107,53,0.15), rgba(123,92,255,0.12));
|
|
border: 1px solid #3a3a50;
|
|
border-bottom-left-radius: 4px;
|
|
}
|
|
.chat-form {
|
|
display: flex;
|
|
gap: 0.5rem;
|
|
}
|
|
.chat-form input {
|
|
flex: 1;
|
|
background: #1a1a28;
|
|
border: 1px solid #3a3a50;
|
|
border-radius: 10px;
|
|
padding: 0.6rem 0.75rem;
|
|
color: var(--text);
|
|
font-size: 0.85rem;
|
|
}
|
|
.chat-form input:focus {
|
|
outline: none;
|
|
border-color: var(--accent);
|
|
}
|
|
.chat-form button {
|
|
flex: 0 0 auto;
|
|
min-width: 72px;
|
|
padding: 0.6rem 1rem;
|
|
}
|
|
.library {
|
|
margin-top: 1.25rem;
|
|
border-top: 1px solid #2a2a3a;
|
|
padding-top: 1rem;
|
|
}
|
|
.library h2 {
|
|
font-size: 0.8rem;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.08em;
|
|
color: var(--muted);
|
|
margin-bottom: 0.5rem;
|
|
}
|
|
.library-list {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.35rem;
|
|
max-height: 140px;
|
|
overflow-y: auto;
|
|
}
|
|
.song-row {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
gap: 0.5rem;
|
|
padding: 0.5rem 0.65rem;
|
|
background: #1a1a28;
|
|
border: 1px solid #2a2a3a;
|
|
border-radius: 10px;
|
|
cursor: pointer;
|
|
font-size: 0.82rem;
|
|
text-align: left;
|
|
color: var(--text);
|
|
width: 100%;
|
|
}
|
|
.song-row:hover { border-color: var(--accent); }
|
|
.song-row.playing { border-color: var(--accent); background: rgba(255,107,53,0.08); }
|
|
.song-meta { color: var(--muted); font-size: 0.72rem; }
|
|
.library-empty { color: var(--muted); font-size: 0.8rem; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="radio">
|
|
<div class="badge" id="modeBadge">● Live</div>
|
|
<div class="header-row">
|
|
<h1>Ozan Radio</h1>
|
|
<button type="button" class="icon-btn" id="settingsBtn" title="Settings" aria-label="Settings">⚙</button>
|
|
</div>
|
|
<p class="tagline">No Spotify playback. No catalog tracks. DeepSeek picks the vibe — Google Lyria 3 composes it fresh.</p>
|
|
|
|
<section class="dashboard" id="dashboard">
|
|
<div class="stat-card">
|
|
<div class="stat-label">Today spent</div>
|
|
<div class="stat-value accent" id="statSpent">$0.00</div>
|
|
<div class="stat-sub" id="statPerTrack">~$0.08 / track</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="stat-label">New songs today</div>
|
|
<div class="stat-value" id="statGenerated">0 / 10</div>
|
|
<div class="stat-sub" id="statRemaining">10 remaining</div>
|
|
</div>
|
|
<div class="stat-card wide">
|
|
<div class="stat-label">Max daily budget (at limit)</div>
|
|
<div class="stat-value" id="statMaxBudget">$0.82</div>
|
|
<div class="stat-sub">Lyria Pro + DeepSeek estimate</div>
|
|
</div>
|
|
</section>
|
|
|
|
<section class="settings-panel" id="settingsPanel">
|
|
<h2>Playback & limits</h2>
|
|
<div class="setting-row">
|
|
<label>
|
|
Shuffle mode
|
|
<span class="hint">Mix saved songs and freshly generated tracks</span>
|
|
</label>
|
|
<label class="toggle">
|
|
<input type="checkbox" id="setShuffle" checked>
|
|
<span></span>
|
|
</label>
|
|
</div>
|
|
<div class="setting-row">
|
|
<label>
|
|
Mix existing + new
|
|
<span class="hint">When shuffle is on, also compose new tracks</span>
|
|
</label>
|
|
<label class="toggle">
|
|
<input type="checkbox" id="setMix" checked>
|
|
<span></span>
|
|
</label>
|
|
</div>
|
|
<div class="setting-row">
|
|
<label>
|
|
New song chance
|
|
<span class="hint">Probability each shuffle picks a fresh track</span>
|
|
</label>
|
|
<input type="range" class="range-input" id="setChance" min="0" max="100" value="35">
|
|
</div>
|
|
<div class="setting-row">
|
|
<label>
|
|
Max new songs / day
|
|
<span class="hint">Hard cap on Lyria generations</span>
|
|
</label>
|
|
<input type="number" class="num-input" id="setMaxPerDay" min="1" max="100" value="10">
|
|
</div>
|
|
</section>
|
|
|
|
<div class="viz" id="viz">
|
|
<div class="bar"></div><div class="bar"></div><div class="bar"></div>
|
|
<div class="bar"></div><div class="bar"></div><div class="bar"></div><div class="bar"></div>
|
|
</div>
|
|
|
|
<div class="now-title" id="title">Waiting for first track…</div>
|
|
<div class="now-mood" id="mood"></div>
|
|
<div class="dj-line" id="dj"></div>
|
|
|
|
<audio id="player" controls></audio>
|
|
|
|
<div class="controls">
|
|
<button class="primary" id="genBtn">Generate next</button>
|
|
<button class="secondary" id="skipBtn">Skip</button>
|
|
<button class="secondary" id="refreshBtn">Refresh</button>
|
|
</div>
|
|
|
|
<div class="status" id="status">Connecting…</div>
|
|
|
|
<section class="library">
|
|
<h2>Saved songs</h2>
|
|
<div class="library-list" id="libraryList">
|
|
<div class="library-empty">Loading library…</div>
|
|
</div>
|
|
</section>
|
|
|
|
<section class="chat">
|
|
<h2>Talk to the DJ</h2>
|
|
<div class="chat-log" id="chatLog"></div>
|
|
<form class="chat-form" id="chatForm">
|
|
<input id="chatInput" type="text" placeholder="Ask for a vibe… e.g. more Sahel, slower, surprise me" maxlength="500" autocomplete="off">
|
|
<button type="submit" class="primary" id="chatSend">Send</button>
|
|
</form>
|
|
</section>
|
|
|
|
<div class="stack">
|
|
DJ: DeepSeek · Music: Google Lyria 3 · Taste: settings.json<br>
|
|
Optional live layer: Magenta RealTime 2 on Apple Silicon
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const API = window.location.origin;
|
|
const player = document.getElementById('player');
|
|
const viz = document.getElementById('viz');
|
|
const titleEl = document.getElementById('title');
|
|
const moodEl = document.getElementById('mood');
|
|
const djEl = document.getElementById('dj');
|
|
const statusEl = document.getElementById('status');
|
|
const genBtn = document.getElementById('genBtn');
|
|
const skipBtn = document.getElementById('skipBtn');
|
|
const refreshBtn = document.getElementById('refreshBtn');
|
|
const chatLog = document.getElementById('chatLog');
|
|
const chatForm = document.getElementById('chatForm');
|
|
const chatInput = document.getElementById('chatInput');
|
|
const chatSend = document.getElementById('chatSend');
|
|
const libraryList = document.getElementById('libraryList');
|
|
const settingsBtn = document.getElementById('settingsBtn');
|
|
const settingsPanel = document.getElementById('settingsPanel');
|
|
const modeBadge = document.getElementById('modeBadge');
|
|
const setShuffle = document.getElementById('setShuffle');
|
|
const setMix = document.getElementById('setMix');
|
|
const setChance = document.getElementById('setChance');
|
|
const setMaxPerDay = document.getElementById('setMaxPerDay');
|
|
const statSpent = document.getElementById('statSpent');
|
|
const statPerTrack = document.getElementById('statPerTrack');
|
|
const statGenerated = document.getElementById('statGenerated');
|
|
const statRemaining = document.getElementById('statRemaining');
|
|
const statMaxBudget = document.getElementById('statMaxBudget');
|
|
|
|
let currentTrackId = null;
|
|
let radioSettings = { playback: { shuffle: true, mix_existing_and_new: true, new_song_chance: 0.35 } };
|
|
let savingSettings = false;
|
|
let lastGenError = null;
|
|
|
|
function fmtUsd(n) {
|
|
return '$' + Number(n || 0).toFixed(2);
|
|
}
|
|
|
|
function applyTrack(t, source) {
|
|
if (!t) return;
|
|
currentTrackId = t.track_id;
|
|
titleEl.textContent = t.title;
|
|
moodEl.textContent = t.mood ? `Mood: ${t.mood}` : '';
|
|
djEl.textContent = t.dj_line ? `"${t.dj_line}"` : '';
|
|
const url = `${API}${t.audio_url}`;
|
|
if (player.src !== url) {
|
|
player.src = url;
|
|
player.play().catch(() => {});
|
|
}
|
|
const srcLabel = source === 'generated' ? 'New · ' : source === 'library' ? 'Library · ' : '';
|
|
statusEl.textContent = `${srcLabel}Playing · ${t.track_id}`;
|
|
loadLibrary();
|
|
}
|
|
|
|
function applyGenerationState(gen) {
|
|
if (!gen) return;
|
|
if (gen.busy) {
|
|
genBtn.disabled = true;
|
|
const title = gen.track_title ? ` "${gen.track_title}"` : '';
|
|
const phase = gen.phase === 'planning'
|
|
? `DeepSeek planning${title}…`
|
|
: `Lyria composing${title}… (~30s)`;
|
|
statusEl.textContent = phase;
|
|
statusEl.classList.add('generating');
|
|
statusEl.classList.remove('error');
|
|
return;
|
|
}
|
|
genBtn.disabled = false;
|
|
statusEl.classList.remove('generating');
|
|
if (gen.error) {
|
|
statusEl.textContent = gen.error;
|
|
statusEl.classList.add('error');
|
|
if (gen.error !== lastGenError) {
|
|
lastGenError = gen.error;
|
|
addBubble('dj', `Couldn't finish that track: ${gen.error}`);
|
|
}
|
|
return;
|
|
}
|
|
lastGenError = null;
|
|
statusEl.classList.remove('error');
|
|
}
|
|
|
|
function updateDashboard(stats) {
|
|
if (!stats) return;
|
|
const today = stats.today || {};
|
|
const costs = stats.costs || {};
|
|
statSpent.textContent = fmtUsd(today.estimated_usd);
|
|
statPerTrack.textContent = `~${fmtUsd(costs.per_track_estimate_usd)} / track`;
|
|
statGenerated.textContent = `${today.generated || 0} / ${today.max_per_day || 10}`;
|
|
statRemaining.textContent = `${today.remaining ?? 0} remaining`;
|
|
statMaxBudget.textContent = fmtUsd(stats.projected_daily_max_usd);
|
|
if (stats.playback) {
|
|
radioSettings.playback = stats.playback;
|
|
syncSettingsUI(stats.playback);
|
|
}
|
|
applyGenerationState(stats.generation);
|
|
updateModeBadge();
|
|
}
|
|
|
|
function syncSettingsUI(pb) {
|
|
if (savingSettings) return;
|
|
setShuffle.checked = !!pb.shuffle;
|
|
setMix.checked = !!pb.mix_existing_and_new;
|
|
setChance.value = Math.round((pb.new_song_chance || 0.35) * 100);
|
|
}
|
|
|
|
function updateModeBadge() {
|
|
const shuffle = radioSettings.playback?.shuffle;
|
|
modeBadge.textContent = shuffle ? '● Shuffle' : '● Live';
|
|
skipBtn.textContent = shuffle ? 'Shuffle next' : 'Skip';
|
|
}
|
|
|
|
async function loadStats(returnData = false) {
|
|
try {
|
|
const res = await fetch(`${API}/api/stats`);
|
|
const data = await res.json();
|
|
updateDashboard(data);
|
|
return returnData ? data : undefined;
|
|
} catch (_) {}
|
|
}
|
|
|
|
async function loadSettings() {
|
|
try {
|
|
const res = await fetch(`${API}/api/settings`);
|
|
const data = await res.json();
|
|
radioSettings = data;
|
|
syncSettingsUI({
|
|
shuffle: data.playback?.shuffle,
|
|
mix_existing_and_new: data.playback?.mix_existing_and_new,
|
|
new_song_chance: data.playback?.new_song_chance,
|
|
});
|
|
if (data.budget) {
|
|
setMaxPerDay.value = data.budget.max_per_day || 10;
|
|
}
|
|
updateModeBadge();
|
|
} catch (_) {}
|
|
}
|
|
|
|
let saveTimer = null;
|
|
function scheduleSaveSettings() {
|
|
clearTimeout(saveTimer);
|
|
saveTimer = setTimeout(saveSettings, 400);
|
|
}
|
|
|
|
async function saveSettings() {
|
|
savingSettings = true;
|
|
const patch = {
|
|
playback: {
|
|
shuffle: setShuffle.checked,
|
|
mix_existing_and_new: setMix.checked,
|
|
new_song_chance: setChance.value / 100,
|
|
},
|
|
limits: {
|
|
max_new_songs_per_day: parseInt(setMaxPerDay.value, 10) || 10,
|
|
},
|
|
};
|
|
try {
|
|
const res = await fetch(`${API}/api/settings`, {
|
|
method: 'PATCH',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(patch),
|
|
});
|
|
const data = await res.json();
|
|
radioSettings = data;
|
|
updateModeBadge();
|
|
if (data.budget) {
|
|
statGenerated.textContent = `${data.budget.generated || 0} / ${data.budget.max_per_day}`;
|
|
statRemaining.textContent = `${data.budget.remaining ?? 0} remaining`;
|
|
}
|
|
const perTrack = data.costs?.per_track_estimate_usd || 0.082;
|
|
statMaxBudget.textContent = fmtUsd(perTrack * (data.limits?.max_new_songs_per_day || 10));
|
|
} catch (_) {}
|
|
savingSettings = false;
|
|
}
|
|
|
|
settingsBtn.addEventListener('click', () => {
|
|
settingsPanel.classList.toggle('open');
|
|
settingsBtn.classList.toggle('active', settingsPanel.classList.contains('open'));
|
|
});
|
|
[setShuffle, setMix, setChance, setMaxPerDay].forEach(el => {
|
|
el.addEventListener('change', scheduleSaveSettings);
|
|
el.addEventListener('input', scheduleSaveSettings);
|
|
});
|
|
|
|
async function loadLibrary() {
|
|
try {
|
|
const res = await fetch(`${API}/api/songs`);
|
|
const data = await res.json();
|
|
libraryList.innerHTML = '';
|
|
if (!data.songs || data.songs.length === 0) {
|
|
libraryList.innerHTML = '<div class="library-empty">No saved songs yet — generate one!</div>';
|
|
return;
|
|
}
|
|
for (const song of data.songs) {
|
|
const btn = document.createElement('button');
|
|
btn.type = 'button';
|
|
btn.className = 'song-row' + (song.id === currentTrackId ? ' playing' : '');
|
|
const sizeMb = song.size_bytes ? (song.size_bytes / 1e6).toFixed(1) + ' MB' : '';
|
|
btn.innerHTML = `<span>${song.title}</span><span class="song-meta">${sizeMb}</span>`;
|
|
btn.addEventListener('click', () => playSong(song.id));
|
|
libraryList.appendChild(btn);
|
|
}
|
|
} catch (_) {
|
|
libraryList.innerHTML = '<div class="library-empty">Library offline</div>';
|
|
}
|
|
}
|
|
|
|
async function playSong(trackId) {
|
|
try {
|
|
const res = await fetch(`${API}/api/songs/${trackId}/play`, { method: 'POST' });
|
|
const data = await res.json();
|
|
if (data.status === 'ok' && data.track) {
|
|
applyTrack(data.track, 'library');
|
|
}
|
|
} catch (_) {}
|
|
}
|
|
|
|
function addBubble(role, text) {
|
|
const el = document.createElement('div');
|
|
el.className = `bubble ${role}`;
|
|
el.textContent = text;
|
|
chatLog.appendChild(el);
|
|
chatLog.scrollTop = chatLog.scrollHeight;
|
|
}
|
|
|
|
async function loadChat() {
|
|
try {
|
|
const res = await fetch(`${API}/api/chat`);
|
|
const data = await res.json();
|
|
chatLog.innerHTML = '';
|
|
for (const m of data.messages || []) {
|
|
addBubble(m.role, m.content);
|
|
}
|
|
} catch (_) {}
|
|
}
|
|
|
|
async function sendChat(text) {
|
|
chatSend.disabled = true;
|
|
chatInput.disabled = true;
|
|
addBubble('user', text);
|
|
try {
|
|
const res = await fetch(`${API}/api/chat`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ message: text }),
|
|
});
|
|
const data = await res.json();
|
|
if (data.reply) addBubble('dj', data.reply);
|
|
if (data.generating) {
|
|
statusEl.textContent = 'DeepSeek planning your request…';
|
|
statusEl.classList.add('generating');
|
|
pollForNewTrack();
|
|
}
|
|
} catch (_) {
|
|
addBubble('dj', 'Signal lost — try again.');
|
|
} finally {
|
|
chatSend.disabled = false;
|
|
chatInput.disabled = false;
|
|
chatInput.focus();
|
|
}
|
|
}
|
|
|
|
let pollTimer = null;
|
|
function pollForNewTrack() {
|
|
let n = 0;
|
|
clearInterval(pollTimer);
|
|
pollTimer = setInterval(async () => {
|
|
n += 1;
|
|
const stats = await loadStats(true);
|
|
if (stats?.generation?.busy) return;
|
|
if (stats?.generation?.error) {
|
|
clearInterval(pollTimer);
|
|
return;
|
|
}
|
|
await refreshNow();
|
|
const now = await fetch(`${API}/api/now`).then(r => r.json()).catch(() => null);
|
|
if (now?.track?.track_id !== currentTrackId) clearInterval(pollTimer);
|
|
if (n > 60) clearInterval(pollTimer);
|
|
}, 3000);
|
|
}
|
|
|
|
async function refreshNow() {
|
|
try {
|
|
const res = await fetch(`${API}/api/now`);
|
|
const data = await res.json();
|
|
if (data.status === 'idle') {
|
|
titleEl.textContent = 'Queue empty';
|
|
moodEl.textContent = '';
|
|
djEl.textContent = 'Hit Generate to compose the first track.';
|
|
statusEl.textContent = data.message || 'Idle';
|
|
return;
|
|
}
|
|
applyTrack(data.track);
|
|
} catch (e) {
|
|
statusEl.textContent = 'Server offline — start: python -m ozan_radio';
|
|
}
|
|
}
|
|
|
|
async function generate() {
|
|
genBtn.disabled = true;
|
|
statusEl.textContent = 'DeepSeek is planning… Lyria is composing…';
|
|
try {
|
|
const res = await fetch(`${API}/api/generate`, { method: 'POST' });
|
|
const data = await res.json();
|
|
if (data.status === 'busy') {
|
|
statusEl.textContent = data.message;
|
|
} else if (data.status === 'limit') {
|
|
statusEl.textContent = data.message || 'Daily limit reached';
|
|
updateDashboard({ today: data.budget, costs: radioSettings.costs });
|
|
} else if (data.status === 'error') {
|
|
statusEl.textContent = data.message || 'Generation failed';
|
|
statusEl.classList.add('error');
|
|
applyGenerationState(data.generation || { error: data.message });
|
|
} else if (data.status === 'ok') {
|
|
if (data.track) applyTrack(data.track, data.source || 'generated');
|
|
await loadStats();
|
|
} else {
|
|
statusEl.textContent = 'Generation failed — check server logs';
|
|
}
|
|
} catch (e) {
|
|
statusEl.textContent = 'Request failed';
|
|
} finally {
|
|
genBtn.disabled = false;
|
|
}
|
|
}
|
|
|
|
async function nextTrack() {
|
|
skipBtn.disabled = true;
|
|
const shuffle = radioSettings.playback?.shuffle;
|
|
try {
|
|
const endpoint = shuffle ? `${API}/api/shuffle/next` : `${API}/api/skip`;
|
|
const res = await fetch(endpoint, { method: 'POST' });
|
|
const data = await res.json();
|
|
if (data.status === 'limit') {
|
|
statusEl.textContent = data.message || 'Daily limit — no more new songs today';
|
|
} else if (data.status === 'busy') {
|
|
statusEl.textContent = data.message;
|
|
statusEl.classList.add('generating');
|
|
pollForNewTrack();
|
|
return;
|
|
} else if (data.status === 'error') {
|
|
statusEl.textContent = data.message || 'Generation failed';
|
|
statusEl.classList.add('error');
|
|
} else if (data.status === 'ok' && data.track) {
|
|
applyTrack(data.track, data.source);
|
|
} else if (data.status === 'idle') {
|
|
await refreshNow();
|
|
}
|
|
if (data.budget || data.cost_usd !== undefined) {
|
|
await loadStats();
|
|
}
|
|
} finally {
|
|
skipBtn.disabled = false;
|
|
}
|
|
}
|
|
|
|
genBtn.addEventListener('click', generate);
|
|
skipBtn.addEventListener('click', nextTrack);
|
|
refreshBtn.addEventListener('click', () => { refreshNow(); loadStats(); });
|
|
player.addEventListener('ended', nextTrack);
|
|
player.addEventListener('play', () => viz.classList.remove('paused'));
|
|
player.addEventListener('pause', () => viz.classList.add('paused'));
|
|
chatForm.addEventListener('submit', (e) => {
|
|
e.preventDefault();
|
|
const text = chatInput.value.trim();
|
|
if (!text) return;
|
|
chatInput.value = '';
|
|
sendChat(text);
|
|
});
|
|
|
|
refreshNow();
|
|
loadLibrary();
|
|
loadChat();
|
|
loadSettings();
|
|
loadStats();
|
|
setInterval(() => { refreshNow(); loadStats(); }, 15000);
|
|
</script>
|
|
</body>
|
|
</html>
|