Discord Rich Presence, album folder moves and TheAudioDB logos

- Discord: listening status with cover, artist and progress; choose what your status names; optional own Discord app with a Save the images button
- Songs given an album move from Tracks into that album's folder with their lyrics and video; single downloads join an existing album folder
- Artist logos, photos and bios from TheAudioDB too, with logos in the Search online picker
This commit is contained in:
Christian
2026-11-20 00:24:27 -05:00
parent 0997dc7d34
commit dc8e489c90
13 changed files with 1088 additions and 41 deletions
+2
View File
@@ -238,6 +238,7 @@ async function init() {
bindMini();
bindConnect();
bindUpdates();
bindDiscord();
bindPlaybackSettings();
bindSearch();
bindTools();
@@ -1548,6 +1549,7 @@ function renderSettings() {
renderSignin();
if (typeof renderPlaybackSettings === "function") renderPlaybackSettings();
if (typeof renderApiSettings === "function") renderApiSettings();
if (typeof renderDiscordSettings === "function") renderDiscordSettings();
renderToolSettings();
renderLibrarySettings();
renderLyricsSettings();
+98
View File
@@ -0,0 +1,98 @@
// atmosphere · discord.js · Shares what's playing with Discord and runs the Discord settings
const Dsc = { timer: 0, last: "" };
const DISCORD_PORTAL = "https://discord.com/developers/applications";
function discordSnapshot() {
const t = Player.current;
if (!t) return null;
const a = Player.audio;
const dur = Number.isFinite(a.duration) && a.duration > 0 ? a.duration * 1000 : t.durationMs || 0;
return { title: t.title || "", artist: t.artist || "", album: t.album || "", durationMs: Math.round(dur), positionMs: Math.round((a.currentTime || 0) * 1000), playing: !a.paused };
}
function discordSoon(force = false) {
clearTimeout(Dsc.timer);
Dsc.timer = setTimeout(() => {
const now = discordSnapshot();
const key = JSON.stringify(now && { ...now, positionMs: Math.round(now.positionMs / 2000) });
if (!force && key === Dsc.last) return;
Dsc.last = key;
invoke("discord_now", { now }).catch(() => {});
}, 300);
}
const DISCORD_TEXT = {
off: ["Off. Nothing is shared with Discord.", ""],
noid: ["Add your Discord application ID below to turn this on.", "err"],
connecting: ["Connecting to Discord…", ""],
waiting: ["Waiting for Discord. Open the Discord app on this computer and it connects by itself.", ""],
};
function renderDiscordStatus(st) {
const el = $("#discordStatus");
if (!el || !st) return;
const [text, kind] = DISCORD_TEXT[st.state] || [st.error || "Couldn't reach Discord.", "err"];
if (st.state === "connected") {
el.textContent = st.error ? `Connected, but Discord said: ${st.error}` : `Connected${st.user ? ` as ${st.user}` : ""}. Your status shows what you're playing.`;
el.dataset.kind = st.error ? "err" : "ok";
} else {
el.textContent = text;
el.dataset.kind = kind;
}
$("#discordClientId").placeholder = st.builtinId ? "Atmosphere's own" : "Required";
}
async function renderDiscordSettings() {
const s = state.settings;
if (!s || !$("#discordStatus")) return;
$$("[data-seg=discordStatus] button").forEach((b) => b.setAttribute("aria-pressed", String(b.dataset.value === (s.discordStatus || "app"))));
$$(".discord-opt").forEach((row) => row.classList.toggle("dim", !s.discordEnabled));
const id = $("#discordClientId");
if (document.activeElement !== id) id.value = s.discordClientId || "";
renderDiscordStatus(await invoke("discord_status").catch(() => null));
}
async function saveDiscordId(e) {
const v = e.target.value.trim();
if (v && !/^\d{15,25}$/.test(v)) {
toast("An application ID is a long number. Copy it from your app's General Information page.", "err");
e.target.value = state.settings.discordClientId || "";
return;
}
if (v === (state.settings.discordClientId || "")) return;
await patch({ discordClientId: v });
renderDiscordSettings();
}
async function saveDiscordAssets(btn) {
btn.classList.add("loading");
try {
const dir = await invoke("discord_save_assets");
if (dir) {
toast("Saved the images and a short how-to", "ok");
invoke("reveal", { path: dir }).catch(() => {});
}
} catch (e) {
toast(errText(e), "err");
} finally {
btn.classList.remove("loading");
}
}
function bindDiscord() {
window.addEventListener("player", (e) => {
const type = e.detail.type;
if (type === "track" || type === "state") discordSoon();
});
Player.on("seeked", () => discordSoon(true));
Player.on("loadedmetadata", () => discordSoon(true));
setInterval(() => discordSoon(), 15000);
listen("atmosphere://discord", (e) => renderDiscordStatus(e.payload));
$("#discordToggle")?.addEventListener("change", () => setTimeout(() => { renderDiscordSettings(); discordSoon(true); }, 300));
$$("[data-seg=discordStatus] button").forEach((b) => b.addEventListener("click", () => patch({ discordStatus: b.dataset.value }).then(renderDiscordSettings)));
$("#discordClientId")?.addEventListener("change", saveDiscordId);
$("#discordPortal")?.addEventListener("click", () => invoke("open_link", { url: DISCORD_PORTAL }).catch(() => {}));
$("#discordAssets")?.addEventListener("click", (e) => saveDiscordAssets(e.currentTarget));
discordSoon(true);
renderDiscordSettings();
}
+25 -1
View File
@@ -204,7 +204,7 @@
<div class="group" id="libFolders"></div>
<div class="group gap-top">
<div class="setting"><div><strong>Playlist folders live in</strong><span id="playlistsDir"></span></div></div>
<label class="setting"><div><strong>Find artist photos, bios and logos</strong><span>Looks up artist names on Deezer, Wikipedia and Wikidata, which need no account or key. Nothing else is sent, and you can change or remove anything on an artist's page.</span></div><input type="checkbox" class="switch" data-key="artistInfo" /></label>
<label class="setting"><div><strong>Find artist photos, bios and logos</strong><span>Looks up artist names on Deezer, Wikipedia, Wikidata and TheAudioDB, which need no account or key. Nothing else is sent, and you can change or remove anything on an artist's page.</span></div><input type="checkbox" class="switch" data-key="artistInfo" /></label>
<div class="setting" id="hiddenSongs"></div>
<label class="setting"><div><strong>Copy songs into playlists</strong><span>Off: songs are hard-linked, so they appear in the folder without using extra space (same drive only). On: real copies, which are best for syncing to phones and USB drives.</span></div><input type="checkbox" class="switch" data-key="playlistCopy" /></label>
</div>
@@ -285,6 +285,29 @@
<label class="setting"><div><strong>Offer copied links</strong><span>When you switch to Atmosphere with a link copied, offer to fetch it.</span></div><input type="checkbox" class="switch" data-key="watchClipboard" /></label>
</div>
<h2 id="set-discord">Discord</h2>
<div class="group">
<label class="setting"><div><strong>Show what you're listening to</strong><span class="api-status" id="discordStatus" role="status">Off. Nothing is shared with Discord.</span></div><input type="checkbox" class="switch" data-key="discordEnabled" id="discordToggle" /></label>
<div class="setting discord-opt">
<div><strong>Your status says</strong><span>What people see under your name, like "Listening to Atmosphere". The song, artist and progress always show on your profile.</span></div>
<div class="seg" data-seg="discordStatus"><button type="button" data-value="app">Atmosphere</button><button type="button" data-value="artist">Artist</button><button type="button" data-value="song">Song</button></div>
</div>
<label class="setting discord-opt"><div><strong>Show cover art</strong><span>Discord can only show pictures from the web, so Atmosphere looks the song up on Deezer (only the artist and title are sent). Off: the Atmosphere logo is shown.</span></div><input type="checkbox" class="switch" data-key="discordCover" /></label>
<label class="setting discord-opt"><div><strong>Keep showing while paused</strong><span>Off: your status clears when you pause and comes back when you press play.</span></div><input type="checkbox" class="switch" data-key="discordPaused" /></label>
<details class="setting advanced discord-opt">
<summary><strong>Your own Discord app</strong><span>Shows your app's name and art instead, like "Listening to My Music". Leave the ID blank to use Atmosphere's.</span></summary>
<div class="adv-fields">
<ol class="discord-steps">
<li>Create an application in the <button class="link" id="discordPortal" type="button">Discord Developer Portal</button>. Its name is what your status shows.</li>
<li>Save the images, then upload both under <strong>Rich Presence › Art Assets</strong> without renaming them.</li>
<li>Paste the <strong>Application ID</strong> from <strong>General Information</strong> here.</li>
</ol>
<div class="discord-assets"><button class="btn" id="discordAssets" type="button"><span class="label">Save the images…</span><span class="spin" aria-hidden="true"></span></button><span class="muted small">You choose the folder. Includes the logo, the paused badge and these steps.</span></div>
<label><span>Application ID</span><input class="text" id="discordClientId" placeholder="Atmosphere's own" inputmode="numeric" spellcheck="false" autocomplete="off" /></label>
</div>
</details>
</div>
<h2 id="set-api">Connections</h2>
<p class="set-note">Let other apps on this computer, like stream overlays, status tools or your own scripts, see what's playing and control Atmosphere. It stays off unless you turn it on.</p>
<div class="group">
@@ -400,5 +423,6 @@
<script src="updates.js"></script>
<script src="search.js"></script>
<script src="tools.js"></script>
<script src="discord.js"></script>
</body>
</html>
+16 -6
View File
@@ -655,15 +655,17 @@ function queueLibraryArtists() {
}
async function searchArtistOnline(ar) {
let pick = { photo: null, page: null };
let pick = { photo: null, page: null, logo: null };
const input = h("input", { class: "text wide", type: "search", value: ar.name, "aria-label": "Search for this artist", spellcheck: "false" });
const photos = h("div", { class: "pick-photos" });
const pages = h("div", { class: "pick-pages" });
const logos = h("div", { class: "pick-logos" });
const logoHead = h("strong", { class: "pick-head" }, "Logos from TheAudioDB");
const status = h("p", { class: "muted small" }, "Searching…");
const fans = (n) => (n >= 1e6 ? `${(n / 1e6).toFixed(1)}M fans` : n >= 1e3 ? `${Math.round(n / 1e3)}K fans` : `${n} fans`);
const run = async () => {
status.textContent = "Searching…";
pick = { photo: null, page: null };
pick = { photo: null, page: null, logo: null };
const r = await invoke("artist_choices", { query: input.value }).catch((e) => (status.textContent = errText(e), null));
if (!r) return;
photos.replaceChildren(...r.photos.map((p) => {
@@ -676,19 +678,27 @@ async function searchArtistOnline(ar) {
h("strong", {}, p.title), h("span", {}, p.description || "No description"));
return el;
}));
status.textContent = r.photos.length || r.pages.length ? "Pick a photo, a Wikipedia page for the bio and logo, or both." : "Nothing found. Try a different spelling.";
const lg = r.logos || [];
logos.replaceChildren(...lg.map((l) => {
const el = h("button", { class: "pick-logo", type: "button", title: l.name, onclick: () => { pick.logo = pick.logo === l.full ? null : l.full; $$(".pick-logo", logos).forEach((x) => x.classList.toggle("on", x === el && !!pick.logo)); } },
h("img", { src: l.thumb, alt: "" }), h("span", {}, l.name));
return el;
}));
logos.hidden = logoHead.hidden = !lg.length;
status.textContent = r.photos.length || r.pages.length || lg.length ? "Pick a photo, a logo, a Wikipedia page for the bio, or any mix." : "Nothing found. Try a different spelling.";
};
input.addEventListener("keydown", (e) => { if (e.key === "Enter") { e.preventDefault(); run(); } });
const body = h("div", { class: "stack" },
h("div", { class: "row" }, input, h("button", { class: "btn", type: "button", onclick: run }, icon("search"), "Search")),
status,
h("strong", { class: "pick-head" }, "Photos from Deezer"), photos,
h("strong", { class: "pick-head" }, "Wikipedia page (bio and logo)"), pages);
logoHead, logos,
h("strong", { class: "pick-head" }, "Wikipedia page (bio, and a logo if you don't pick one)"), pages);
run();
const ok = await modal(`Find ${ar.name} online`, body, [{ label: "Cancel", value: false }, { label: "Use these", value: true, primary: true }]);
if (!ok || (!pick.photo && !pick.page)) return null;
if (!ok || (!pick.photo && !pick.page && !pick.logo)) return null;
try {
const meta = await invoke("artist_apply", { name: ar.name, photo: pick.photo, page: pick.page });
const meta = await invoke("artist_apply", { name: ar.name, photo: pick.photo, page: pick.page, logo: pick.logo });
setArtistMeta(ar.name, meta);
toast("Artist updated", "ok");
return meta;
+13
View File
@@ -1191,3 +1191,16 @@ body.mini-mode > *:not(#mini):not(.toasts):not(.modal-wrap):not(script) { displa
.mini .mini-info, .mini .mini-ctl, .mini .mini-top { flex-shrink: 0; }
.mini.has-panel .mini-panel { min-height: 96px; }
.mini.tiny.has-panel .mini-panel { display: none; }
/* discord */
.discord-opt.dim { opacity: 0.55; }
.discord-steps { margin: 0; padding-left: 18px; display: grid; gap: 6px; color: var(--text-2); font-size: 12.5px; line-height: 1.45; }
.discord-steps strong { color: var(--text); font-weight: 600; }
.discord-assets { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.discord-assets .muted { font-size: 12px; }
/* artist logo picker */
.pick-logos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--s2); }
.pick-logo { display: grid; gap: 6px; padding: var(--s3); border-radius: var(--r-ctl); border: 1px solid var(--border); background: repeating-conic-gradient(rgba(127, 127, 127, 0.14) 0 25%, transparent 0 50%) 0 0 / 14px 14px; color: var(--text-2); font-size: 12px; text-align: center; cursor: pointer; }
.pick-logo img { width: 100%; height: 56px; object-fit: contain; }
.pick-logo.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }