Web: Plex playlist editing, offline art, glass search, NO STEMS tag, artist header fix

- Edit/Rename/Delete on Plex playlists, drag-to-reorder edit mode with the iOS
  remove-then-move-after commit, Remove from playlist, Add to Plex playlists
- Downloads store art blobs with each song and group so it shows offline
- Search box gets a tinted glass blur
- NO STEMS tag restyled and aligned in rows and cards
- Albums header on the artist page no longer overlaps the play button

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-11-20 17:29:03 -08:00
1 parent 3ecfdaa73b
commit 0ef4c650d1
4 files changed
+149 -24

No files matched your search

+98 -11
View File
@@ -3,7 +3,7 @@
import { $, $$, esc, fmtTime, fmtBytes, plural, on, emit, toast, ICON, store, uuid } from "./util.js";
import { S, save, songMixes, saveSongMix, forgetSongMix, playlists, savePlaylists, newPlaylist, addToPlaylist, Offline } from "./store.js";
import { px, img, rawImg, track, sources, liveServers, server, refreshServer, addServer, manualServer, signIn, sortState, pickSort, comparator, sortTracks, Pager, everything } from "./plex.js";
import { px, img, rawImg, track, sources, liveServers, server, refreshServer, addServer, manualServer, signIn, sortState, pickSort, comparator, sortTracks, Pager, everything, pxSend, plexUri } from "./plex.js";
import { Stems, Live, stemNow, stemTrack, stemBase, api } from "./stems.js";
import { E, Q, setting, stemGain, presets, allPresets, presetLabel, applyPreset, currentPreset, nextPreset, savePreset, deletePreset, movePreset, restorePresets, deleteAllCustom, toggleLock,
mixChanged, setKaraoke, setKaraokeMode, sameMix, setSpeed, saveQueue, saveOffline, Radio } from "./player.js";
@@ -768,12 +768,28 @@ function stemItem(tracks) {
}
return { label: tracks.length === 1 ? "Stem Now" : `Stem Now (${need.length})`, run: () => stemNow(tracks) };
}
function pickPlaylist(x, y, tracks, mix = null) {
// Stem playlists live in the browser. Plex playlists take the songs from their own server.
async function pickPlaylist(x, y, tracks, mix = null) {
const add = p => { addToPlaylist(p, tracks, mix); toast(`Added to “${p.title}”${mix ? " with this mix" : ""}`); };
const srv = tracks.find(t => t.srv && t.key)?.srv, pts = tracks.filter(t => t.srv === srv && t.key);
const pls = srv && server(srv) && !mix ? ((await px(srv, "/playlists", { playlistType: "audio" }).catch(() => ({}))).Metadata || []).filter(p => !p.smart) : [];
const toPlex = async (key, title) => {
try {
const uri = await plexUri(srv, pts.map(t => t.key));
if (key) await pxSend(srv, "PUT", `/playlists/${key}/items`, { uri });
else await pxSend(srv, "POST", "/playlists", { type: "audio", title, smart: 0, uri });
Finder.pls = null;
toast(`Added to “${title}”`);
if (location.hash === `#/playlist/${srv}:${key}`) route();
} catch (e) { toast(e.message); }
};
Menu.open(x, y, [
{ head: "Stem playlists" },
{ label: "New stem playlist…", run: () => { const n = prompt("Stem playlist name"); if (n?.trim()) add(newPlaylist(n.trim())); } },
playlists.length && "-",
...playlists.map(p => ({ label: p.title, run: () => add(p) })),
...(srv && server(srv) && !mix ? ["-", { head: `Plex playlists · ${server(srv).name}` },
{ label: "New Plex playlist…", run: () => { const n = prompt("Plex playlist name"); if (n?.trim()) toPlex(null, n.trim()); } },
...pls.map(p => ({ label: p.title, run: () => toPlex(p.ratingKey, p.title) }))] : []),
]);
}
function trackMenu(x, y, listId, i) {
@@ -784,7 +800,7 @@ function trackMenu(x, y, listId, i) {
{ label: "Add to queue", run: () => Q.add([listItems[listId]?.[i] || t]) },
"-",
stemItem([t]),
{ label: "Add to stem playlist…", run: () => pickPlaylist(x, y, [t]) },
{ label: "Add to playlist…", run: () => pickPlaylist(x, y, [t]) },
Offline.has(t.id) ? { label: "Remove download", run: () => Offline.remove(t.id).then(() => emit("offline")) }
: { label: "Download for offline", run: () => download([t]) },
(t.albumKey || t.artistKey) && "-",
@@ -794,6 +810,10 @@ function trackMenu(x, y, listId, i) {
pl && Q.cur()?.id === t.id && E.entry && { label: "Use the current mix here", run: () => { pl.items[i].mix = JSON.parse(JSON.stringify(S.mix)); savePlaylists(); route(); } },
pl && pl.items[i].mix && { label: "Clear this item's mix", run: () => { pl.items[i].mix = null; savePlaylists(); route(); } },
pl && { label: "Remove from playlist", run: () => { pl.items.splice(i, 1); pl.updated = Date.now(); savePlaylists(); route(); } },
listId === "playlist" && curPx?.editable && t.pid != null && "-",
listId === "playlist" && curPx?.editable && t.pid != null && { label: "Remove from playlist", run: async () => {
try { await pxSend(curPx.srv, "DELETE", `/playlists/${curPx.key}/items/${t.pid}`); Finder.pls = null; route(); } catch (e) { toast(e.message); }
} },
]);
}
async function leaves(srv, key) { return ((await px(srv, `/library/metadata/${key}/allLeaves`)).Metadata || []).map(m => track(srv, m)); }
@@ -806,13 +826,14 @@ function listMenu(x, y, get, group = null) {
{ label: "Add to queue", run: run(ts => Q.add(ts)) },
"-",
{ label: "Stem Now", run: run(ts => stemNow(ts)) },
{ label: "Add to stem playlist…", run: run(ts => pickPlaylist(x, y, ts)) },
{ label: "Add to playlist…", run: run(ts => pickPlaylist(x, y, ts)) },
{ label: "Download for offline", run: run(ts => download(ts, group)) },
]);
}
// ---- views --------------------------------------------------------------------------------------
let curPx = null, pxEdit = null;
let lists = {}, listItems = {}, seq = 0, kick = null, genreCache = null;
const visible = tracks => S.stemFilter ? tracks.filter(t => !!Stems.find(t.t || t) === (S.stemFilter === "stems")) : tracks;
function playFrom(listId, i) {
@@ -934,6 +955,7 @@ async function genres() {
const hue = s => [...s].reduce((h, c) => (h * 31 + c.charCodeAt(0)) % 360, 7);
// Downloads the way iOS shows them: Playlists, Albums and Artists as card grids, then loose songs.
let dlUrls = [];
const DL_KINDS = [["Playlists", h => !/^#\/(album|artist)\//.test(h)], ["Albums", h => h.startsWith("#/album/")], ["Artists", h => h.startsWith("#/artist/")]];
function dlGroups(recs) {
const by = new Map(), loose = [];
@@ -945,10 +967,13 @@ function dlGroups(recs) {
}
const gs = [...by.values()];
gs.forEach((x, n) => { x.n = n; x.recs.sort((a, b) => a.saved - b.saved); lists["dl:" + n] = x.recs.map(r => r.track); });
dlUrls.forEach(u => URL.revokeObjectURL(u)); dlUrls = [];
const blobUrl = b => b instanceof Blob ? (dlUrls.push(URL.createObjectURL(b)), dlUrls.at(-1)) : "";
const tile = ({ g, recs, n }) => {
const t = recs[0].track, h = g.href, songs = plural(recs.length, "song");
const art = blobUrl(g.art) || blobUrl(recs.find(r => r.art)?.art) || artOf(recs.find(r => r.track.thumb)?.track, 300);
const s = h.startsWith("#/album/") ? t.artist || "" : h.startsWith("#/artist/") ? songs : `Playlist · ${songs}`;
return card({ href: esc(h), img: artOf(t, 300), t: g.title, s, round: h.startsWith("#/artist/"), dl: n });
return card({ href: esc(h), img: art, t: g.title, s, round: h.startsWith("#/artist/"), dl: n });
};
return DL_KINDS.map(([title, test]) => {
const list = gs.filter(x => test(x.g.href));
@@ -1107,9 +1132,11 @@ const routes = {
const [srv, key] = splitKey(arg);
const [info, items] = await Promise.all([px(srv, `/playlists/${key}`), px(srv, `/playlists/${key}/items`)]);
if (my !== seq) return;
const p = info.Metadata?.[0] || {}, tracks = sortTracks((items.Metadata || []).map(m => track(srv, m)), sortState("playlist"));
view.innerHTML = hero(img(srv, p.thumb || p.composite, 420), "Playlist", p.title, plural(tracks.length, "track"), "playlist", false, p.composite && rawImg(srv, p.composite, 420))
+ `<div class="bar sm"><span class="grow"></span>${stemsChip()}${sortControl("playlist")}</div>` + trackTable("playlist", tracks);
const p = info.Metadata?.[0] || {}, raw = (items.Metadata || []).map(m => track(srv, m)), tracks = sortTracks(raw, sortState("playlist"));
curPx = { srv, key, title: p.title, editable: !p.smart, raw };
const id = esc(arg), tools = p.smart ? " · Smart playlist" : ` · <button class="link" data-pxedit="${id}">Edit</button> · <button class="link" data-pxrename="${id}">Rename</button> · <button class="link" data-pxdelete="${id}">Delete</button>`;
view.innerHTML = hero(img(srv, p.thumb || p.composite, 420), "Playlist", p.title, plural(tracks.length, "track") + tools, "playlist", false, p.composite && rawImg(srv, p.composite, 420))
+ `<div id="pxbody"><div class="bar sm"><span class="grow"></span>${stemsChip()}${sortControl("playlist")}</div>${trackTable("playlist", tracks)}</div>`;
},
async stemplaylist(my, id) {
const p = playlists.find(x => x.id === id);
@@ -1166,6 +1193,7 @@ const routes = {
async function route() {
const my = ++seq;
pxEdit = null; curPx = null;
const [, name = "home", ...rest] = (location.hash || "#/home").split("/");
const arg = decodeURIComponent(rest.join("/"));
$$("#nav a").forEach(a => a.classList.toggle("on", a.dataset.nav === name || (a.dataset.nav === "genres" && name === "genre") || (a.dataset.nav === "playlists" && /playlist$/.test(name))));
@@ -1199,7 +1227,7 @@ view.addEventListener("click", async ev => {
if (!tracks.length) return toast(!all.length ? "Still loading…" : S.stemFilter === "nostems" ? "All of these have stems" : "None of these have stems yet");
return Q.playList(tracks, ds.mode === "shuffle" ? -1 : 0, ds.mode === "shuffle");
}
if (ds.listmenu) { const r = el.getBoundingClientRect(); return listMenu(r.left, r.bottom, async () => listItems[ds.listmenu] || lists[ds.listmenu] || [], { title: $(".hero h1", view)?.textContent || "", href: location.hash }); }
if (ds.listmenu) { const r = el.getBoundingClientRect(); return listMenu(r.left, r.bottom, async () => listItems[ds.listmenu] || lists[ds.listmenu] || [], { title: $(".hero h1", view)?.textContent || "", href: location.hash, art: $(".hero img.art", view)?.src || "" }); }
if (ds.station) {
try {
let ts;
@@ -1237,11 +1265,70 @@ view.addEventListener("click", async ev => {
const ts = (await Promise.all(albums.map(m => leaves(m._srv, m.ratingKey)))).flat();
return Q.playList(visible(ts), -1, true);
}
if (ds.pxrename && curPx) {
const n = prompt("Rename playlist", curPx.title);
if (n?.trim() && n.trim() !== curPx.title) try { await pxSend(curPx.srv, "PUT", `/playlists/${curPx.key}`, { title: n.trim() }); Finder.pls = null; route(); } catch (e) { toast(e.message); }
return;
}
if (ds.pxdelete && curPx) {
if (confirm(`Delete “${curPx.title}” from Plex? This can't be undone.`)) try { await pxSend(curPx.srv, "DELETE", `/playlists/${curPx.key}`); Finder.pls = null; location.hash = "#/playlists"; } catch (e) { toast(e.message); }
return;
}
if (ds.pxedit && curPx) { pxEdit = { orig: curPx.raw, cur: [...curPx.raw] }; drawPxEdit(); return; }
if ("pxcancel" in ds) { pxEdit = null; route(); return; }
if (ds.pxrm != null && pxEdit) { pxEdit.cur.splice(+ds.pxrm, 1); drawPxEdit(); return; }
if ("pxdone" in ds && pxEdit) { el.disabled = true; await commitPxEdit(); return; }
if ("newpl" in ds) { const n = prompt("Stem playlist name"); if (n?.trim()) { newPlaylist(n.trim()); route(); } return; }
if (ds.plrename) { const p = playlists.find(x => x.id === ds.plrename), n = prompt("Rename", p.title); if (n?.trim()) { p.title = n.trim(); savePlaylists(); route(); } return; }
if (ds.pldelete) { if (confirm("Delete this stem playlist?")) { playlists.splice(playlists.findIndex(x => x.id === ds.pldelete), 1); savePlaylists(); location.hash = "#/playlists"; } return; }
if ("dlclear" in ds) { if (confirm("Remove every download?")) { for (const id of [...Offline.ids]) await Offline.remove(id); emit("offline"); route(); } }
});
// ---- Plex playlist edit mode (iOS PlaylistScreens): drag to reorder, remove, then Done ----------
function drawPxEdit() {
const body = $("#pxbody", view);
if (!body || !pxEdit) return;
body.innerHTML = `<div class="bar sm"><span class="note">Drag to reorder</span><span class="grow"></span><button class="chip" data-pxcancel>Cancel</button><button class="chip on" data-pxdone>Done</button></div>
<div class="pxedit">${pxEdit.cur.map((t, i) => `<div class="pxrow" data-i="${i}"><span class="grip" title="Drag">${ICON.queue}</span><img src="${esc(artOf(t, 96))}" alt="" ${FB}><div class="pxt"><b>${esc(t.title)}</b><small>${esc(t.artist)}</small></div><button class="ib bad" data-pxrm="${i}" title="Remove">${ICON.x}</button></div>`).join("") || `<p class="empty-msg">Nothing left. Done will empty the playlist.</p>`}</div>`;
}
// Pointer drag on the grip, so it works with touch too. Only transforms move during the drag.
view.addEventListener("pointerdown", e => {
const g = e.target.closest(".pxrow .grip");
if (!g || !pxEdit) return;
e.preventDefault();
const row = g.parentElement, wrap = row.parentElement, rows = [...wrap.children], from = +row.dataset.i;
const h = row.getBoundingClientRect().height + parseFloat(getComputedStyle(wrap).rowGap || 0), y0 = e.clientY;
let to = from;
row.classList.add("drag"); g.setPointerCapture(e.pointerId);
const move = ev => {
const dy = ev.clientY - y0;
to = Math.max(0, Math.min(rows.length - 1, from + Math.round(dy / h)));
row.style.transform = `translateY(${dy}px)`;
rows.forEach((r, i) => { if (r !== row) r.style.transform = i > from && i <= to ? `translateY(${-h}px)` : i < from && i >= to ? `translateY(${h}px)` : ""; });
};
const up = () => {
g.removeEventListener("pointermove", move); g.removeEventListener("pointerup", up); g.removeEventListener("pointercancel", up);
if (to !== from) pxEdit.cur.splice(to, 0, ...pxEdit.cur.splice(from, 1));
drawPxEdit();
};
g.addEventListener("pointermove", move); g.addEventListener("pointerup", up); g.addEventListener("pointercancel", up);
});
// Removals first, then replay the new order as move-after calls against a simulated list.
async function commitPxEdit() {
const { srv, key } = curPx, keep = new Set(pxEdit.cur.map(t => t.pid));
try {
for (const t of pxEdit.orig) if (!keep.has(t.pid)) await pxSend(srv, "DELETE", `/playlists/${key}/items/${t.pid}`);
const sim = pxEdit.orig.filter(t => keep.has(t.pid)).map(t => t.pid);
for (let i = 0; i < pxEdit.cur.length; i++) {
const pid = pxEdit.cur[i].pid;
if (sim[i] === pid) continue;
const after = i ? pxEdit.cur[i - 1].pid : null;
await pxSend(srv, "PUT", `/playlists/${key}/items/${pid}/move`, { after });
sim.splice(sim.indexOf(pid), 1); sim.splice(i, 0, pid);
}
toast("Playlist saved");
} catch (e) { toast(e.message); }
pxEdit = null; Finder.pls = null; route();
}
async function removeDl(n, what) {
const ts = lists["dl:" + n] || [];
if (!confirm(`Remove ${what} (${plural(ts.length, "download")})? They will no longer play offline.`)) return;
@@ -1263,7 +1350,7 @@ view.addEventListener("contextmenu", ev => {
const row = ev.target.closest("tr[data-list]"), c = ev.target.closest(".card[data-kind]"), d = ev.target.closest(".card[data-dl]");
if (d) { ev.preventDefault(); dlMenu(ev.clientX, ev.clientY, d.dataset.dl, $(".t", d).textContent); }
else if (row) { ev.preventDefault(); trackMenu(ev.clientX, ev.clientY, row.dataset.list, +row.dataset.i); }
else if (c) { ev.preventDefault(); listMenu(ev.clientX, ev.clientY, () => cardTracks(c), { title: $(".t", c).textContent, href: c.getAttribute("href") }); }
else if (c) { ev.preventDefault(); listMenu(ev.clientX, ev.clientY, () => cardTracks(c), { title: $(".t", c).textContent, href: c.getAttribute("href"), art: $("img", c)?.src || "" }); }
});
// ---- settings -----------------------------------------------------------------------------------