Add shuffle dashboard with cost tracking and daily generation limits.
Player settings panel, stats API, and README document how saved and new tracks mix under a per-day Lyria cap. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+369
-31
@@ -35,6 +35,33 @@
|
||||
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;
|
||||
@@ -55,9 +82,116 @@
|
||||
.tagline {
|
||||
color: var(--muted);
|
||||
font-size: 0.85rem;
|
||||
margin-bottom: 1.5rem;
|
||||
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;
|
||||
@@ -79,6 +213,7 @@
|
||||
.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; }
|
||||
@@ -247,10 +382,69 @@
|
||||
</head>
|
||||
<body>
|
||||
<div class="radio">
|
||||
<div class="badge">● Live</div>
|
||||
<h1>Ozan Radio</h1>
|
||||
<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>
|
||||
@@ -287,7 +481,7 @@
|
||||
</section>
|
||||
|
||||
<div class="stack">
|
||||
DJ: DeepSeek · Music: Google Lyria 3 · Taste: Spotify (read-only)<br>
|
||||
DJ: DeepSeek · Music: Google Lyria 3 · Taste: settings.json<br>
|
||||
Optional live layer: Magenta RealTime 2 on Apple Silicon
|
||||
</div>
|
||||
</div>
|
||||
@@ -295,6 +489,7 @@
|
||||
<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');
|
||||
@@ -307,7 +502,142 @@
|
||||
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;
|
||||
|
||||
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 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);
|
||||
}
|
||||
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() {
|
||||
try {
|
||||
const res = await fetch(`${API}/api/stats`);
|
||||
const data = await res.json();
|
||||
updateDashboard(data);
|
||||
} 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 {
|
||||
@@ -337,14 +667,7 @@
|
||||
const res = await fetch(`${API}/api/songs/${trackId}/play`, { method: 'POST' });
|
||||
const data = await res.json();
|
||||
if (data.status === 'ok' && data.track) {
|
||||
currentTrackId = data.track.track_id;
|
||||
titleEl.textContent = data.track.title;
|
||||
moodEl.textContent = data.track.mood ? `Mood: ${data.track.mood}` : '';
|
||||
djEl.textContent = data.track.dj_line ? `"${data.track.dj_line}"` : '';
|
||||
player.src = `${API}${data.track.audio_url}`;
|
||||
player.play().catch(() => {});
|
||||
statusEl.textContent = `Playing · ${data.track.track_id}`;
|
||||
loadLibrary();
|
||||
applyTrack(data.track, 'library');
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
@@ -400,6 +723,7 @@
|
||||
pollTimer = setInterval(async () => {
|
||||
n += 1;
|
||||
await refreshNow();
|
||||
await loadStats();
|
||||
if (n > 60) clearInterval(pollTimer);
|
||||
}, 5000);
|
||||
}
|
||||
@@ -415,16 +739,7 @@
|
||||
statusEl.textContent = data.message || 'Idle';
|
||||
return;
|
||||
}
|
||||
const t = data.track;
|
||||
currentTrackId = t.track_id;
|
||||
titleEl.textContent = t.title;
|
||||
moodEl.textContent = t.mood ? `Mood: ${t.mood}` : '';
|
||||
djEl.textContent = t.dj_line ? `"${t.dj_line}"` : '';
|
||||
if (t.audio_url && player.src !== `${API}${t.audio_url}`) {
|
||||
player.src = `${API}${t.audio_url}`;
|
||||
player.play().catch(() => {});
|
||||
}
|
||||
statusEl.textContent = `Playing · ${t.track_id}`;
|
||||
applyTrack(data.track);
|
||||
} catch (e) {
|
||||
statusEl.textContent = 'Server offline — start: python -m ozan_radio';
|
||||
}
|
||||
@@ -438,9 +753,12 @@
|
||||
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 === 'ok') {
|
||||
await refreshNow();
|
||||
await loadLibrary();
|
||||
if (data.track) applyTrack(data.track, data.source || 'generated');
|
||||
await loadStats();
|
||||
} else {
|
||||
statusEl.textContent = 'Generation failed — check server logs';
|
||||
}
|
||||
@@ -451,20 +769,38 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function skip() {
|
||||
async function nextTrack() {
|
||||
skipBtn.disabled = true;
|
||||
const shuffle = radioSettings.playback?.shuffle;
|
||||
try {
|
||||
await fetch(`${API}/api/skip`, { method: 'POST' });
|
||||
await refreshNow();
|
||||
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;
|
||||
pollForNewTrack();
|
||||
return;
|
||||
} 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', skip);
|
||||
refreshBtn.addEventListener('click', refreshNow);
|
||||
player.addEventListener('ended', () => { skip(); });
|
||||
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();
|
||||
@@ -476,7 +812,9 @@
|
||||
refreshNow();
|
||||
loadLibrary();
|
||||
loadChat();
|
||||
setInterval(refreshNow, 15000);
|
||||
loadSettings();
|
||||
loadStats();
|
||||
setInterval(() => { refreshNow(); loadStats(); }, 15000);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
Before
After
|
Reference in New Issue
Block a user