diff --git a/web/app.js b/web/app.js index fa66a10..f50f2a8 100644 --- a/web/app.js +++ b/web/app.js @@ -662,14 +662,27 @@ view.addEventListener("click", ev => { if (act) { const tracks = lists[act.dataset.play]; if (act.dataset.mode === "queue") Q.add(tracks); + else if (act.dataset.mode === "stem") stemNow(tracks); else Q.playList(tracks, act.dataset.mode === "shuffle" ? -1 : 0, act.dataset.mode === "shuffle"); } }); +async function stemNow(tracks) { + const seen = new Set(); + const paths = tracks.filter(t => t.file && !Stems.find(t) && !seen.has(t.file) && seen.add(t.file)).map(t => t.file); + if (!paths.length) return toast("Already has stems"); + try { + const r = await fetch(stemBase() + "/api/stem" + stemQuery(), { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ paths }) }); + const j = await r.json().catch(() => ({})); + toast(r.ok ? `Stemming ${paths.length === 1 ? "1 track" : paths.length + " tracks"} next` : `Couldn't queue: ${j.error || r.status}`); + } catch (e) { toast("Couldn't queue: " + e.message); } +} + const playButtons = id => `
-
`; + + `; function needPlex() { view.innerHTML = `

Welcome

Sign in to Plex in Settings to browse your library, or open Stems only.

`;