Spaces:
Runtime error
Runtime error
Update static/index.html
Browse files- static/index.html +159 -1
static/index.html
CHANGED
|
@@ -247,6 +247,7 @@
|
|
| 247 |
let currentView = "songs";
|
| 248 |
let syncedLyrics = [];
|
| 249 |
let audioCtx, sourceNode, filters = [];
|
|
|
|
| 250 |
async function initApp() {
|
| 251 |
const st = await fetch("/api/status").then(r => r.json()).catch(() => ({configured: false}));
|
| 252 |
if (!st.configured || !st.authorized) {
|
|
@@ -255,6 +256,7 @@
|
|
| 255 |
await loadCatalogue();
|
| 256 |
}
|
| 257 |
}
|
|
|
|
| 258 |
async function loadCatalogue() {
|
| 259 |
catalogue = await fetch("/api/catalogue").then(r => r.json());
|
| 260 |
document.getElementById("countSongs").innerText = catalogue.length;
|
|
@@ -263,18 +265,21 @@
|
|
| 263 |
document.getElementById("countHiRes").innerText = catalogue.filter(t => t.bit_depth >= 24).length;
|
| 264 |
renderCatalogue();
|
| 265 |
}
|
|
|
|
| 266 |
function setView(view, btn) {
|
| 267 |
currentView = view;
|
| 268 |
document.querySelectorAll(".nav-btn").forEach(b => b.classList.remove("active"));
|
| 269 |
if (btn) btn.classList.add("active");
|
| 270 |
renderCatalogue();
|
| 271 |
}
|
|
|
|
| 272 |
function formatTime(sec) {
|
| 273 |
if (!sec || isNaN(sec)) return "0:00";
|
| 274 |
const m = Math.floor(sec / 60);
|
| 275 |
const s = Math.floor(sec % 60).toString().padStart(2, "0");
|
| 276 |
return `${m}:${s}`;
|
| 277 |
}
|
|
|
|
| 278 |
function renderCatalogue() {
|
| 279 |
const q = document.getElementById("searchInput").value.toLowerCase();
|
| 280 |
const box = document.getElementById("catalogueContent");
|
|
@@ -284,10 +289,13 @@
|
|
| 284 |
t.album.toLowerCase().includes(q) ||
|
| 285 |
`${t.bit_depth}-bit`.includes(q)
|
| 286 |
);
|
|
|
|
| 287 |
if (currentView === "hires") {
|
| 288 |
list = list.filter(t => t.bit_depth >= 24);
|
| 289 |
}
|
|
|
|
| 290 |
filteredQueue = list;
|
|
|
|
| 291 |
if (currentView === "albums") {
|
| 292 |
const albums = {};
|
| 293 |
list.forEach(t => {
|
|
@@ -302,6 +310,7 @@
|
|
| 302 |
`).join("") + `</div>`;
|
| 303 |
return;
|
| 304 |
}
|
|
|
|
| 305 |
box.innerHTML = list.map((t, idx) => {
|
| 306 |
const khz = (t.sample_rate / 1000).toFixed(1).replace(".0", "");
|
| 307 |
return `
|
|
@@ -318,26 +327,31 @@
|
|
| 318 |
`;
|
| 319 |
}).join("");
|
| 320 |
}
|
|
|
|
| 321 |
function filterByText(txt) {
|
| 322 |
document.getElementById("searchInput").value = txt;
|
| 323 |
setView("songs");
|
| 324 |
}
|
|
|
|
| 325 |
function playIndex(idx) {
|
| 326 |
if (idx < 0 || idx >= filteredQueue.length) return;
|
| 327 |
currentIndex = idx;
|
| 328 |
const t = filteredQueue[idx];
|
| 329 |
const khz = (t.sample_rate / 1000).toFixed(1).replace(".0", "");
|
|
|
|
| 330 |
document.getElementById("nowTitle").innerText = t.title;
|
| 331 |
document.getElementById("nowArtist").innerText = `${t.artist} — ${t.album}`;
|
| 332 |
document.getElementById("nowBadge").innerText = `${t.bit_depth}-BIT / ${khz}kHz LOSSLESS`;
|
| 333 |
const coverUrl = `/api/cover/${t.msg_id}`;
|
| 334 |
document.getElementById("nowCover").src = coverUrl;
|
| 335 |
document.getElementById("ambientBg").style.backgroundImage = `url(${coverUrl})`;
|
|
|
|
| 336 |
audio.src = `/api/stream/${t.msg_id}`;
|
| 337 |
audio.play();
|
| 338 |
document.getElementById("playPauseBtn").innerText = "⏸";
|
| 339 |
renderCatalogue();
|
| 340 |
loadLyrics(t.title, t.artist);
|
|
|
|
| 341 |
if ('mediaSession' in navigator) {
|
| 342 |
navigator.mediaSession.metadata = new MediaMetadata({
|
| 343 |
title: t.title, artist: t.artist, album: t.album,
|
|
@@ -345,14 +359,17 @@
|
|
| 345 |
});
|
| 346 |
}
|
| 347 |
}
|
|
|
|
| 348 |
function togglePlay() {
|
| 349 |
if (!audio.src && filteredQueue.length) return playIndex(0);
|
| 350 |
if (audio.paused) { audio.play(); document.getElementById("playPauseBtn").innerText = "⏸"; }
|
| 351 |
else { audio.pause(); document.getElementById("playPauseBtn").innerText = "▶"; }
|
| 352 |
}
|
|
|
|
| 353 |
function nextTrack() { if (currentIndex + 1 < filteredQueue.length) playIndex(currentIndex + 1); }
|
| 354 |
function prevTrack() { if (currentIndex - 1 >= 0) playIndex(currentIndex - 1); }
|
| 355 |
audio.onended = () => nextTrack();
|
|
|
|
| 356 |
audio.ontimeupdate = () => {
|
| 357 |
document.getElementById("curTime").innerText = formatTime(audio.currentTime);
|
| 358 |
document.getElementById("durTime").innerText = formatTime(audio.duration);
|
|
@@ -370,4 +387,145 @@
|
|
| 370 |
} else {
|
| 371 |
item.el.classList.remove("active");
|
| 372 |
}
|
| 373 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
let currentView = "songs";
|
| 248 |
let syncedLyrics = [];
|
| 249 |
let audioCtx, sourceNode, filters = [];
|
| 250 |
+
|
| 251 |
async function initApp() {
|
| 252 |
const st = await fetch("/api/status").then(r => r.json()).catch(() => ({configured: false}));
|
| 253 |
if (!st.configured || !st.authorized) {
|
|
|
|
| 256 |
await loadCatalogue();
|
| 257 |
}
|
| 258 |
}
|
| 259 |
+
|
| 260 |
async function loadCatalogue() {
|
| 261 |
catalogue = await fetch("/api/catalogue").then(r => r.json());
|
| 262 |
document.getElementById("countSongs").innerText = catalogue.length;
|
|
|
|
| 265 |
document.getElementById("countHiRes").innerText = catalogue.filter(t => t.bit_depth >= 24).length;
|
| 266 |
renderCatalogue();
|
| 267 |
}
|
| 268 |
+
|
| 269 |
function setView(view, btn) {
|
| 270 |
currentView = view;
|
| 271 |
document.querySelectorAll(".nav-btn").forEach(b => b.classList.remove("active"));
|
| 272 |
if (btn) btn.classList.add("active");
|
| 273 |
renderCatalogue();
|
| 274 |
}
|
| 275 |
+
|
| 276 |
function formatTime(sec) {
|
| 277 |
if (!sec || isNaN(sec)) return "0:00";
|
| 278 |
const m = Math.floor(sec / 60);
|
| 279 |
const s = Math.floor(sec % 60).toString().padStart(2, "0");
|
| 280 |
return `${m}:${s}`;
|
| 281 |
}
|
| 282 |
+
|
| 283 |
function renderCatalogue() {
|
| 284 |
const q = document.getElementById("searchInput").value.toLowerCase();
|
| 285 |
const box = document.getElementById("catalogueContent");
|
|
|
|
| 289 |
t.album.toLowerCase().includes(q) ||
|
| 290 |
`${t.bit_depth}-bit`.includes(q)
|
| 291 |
);
|
| 292 |
+
|
| 293 |
if (currentView === "hires") {
|
| 294 |
list = list.filter(t => t.bit_depth >= 24);
|
| 295 |
}
|
| 296 |
+
|
| 297 |
filteredQueue = list;
|
| 298 |
+
|
| 299 |
if (currentView === "albums") {
|
| 300 |
const albums = {};
|
| 301 |
list.forEach(t => {
|
|
|
|
| 310 |
`).join("") + `</div>`;
|
| 311 |
return;
|
| 312 |
}
|
| 313 |
+
|
| 314 |
box.innerHTML = list.map((t, idx) => {
|
| 315 |
const khz = (t.sample_rate / 1000).toFixed(1).replace(".0", "");
|
| 316 |
return `
|
|
|
|
| 327 |
`;
|
| 328 |
}).join("");
|
| 329 |
}
|
| 330 |
+
|
| 331 |
function filterByText(txt) {
|
| 332 |
document.getElementById("searchInput").value = txt;
|
| 333 |
setView("songs");
|
| 334 |
}
|
| 335 |
+
|
| 336 |
function playIndex(idx) {
|
| 337 |
if (idx < 0 || idx >= filteredQueue.length) return;
|
| 338 |
currentIndex = idx;
|
| 339 |
const t = filteredQueue[idx];
|
| 340 |
const khz = (t.sample_rate / 1000).toFixed(1).replace(".0", "");
|
| 341 |
+
|
| 342 |
document.getElementById("nowTitle").innerText = t.title;
|
| 343 |
document.getElementById("nowArtist").innerText = `${t.artist} — ${t.album}`;
|
| 344 |
document.getElementById("nowBadge").innerText = `${t.bit_depth}-BIT / ${khz}kHz LOSSLESS`;
|
| 345 |
const coverUrl = `/api/cover/${t.msg_id}`;
|
| 346 |
document.getElementById("nowCover").src = coverUrl;
|
| 347 |
document.getElementById("ambientBg").style.backgroundImage = `url(${coverUrl})`;
|
| 348 |
+
|
| 349 |
audio.src = `/api/stream/${t.msg_id}`;
|
| 350 |
audio.play();
|
| 351 |
document.getElementById("playPauseBtn").innerText = "⏸";
|
| 352 |
renderCatalogue();
|
| 353 |
loadLyrics(t.title, t.artist);
|
| 354 |
+
|
| 355 |
if ('mediaSession' in navigator) {
|
| 356 |
navigator.mediaSession.metadata = new MediaMetadata({
|
| 357 |
title: t.title, artist: t.artist, album: t.album,
|
|
|
|
| 359 |
});
|
| 360 |
}
|
| 361 |
}
|
| 362 |
+
|
| 363 |
function togglePlay() {
|
| 364 |
if (!audio.src && filteredQueue.length) return playIndex(0);
|
| 365 |
if (audio.paused) { audio.play(); document.getElementById("playPauseBtn").innerText = "⏸"; }
|
| 366 |
else { audio.pause(); document.getElementById("playPauseBtn").innerText = "▶"; }
|
| 367 |
}
|
| 368 |
+
|
| 369 |
function nextTrack() { if (currentIndex + 1 < filteredQueue.length) playIndex(currentIndex + 1); }
|
| 370 |
function prevTrack() { if (currentIndex - 1 >= 0) playIndex(currentIndex - 1); }
|
| 371 |
audio.onended = () => nextTrack();
|
| 372 |
+
|
| 373 |
audio.ontimeupdate = () => {
|
| 374 |
document.getElementById("curTime").innerText = formatTime(audio.currentTime);
|
| 375 |
document.getElementById("durTime").innerText = formatTime(audio.duration);
|
|
|
|
| 387 |
} else {
|
| 388 |
item.el.classList.remove("active");
|
| 389 |
}
|
| 390 |
+
});
|
| 391 |
+
};
|
| 392 |
+
|
| 393 |
+
function seekTo(pct) {
|
| 394 |
+
if (audio.duration) audio.currentTime = (pct / 100) * audio.duration;
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
async function loadLyrics(title, artist) {
|
| 398 |
+
const pane = document.getElementById("lyricsPane");
|
| 399 |
+
pane.innerHTML = `<p style="opacity:0.5;">Fetching time-synced lyrics...</p>`;
|
| 400 |
+
syncedLyrics = [];
|
| 401 |
+
try {
|
| 402 |
+
const res = await fetch(`https://lrclib.net/api/search?q=${encodeURIComponent(title + " " + artist)}`);
|
| 403 |
+
const data = await res.json();
|
| 404 |
+
const found = data.find(d => d.syncedLyrics);
|
| 405 |
+
if (!found) { pane.innerHTML = `<p style="opacity:0.5;">No synced lyrics found for this track.</p>`; return; }
|
| 406 |
+
pane.innerHTML = "";
|
| 407 |
+
found.syncedLyrics.split("\n").forEach(line => {
|
| 408 |
+
const m = line.match(/\[(\d+):(\d+\.\d+)\](.*)/);
|
| 409 |
+
if (m) {
|
| 410 |
+
const time = parseInt(m[1]) * 60 + parseFloat(m[2]);
|
| 411 |
+
const text = m[3].trim();
|
| 412 |
+
if (text) {
|
| 413 |
+
const div = document.createElement("div");
|
| 414 |
+
div.className = "lyric-line";
|
| 415 |
+
div.innerText = text;
|
| 416 |
+
div.onclick = () => { audio.currentTime = time; };
|
| 417 |
+
pane.appendChild(div);
|
| 418 |
+
syncedLyrics.push({ time, el: div });
|
| 419 |
+
}
|
| 420 |
+
}
|
| 421 |
+
});
|
| 422 |
+
} catch (e) {
|
| 423 |
+
pane.innerHTML = `<p style="opacity:0.5;">Lyrics service unreachable.</p>`;
|
| 424 |
+
}
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
function toggleBitPerfect() {
|
| 428 |
+
const bp = document.getElementById("bitPerfectToggle").checked;
|
| 429 |
+
const ctrl = document.getElementById("dspControls");
|
| 430 |
+
if (bp) {
|
| 431 |
+
ctrl.style.opacity = "0.4";
|
| 432 |
+
ctrl.style.pointerEvents = "none";
|
| 433 |
+
filters.forEach(f => f.gain.value = 0);
|
| 434 |
+
} else {
|
| 435 |
+
ctrl.style.opacity = "1";
|
| 436 |
+
ctrl.style.pointerEvents = "auto";
|
| 437 |
+
if (!audioCtx) {
|
| 438 |
+
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
| 439 |
+
sourceNode = audioCtx.createMediaElementSource(audio);
|
| 440 |
+
const freqs = [60, 250, 1000, 4000, 12000];
|
| 441 |
+
const ids = ["eq60", "eq250", "eq1k", "eq4k", "eq12k"];
|
| 442 |
+
let prev = sourceNode;
|
| 443 |
+
freqs.forEach((f, idx) => {
|
| 444 |
+
const node = audioCtx.createBiquadFilter();
|
| 445 |
+
node.type = idx === 0 ? "lowshelf" : idx === 4 ? "highshelf" : "peaking";
|
| 446 |
+
node.frequency.value = f;
|
| 447 |
+
prev.connect(node);
|
| 448 |
+
prev = node;
|
| 449 |
+
filters.push(node);
|
| 450 |
+
document.getElementById(ids[idx]).oninput = e => node.gain.value = parseFloat(e.target.value);
|
| 451 |
+
});
|
| 452 |
+
prev.connect(audioCtx.destination);
|
| 453 |
+
}
|
| 454 |
+
}
|
| 455 |
+
}
|
| 456 |
+
|
| 457 |
+
function startSmartRadio() {
|
| 458 |
+
if (currentIndex < 0) return;
|
| 459 |
+
const seed = filteredQueue[currentIndex];
|
| 460 |
+
// Smart Radio: prioritizes same genre/artist or similar bit-depth lossless tracks
|
| 461 |
+
const radioQueue = [seed, ...catalogue.filter(t => t.msg_id !== seed.msg_id).sort((a, b) => {
|
| 462 |
+
const scoreA = (a.artist === seed.artist ? 3 : 0) + (a.genre === seed.genre ? 2 : 0) + Math.random();
|
| 463 |
+
const scoreB = (b.artist === seed.artist ? 3 : 0) + (b.genre === seed.genre ? 2 : 0) + Math.random();
|
| 464 |
+
return scoreB - scoreA;
|
| 465 |
+
})];
|
| 466 |
+
filteredQueue = radioQueue;
|
| 467 |
+
currentIndex = 0;
|
| 468 |
+
renderCatalogue();
|
| 469 |
+
}
|
| 470 |
+
|
| 471 |
+
function switchRightTab(tab) {
|
| 472 |
+
document.getElementById("lyricsPane").style.display = tab === "lyrics" ? "block" : "none";
|
| 473 |
+
document.getElementById("eqPane").style.display = tab === "eq" ? "block" : "none";
|
| 474 |
+
document.getElementById("tabLyricsBtn").classList.toggle("active", tab === "lyrics");
|
| 475 |
+
document.getElementById("tabEqBtn").classList.toggle("active", tab === "eq");
|
| 476 |
+
}
|
| 477 |
+
|
| 478 |
+
async function syncTelegram() {
|
| 479 |
+
const btn = document.getElementById("syncBtn");
|
| 480 |
+
btn.innerText = "⏳ Indexing FLAC Headers...";
|
| 481 |
+
const res = await fetch("/api/sync", { method: "POST" });
|
| 482 |
+
if (res.ok) {
|
| 483 |
+
await loadCatalogue();
|
| 484 |
+
btn.innerText = "✓ Vault Synced";
|
| 485 |
+
setTimeout(() => btn.innerText = "↻ Sync Telegram Vault", 2500);
|
| 486 |
+
} else {
|
| 487 |
+
btn.innerText = "⚠ Auth Required";
|
| 488 |
+
openSetupModal();
|
| 489 |
+
}
|
| 490 |
+
}
|
| 491 |
+
|
| 492 |
+
function openSetupModal() { document.getElementById("setupModal").style.display = "flex"; }
|
| 493 |
+
function closeSetupModal() { document.getElementById("setupModal").style.display = "none"; }
|
| 494 |
+
|
| 495 |
+
let awaitingOtp = false;
|
| 496 |
+
async function submitSetup() {
|
| 497 |
+
const api_id = parseInt(document.getElementById("inpApiId").value);
|
| 498 |
+
const api_hash = document.getElementById("inpApiHash").value.trim();
|
| 499 |
+
const channel_id = parseInt(document.getElementById("inpChannelId").value);
|
| 500 |
+
const phone = document.getElementById("inpPhone").value.trim();
|
| 501 |
+
|
| 502 |
+
if (!awaitingOtp) {
|
| 503 |
+
const res = await fetch("/api/auth/send_code", {
|
| 504 |
+
method: "POST", headers: { "Content-Type": "application/json" },
|
| 505 |
+
body: JSON.stringify({ api_id, api_hash, channel_id, phone })
|
| 506 |
+
}).then(r => r.json());
|
| 507 |
+
if (res.status === "code_sent") {
|
| 508 |
+
awaitingOtp = true;
|
| 509 |
+
document.getElementById("otpBox").style.display = "block";
|
| 510 |
+
document.getElementById("setupSubmitBtn").innerText = "Verify OTP & Connect";
|
| 511 |
+
} else if (res.status === "already_authorized") {
|
| 512 |
+
closeSetupModal();
|
| 513 |
+
syncTelegram();
|
| 514 |
+
}
|
| 515 |
+
} else {
|
| 516 |
+
const code = document.getElementById("inpOtp").value.trim();
|
| 517 |
+
const res = await fetch("/api/auth/verify", {
|
| 518 |
+
method: "POST", headers: { "Content-Type": "application/json" },
|
| 519 |
+
body: JSON.stringify({ phone, code })
|
| 520 |
+
});
|
| 521 |
+
if (res.ok) {
|
| 522 |
+
closeSetupModal();
|
| 523 |
+
syncTelegram();
|
| 524 |
+
}
|
| 525 |
+
}
|
| 526 |
+
}
|
| 527 |
+
|
| 528 |
+
initApp();
|
| 529 |
+
</script>
|
| 530 |
+
</body>
|
| 531 |
+
</html>
|