diff --git a/src/artistinfo.rs b/src/artistinfo.rs index 5918742..90f4447 100644 --- a/src/artistinfo.rs +++ b/src/artistinfo.rs @@ -1,5 +1,6 @@ // atmosphere · artistinfo.rs · Finds artist photos, bios and logos from keyless public sources: Deezer, Wikipedia and Wikidata use anyhow::Result; +use base64::Engine as _; use regex::Regex; use serde_json::Value; use std::sync::LazyLock; @@ -150,7 +151,13 @@ pub async fn choices(http: &reqwest::Client, query: &str) -> (Vec, }) .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 { @@ -236,6 +243,18 @@ mod tests { 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] #[ignore] async fn live_finds_daft_punk() { diff --git a/ui/app.js b/ui/app.js index a884295..3961cb0 100644 --- a/ui/app.js +++ b/ui/app.js @@ -95,10 +95,10 @@ function toast(message, kind = "") { }, kind === "err" ? 6500 : 3000); } -function art(url, cls, alt = "") { - if (!url) return h("div", { class: `${cls} ph` }, icon("music")); +function art(url, cls, alt = "", ph = "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" }); - 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; } diff --git a/ui/library.js b/ui/library.js index a73871c..4fa9c99 100644 --- a/ui/library.js +++ b/ui/library.js @@ -130,10 +130,10 @@ async function loadLibrary() { 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 = "") { - return art(artUrl(key), cls, alt); +function cover(key, cls, alt = "", ph = "music") { + return art(artUrl(key), cls, alt, ph); } /* routing */ @@ -668,7 +668,7 @@ async function searchArtistOnline(ar) { if (!r) return; 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)); } }, - 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; })); pages.replaceChildren(...r.pages.map((p) => { @@ -892,7 +892,7 @@ function albumView(root, key) { 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); } }, - 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-sub" }, ar.albums.length ? plural(ar.albums.length, "release") : plural(ar.tracks.length, "song"))); } @@ -916,7 +916,7 @@ function artistView(root, key) { root.append( h("header", { class: "hero artist-hero" }, 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: "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), diff --git a/ui/lyrics.js b/ui/lyrics.js index 573bc9b..2e1b123 100644 --- a/ui/lyrics.js +++ b/ui/lyrics.js @@ -155,6 +155,18 @@ function renderLyricsAll() { 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() { Lyr.raf = 0; 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); 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]; diff --git a/ui/miniplayer.js b/ui/miniplayer.js index 4fbd99b..9922ddb 100644 --- a/ui/miniplayer.js +++ b/ui/miniplayer.js @@ -12,7 +12,7 @@ const Mini = { const MINI_MIN = { w: 260, h: 96 }; const MINI_MAX = { w: 900, h: 900 }; -const MINI_CORE = 168; +const MINI_CORE = 196; const MINI_STRIP = 112; const MINI_PANEL = 232; diff --git a/ui/search.js b/ui/search.js index 2e137aa..9165205 100644 --- a/ui/search.js +++ b/ui/search.js @@ -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 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 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)) }); if (top && top[0] >= 60) { const x = top[1]; diff --git a/ui/stats.js b/ui/stats.js index a176391..7a95b7a 100644 --- a/ui/stats.js +++ b/ui/stats.js @@ -116,7 +116,7 @@ function statsView(root) { const artistRows = a.artists.slice(0, 8).map((e, i) => { const ar = Lib.artists.get(e.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)}`))); }); body.append(h("div", { class: "stat-split" }, diff --git a/ui/styles.css b/ui/styles.css index 1040ab0..4fd6004 100644 --- a/ui/styles.css +++ b/ui/styles.css @@ -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 span { display: grid; gap: 2px; } .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; }