mirror of
https://github.com/pvrzz/atmosphere.git
synced 2026-11-29 05:22:26 +00:00
Fix artist photo search, artist placeholders and mini player controls
- Artist photo search: thumbnails are fetched by the app and embedded, so they always show (lazy-loaded web images never started loading) - Artists without a photo show the person placeholder instead of an album cover - Mini player: lyrics centre inside their own box instead of scrolling the whole window, and only the cover shrinks when space is tight, so the controls always show
This commit is contained in:
+20
-1
@@ -1,5 +1,6 @@
|
|||||||
// atmosphere · artistinfo.rs · Finds artist photos, bios and logos from keyless public sources: Deezer, Wikipedia and Wikidata
|
// atmosphere · artistinfo.rs · Finds artist photos, bios and logos from keyless public sources: Deezer, Wikipedia and Wikidata
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use base64::Engine as _;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
@@ -150,7 +151,13 @@ pub async fn choices(http: &reqwest::Client, query: &str) -> (Vec<PhotoChoice>,
|
|||||||
})
|
})
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
};
|
};
|
||||||
tokio::join!(photos, pages)
|
let (mut photos, pages) = tokio::join!(photos, pages);
|
||||||
|
let thumbs = futures_util::future::join_all(photos.iter().map(|p| get_bytes(http, &p.thumb))).await;
|
||||||
|
for (p, bytes) in photos.iter_mut().zip(thumbs) {
|
||||||
|
p.thumb = bytes.map(|b| format!("data:image/jpeg;base64,{}", base64::engine::general_purpose::STANDARD.encode(b))).unwrap_or_default();
|
||||||
|
}
|
||||||
|
photos.retain(|p| !p.thumb.is_empty());
|
||||||
|
(photos, pages)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn allowed_photo(url: &str) -> bool {
|
pub fn allowed_photo(url: &str) -> bool {
|
||||||
@@ -236,6 +243,18 @@ mod tests {
|
|||||||
assert!(!allowed_photo("file:///C:/Windows/win.ini"));
|
assert!(!allowed_photo("file:///C:/Windows/win.ini"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
#[ignore]
|
||||||
|
async fn live_choices_include_photos() {
|
||||||
|
let http = reqwest::Client::builder().user_agent(concat!("atmosphere/", env!("CARGO_PKG_VERSION"))).build().unwrap();
|
||||||
|
for q in ["Daft Punk", "Drake", "Taylor Swift", "Westwood"] {
|
||||||
|
let (photos, pages) = choices(&http, q).await;
|
||||||
|
eprintln!("{q}: {} photos, {} pages", photos.len(), pages.len());
|
||||||
|
assert!(!photos.is_empty(), "no photos for {q}");
|
||||||
|
assert!(photos.iter().all(|p| p.thumb.starts_with("data:image/jpeg;base64,") && p.full.starts_with("https://")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
async fn live_finds_daft_punk() {
|
async fn live_finds_daft_punk() {
|
||||||
|
|||||||
@@ -95,10 +95,10 @@ function toast(message, kind = "") {
|
|||||||
}, kind === "err" ? 6500 : 3000);
|
}, kind === "err" ? 6500 : 3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function art(url, cls, alt = "") {
|
function art(url, cls, alt = "", ph = "music") {
|
||||||
if (!url) return h("div", { class: `${cls} ph` }, icon("music"));
|
if (!url) return h("div", { class: `${cls} ph` }, icon(ph));
|
||||||
const img = h("img", { class: cls, src: url, alt, loading: "lazy", draggable: "false", referrerpolicy: "no-referrer" });
|
const img = h("img", { class: cls, src: url, alt, loading: "lazy", draggable: "false", referrerpolicy: "no-referrer" });
|
||||||
img.addEventListener("error", () => img.replaceWith(h("div", { class: `${cls} ph` }, icon("music"))), { once: true });
|
img.addEventListener("error", () => img.replaceWith(h("div", { class: `${cls} ph` }, icon(ph))), { once: true });
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-6
@@ -130,10 +130,10 @@ async function loadLibrary() {
|
|||||||
if (typeof updateCommit === "function") updateCommit();
|
if (typeof updateCommit === "function") updateCommit();
|
||||||
}
|
}
|
||||||
|
|
||||||
const artistImage = (ar) => ar?.meta?.image || ar?.albums.find((a) => a.art)?.art || ar?.tracks.find((t) => t.art)?.art || null;
|
const artistImage = (ar) => ar?.meta?.image || null;
|
||||||
|
|
||||||
function cover(key, cls, alt = "") {
|
function cover(key, cls, alt = "", ph = "music") {
|
||||||
return art(artUrl(key), cls, alt);
|
return art(artUrl(key), cls, alt, ph);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* routing */
|
/* routing */
|
||||||
@@ -668,7 +668,7 @@ async function searchArtistOnline(ar) {
|
|||||||
if (!r) return;
|
if (!r) return;
|
||||||
photos.replaceChildren(...r.photos.map((p) => {
|
photos.replaceChildren(...r.photos.map((p) => {
|
||||||
const el = h("button", { class: "pick-photo", type: "button", title: `${p.name} · ${fans(p.fans)}`, onclick: () => { pick.photo = pick.photo === p.full ? null : p.full; $$(".pick-photo", photos).forEach((x) => x.classList.toggle("on", x === el && !!pick.photo)); } },
|
const el = h("button", { class: "pick-photo", type: "button", title: `${p.name} · ${fans(p.fans)}`, onclick: () => { pick.photo = pick.photo === p.full ? null : p.full; $$(".pick-photo", photos).forEach((x) => x.classList.toggle("on", x === el && !!pick.photo)); } },
|
||||||
h("img", { src: p.thumb, alt: "", referrerpolicy: "no-referrer", loading: "lazy" }), h("span", {}, p.name), h("small", {}, fans(p.fans)));
|
h("img", { src: p.thumb, alt: "" }), h("span", {}, p.name), h("small", {}, fans(p.fans)));
|
||||||
return el;
|
return el;
|
||||||
}));
|
}));
|
||||||
pages.replaceChildren(...r.pages.map((p) => {
|
pages.replaceChildren(...r.pages.map((p) => {
|
||||||
@@ -892,7 +892,7 @@ function albumView(root, key) {
|
|||||||
|
|
||||||
function artistCard(ar) {
|
function artistCard(ar) {
|
||||||
return h("div", { class: "card-tile artist", role: "button", tabindex: "0", "data-artist": ar.key, onclick: () => openLib("artist", ar.key), onkeydown: (e) => { if (e.key === "Enter") openLib("artist", ar.key); } },
|
return h("div", { class: "card-tile artist", role: "button", tabindex: "0", "data-artist": ar.key, onclick: () => openLib("artist", ar.key), onkeydown: (e) => { if (e.key === "Enter") openLib("artist", ar.key); } },
|
||||||
h("div", { class: "tile-art round" }, cover(artistImage(ar), "tile-img", ar.name)),
|
h("div", { class: "tile-art round" }, cover(artistImage(ar), "tile-img", ar.name, "user")),
|
||||||
h("div", { class: "tile-title" }, ar.name),
|
h("div", { class: "tile-title" }, ar.name),
|
||||||
h("div", { class: "tile-sub" }, ar.albums.length ? plural(ar.albums.length, "release") : plural(ar.tracks.length, "song")));
|
h("div", { class: "tile-sub" }, ar.albums.length ? plural(ar.albums.length, "release") : plural(ar.tracks.length, "song")));
|
||||||
}
|
}
|
||||||
@@ -916,7 +916,7 @@ function artistView(root, key) {
|
|||||||
root.append(
|
root.append(
|
||||||
h("header", { class: "hero artist-hero" },
|
h("header", { class: "hero artist-hero" },
|
||||||
h("div", { class: "hero-bg", style: img ? `background-image:url("${artUrl(img)}")` : "" }),
|
h("div", { class: "hero-bg", style: img ? `background-image:url("${artUrl(img)}")` : "" }),
|
||||||
cover(img, "avatar", ar.name),
|
cover(img, "avatar", ar.name, "user"),
|
||||||
h("div", { class: "hero-meta" },
|
h("div", { class: "hero-meta" },
|
||||||
h("div", { class: "kind-line" }, h("span", { class: "kind-btn", style: "cursor:default" }, icon("user"), "Artist")),
|
h("div", { class: "kind-line" }, h("span", { class: "kind-btn", style: "cursor:default" }, icon("user"), "Artist")),
|
||||||
ar.meta?.logo ? h("h1", { class: "hero-title big has-logo" }, h("img", { class: `artist-logo ${ar.meta.logoDark ? "dark" : ""}`, src: artUrl(ar.meta.logo), alt: ar.name })) : h("h1", { class: "hero-title big" }, ar.name),
|
ar.meta?.logo ? h("h1", { class: "hero-title big has-logo" }, h("img", { class: `artist-logo ${ar.meta.logoDark ? "dark" : ""}`, src: artUrl(ar.meta.logo), alt: ar.name })) : h("h1", { class: "hero-title big" }, ar.name),
|
||||||
|
|||||||
+13
-1
@@ -155,6 +155,18 @@ function renderLyricsAll() {
|
|||||||
if (typeof Mini !== "undefined" && Mini.on) renderMiniPanel();
|
if (typeof Mini !== "undefined" && Mini.on) renderMiniPanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function centerLine(el) {
|
||||||
|
let box = el.parentElement;
|
||||||
|
while (box && box !== document.body) {
|
||||||
|
const style = getComputedStyle(box);
|
||||||
|
if (/(auto|scroll)/.test(style.overflowY) && box.scrollHeight > box.clientHeight) break;
|
||||||
|
box = box.parentElement;
|
||||||
|
}
|
||||||
|
if (!box || box === document.body) return;
|
||||||
|
const target = el.getBoundingClientRect().top - box.getBoundingClientRect().top + box.scrollTop - (box.clientHeight - el.offsetHeight) / 2;
|
||||||
|
box.scrollTo({ top: Math.max(0, target), behavior: reduced.matches ? "auto" : "smooth" });
|
||||||
|
}
|
||||||
|
|
||||||
function tick() {
|
function tick() {
|
||||||
Lyr.raf = 0;
|
Lyr.raf = 0;
|
||||||
const visible = !$("#lyricsPanel").hidden || Lyr.tv || (typeof Mini !== "undefined" && Mini.on && Mini.panelShown && Mini.prefs.panel === "lyrics");
|
const visible = !$("#lyricsPanel").hidden || Lyr.tv || (typeof Mini !== "undefined" && Mini.on && Mini.panelShown && Mini.prefs.panel === "lyrics");
|
||||||
@@ -177,7 +189,7 @@ function tick() {
|
|||||||
});
|
});
|
||||||
if (box.classList.contains("depth")) setDepth(box, idx);
|
if (box.classList.contains("depth")) setDepth(box, idx);
|
||||||
const cur = box.querySelector(".lyr-line.on");
|
const cur = box.querySelector(".lyr-line.on");
|
||||||
if (cur) cur.scrollIntoView({ block: "center", behavior: reduced.matches ? "auto" : "smooth" });
|
if (cur) centerLine(cur);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const line = l.lines[idx];
|
const line = l.lines[idx];
|
||||||
|
|||||||
+1
-1
@@ -12,7 +12,7 @@ const Mini = {
|
|||||||
|
|
||||||
const MINI_MIN = { w: 260, h: 96 };
|
const MINI_MIN = { w: 260, h: 96 };
|
||||||
const MINI_MAX = { w: 900, h: 900 };
|
const MINI_MAX = { w: 900, h: 900 };
|
||||||
const MINI_CORE = 168;
|
const MINI_CORE = 196;
|
||||||
const MINI_STRIP = 112;
|
const MINI_STRIP = 112;
|
||||||
const MINI_PANEL = 232;
|
const MINI_PANEL = 232;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ function qsResults(raw) {
|
|||||||
const add = (group, list, n, make) => list.slice(0, n).forEach(([, x], i) => out.push({ group: i === 0 ? group : null, ...make(x) }));
|
const add = (group, list, n, make) => list.slice(0, n).forEach(([, x], i) => out.push({ group: i === 0 ? group : null, ...make(x) }));
|
||||||
const songItem = (t) => ({ kind: "song", title: t.title, sub: [t.artist, t.album].filter(Boolean).join(" · "), art: t.art, run: () => playList([t]), alt: () => Player.playNext([t]) });
|
const songItem = (t) => ({ kind: "song", title: t.title, sub: [t.artist, t.album].filter(Boolean).join(" · "), art: t.art, run: () => playList([t]), alt: () => Player.playNext([t]) });
|
||||||
const albumItem = (a) => ({ kind: "album", title: a.title, sub: `${albumKind(a)} · ${a.artist}`, art: a.art, run: () => openLib("album", a.key), alt: () => playList(a.tracks) });
|
const albumItem = (a) => ({ kind: "album", title: a.title, sub: `${albumKind(a)} · ${a.artist}`, art: a.art, run: () => openLib("album", a.key), alt: () => playList(a.tracks) });
|
||||||
const artistItem = (a) => ({ kind: "artist", title: a.name, sub: `Artist · ${plural(a.tracks.length, "song")}`, art: a.meta?.image || a.albums[0]?.art, round: true, run: () => openLib("artist", a.key), alt: () => playList(a.tracks, 0, true) });
|
const artistItem = (a) => ({ kind: "artist", title: a.name, sub: `Artist · ${plural(a.tracks.length, "song")}`, art: a.meta?.image || null, icon: "user", round: true, run: () => openLib("artist", a.key), alt: () => playList(a.tracks, 0, true) });
|
||||||
const listItem = (p) => ({ kind: "playlist", title: p.name, sub: `Playlist · ${plural(p.order.length, "song")}`, icon: p.linked ? "folder" : "playlist", run: () => openLib("playlist", p.name), alt: () => playList(p.order.map((id) => Lib.byId.get(id)).filter(Boolean)) });
|
const listItem = (p) => ({ kind: "playlist", title: p.name, sub: `Playlist · ${plural(p.order.length, "song")}`, icon: p.linked ? "folder" : "playlist", run: () => openLib("playlist", p.name), alt: () => playList(p.order.map((id) => Lib.byId.get(id)).filter(Boolean)) });
|
||||||
if (top && top[0] >= 60) {
|
if (top && top[0] >= 60) {
|
||||||
const x = top[1];
|
const x = top[1];
|
||||||
|
|||||||
+1
-1
@@ -116,7 +116,7 @@ function statsView(root) {
|
|||||||
const artistRows = a.artists.slice(0, 8).map((e, i) => {
|
const artistRows = a.artists.slice(0, 8).map((e, i) => {
|
||||||
const ar = Lib.artists.get(e.key);
|
const ar = Lib.artists.get(e.key);
|
||||||
return h("div", { class: "rank-row", role: "button", tabindex: "0", onclick: () => ar && openLib("artist", ar.key) },
|
return h("div", { class: "rank-row", role: "button", tabindex: "0", onclick: () => ar && openLib("artist", ar.key) },
|
||||||
h("span", { class: "rank" }, String(i + 1)), cover(ar ? artistImage(ar) : null, "lt-cover round"),
|
h("span", { class: "rank" }, String(i + 1)), cover(ar ? artistImage(ar) : null, "lt-cover round", "", "user"),
|
||||||
h("div", { class: "lt-main" }, h("span", { class: "lt-title" }, e.name), h("span", { class: "lt-sub" }, `${plural(e.plays, "play")} · ${fmtHours(e.ms)}`)));
|
h("div", { class: "lt-main" }, h("span", { class: "lt-title" }, e.name), h("span", { class: "lt-sub" }, `${plural(e.plays, "play")} · ${fmtHours(e.ms)}`)));
|
||||||
});
|
});
|
||||||
body.append(h("div", { class: "stat-split" },
|
body.append(h("div", { class: "stat-split" },
|
||||||
|
|||||||
@@ -1183,3 +1183,11 @@ body.mini-mode > *:not(#mini):not(.toasts):not(.modal-wrap):not(script) { displa
|
|||||||
.keep-audio { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--s3); align-items: start; margin-top: var(--s3); cursor: pointer; }
|
.keep-audio { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--s3); align-items: start; margin-top: var(--s3); cursor: pointer; }
|
||||||
.keep-audio span { display: grid; gap: 2px; }
|
.keep-audio span { display: grid; gap: 2px; }
|
||||||
.keep-audio small { color: var(--text-3); font-size: 11.5px; line-height: 1.4; }
|
.keep-audio small { color: var(--text-3); font-size: 11.5px; line-height: 1.4; }
|
||||||
|
|
||||||
|
/* mini player: the cover gives way first, the controls never do */
|
||||||
|
.mini.portrait .mini-body { flex: 0 1 auto; min-height: 0; }
|
||||||
|
.mini.portrait .mini-art { flex: 0 1 auto; min-height: 0; width: auto; aspect-ratio: 1; max-width: calc(100% - 40px); }
|
||||||
|
.mini.portrait .mini-art img, .mini.portrait .mini-art-empty { width: 100%; height: 100%; }
|
||||||
|
.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; }
|
||||||
|
|||||||
Reference in New Issue
Block a user