diff --git a/frontend/art.html b/frontend/art.html
new file mode 100644
index 0000000..294e55f
--- /dev/null
+++ b/frontend/art.html
@@ -0,0 +1,22 @@
+
+
+
+
+ Album art
+ Albums you've scrobbled that have no cover art.
+
+
+
+
+
+
diff --git a/frontend/css/style.css b/frontend/css/style.css
index 7b6f67d..9cd52d6 100644
--- a/frontend/css/style.css
+++ b/frontend/css/style.css
@@ -1149,3 +1149,24 @@ input {
height: 2.25rem;
align-self: center; /* .log li items default to stretch/start, which suits text, not art */
}
+
+/* ---- Album art: fixing missing art ---------------------------------------------- */
+.art-row {
+ display: grid;
+ grid-template-columns: 4rem minmax(0, 1fr);
+ gap: 1rem;
+ align-items: start;
+}
+
+.art-thumb-lg {
+ width: 4rem;
+ height: 4rem;
+}
+
+.art-row-body .muted {
+ margin: 0.35rem 0 0.75rem;
+}
+
+.art-correction {
+ margin-top: 1rem;
+}
diff --git a/frontend/js/api.js b/frontend/js/api.js
index 308f737..2104516 100644
--- a/frontend/js/api.js
+++ b/frontend/js/api.js
@@ -102,7 +102,7 @@ export async function api(path, { method = "GET", body, auth = true } = {}) {
// Turn webargs validation details into a single readable sentence.
export function describeError(error) {
- const fields = error.details?.json ?? error.details?.query;
+ const fields = error.details?.json ?? error.details?.query ?? error.details?.files;
if (fields) {
return Object.entries(fields)
.map(([field, messages]) => `${field}: ${[].concat(messages).join(" ")}`)
@@ -112,10 +112,10 @@ export function describeError(error) {
}
// Multipart upload with progress (fetch can't report upload progress).
-export function upload(path, formData, onProgress) {
+export function upload(path, formData, onProgress, method = "POST") {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
- xhr.open("POST", `${apiBase}/api/v1${path}`);
+ xhr.open(method, `${apiBase}/api/v1${path}`);
const token = getToken();
if (token) xhr.setRequestHeader("Authorization", `Bearer ${token}`);
xhr.upload.addEventListener("progress", (event) => {
diff --git a/frontend/js/art-failures.js b/frontend/js/art-failures.js
new file mode 100644
index 0000000..ce2f5bb
--- /dev/null
+++ b/frontend/js/art-failures.js
@@ -0,0 +1,170 @@
+import { api, describeError, upload } from "./api.js";
+import { artThumb, forgetArt } from "./art.js";
+import { errorBox, h, num, replace } from "./dom.js";
+import { signedInPage } from "./layout.js";
+
+const PER_PAGE = 25;
+const list = document.getElementById("albums");
+const messages = document.getElementById("messages");
+const pager = document.getElementById("pager");
+const page = Math.max(1, Number.parseInt(new URLSearchParams(location.search).get("page"), 10) || 1);
+
+await signedInPage("art.html");
+await refresh();
+
+async function refresh() {
+ try {
+ render(await api(`/art/failures?page=${page}&limit=${PER_PAGE}`));
+ } catch (error) {
+ replace(list, h("li", {}, errorBox(error.message)));
+ }
+}
+
+function render(result) {
+ document.getElementById("art-summary").textContent = result.total
+ ? `${num(result.total)} of your albums have no cover art, most-played first. Upload a picture, retry the lookup, or correct what it searches for.`
+ : "Every album you've scrobbled has cover art, or is still being looked up.";
+ if (!result.items.length) {
+ replace(list);
+ } else {
+ replace(list, result.items.map(albumRow));
+ }
+ replace(
+ pager,
+ result.page > 1 ? h("a", { class: "button button-quiet", href: `?page=${result.page - 1}` }, "Previous") : h("span"),
+ result.page < result.total_pages
+ ? h("a", { class: "button button-quiet", href: `?page=${result.page + 1}` }, "Next")
+ : h("span"),
+ );
+}
+
+function statusText(item) {
+ const own = item.override;
+ if (own?.status === "pending") return "Your correction is waiting to be looked up.";
+ if (own?.status === "error") {
+ return own.error_code === "NotFound"
+ ? "Your correction didn't find any art."
+ : `Your correction failed (${own.error_code ?? "unknown error"}).`;
+ }
+ if (item.status === "error") return `The lookup failed (${item.error_code ?? "unknown error"}). It will be tried again.`;
+ if (item.status === "not_found") return "No cover art was found for this album.";
+ return "Waiting to be looked up.";
+}
+
+function say(notice) {
+ replace(messages, notice);
+}
+
+function albumRow(item) {
+ const { artist, album } = item;
+ const query = `artist=${encodeURIComponent(artist)}&album=${encodeURIComponent(album)}`;
+ const fileInput = h("input", { type: "file", accept: "image/jpeg,image/png,image/webp", hidden: true });
+ const correction = correctionForm(item, query);
+ const buttons = h("div", { class: "button-row" });
+ const busy = (on) => buttons.querySelectorAll("button").forEach((b) => (b.disabled = on));
+
+ async function act(work, done) {
+ busy(true);
+ replace(messages);
+ try {
+ await work();
+ say(h("p", { class: "notice notice-ok", role: "status" }, done));
+ forgetArt(artist, album);
+ await refresh();
+ } catch (error) {
+ say(errorBox(describeError(error)));
+ } finally {
+ busy(false);
+ }
+ }
+
+ fileInput.addEventListener("change", () => {
+ const file = fileInput.files[0];
+ if (!file) return;
+ const data = new FormData();
+ data.append("file", file);
+ act(() => upload(`/art/album?${query}`, data), `Uploaded art for ${album}.`);
+ fileInput.value = "";
+ });
+
+ replace(
+ buttons,
+ h("button", { type: "button", class: "button", onclick: () => fileInput.click() }, "Upload art"),
+ h(
+ "button",
+ {
+ type: "button",
+ class: "button button-quiet",
+ onclick: () => act(() => api(`/art/album/retry?${query}`, { method: "POST" }), `Looking up ${album} again.`),
+ },
+ "Retry lookup",
+ ),
+ h(
+ "button",
+ { type: "button", class: "button button-quiet", onclick: () => (correction.hidden = !correction.hidden) },
+ "Correct search",
+ ),
+ item.override
+ ? h(
+ "button",
+ {
+ type: "button",
+ class: "button button-quiet",
+ onclick: () => act(() => api(`/art/album?${query}`, { method: "DELETE" }), `Removed your correction for ${album}.`),
+ },
+ "Remove mine",
+ )
+ : null,
+ );
+ correction.addEventListener("submit", (event) => {
+ event.preventDefault();
+ const body = { artist, album };
+ const { search_artist, search_album, release_group_mbid } = correction.elements;
+ if (search_artist.value.trim()) body.search_artist = search_artist.value.trim();
+ if (search_album.value.trim()) body.search_album = search_album.value.trim();
+ if (release_group_mbid.value.trim()) body.release_group_mbid = release_group_mbid.value.trim();
+ act(() => api("/art/album/correction", { method: "PUT", body }), `Queued a corrected lookup for ${album}.`);
+ });
+
+ return h(
+ "li",
+ { class: "art-row" },
+ artThumb(artist, album, "art-thumb-lg"),
+ h(
+ "div",
+ { class: "art-row-body" },
+ h("span", { class: "row-title" }, album),
+ h("span", { class: "by" }, ` by ${artist}`),
+ h("p", { class: "muted" }, `${num(item.scrobbles)} ${item.scrobbles === 1 ? "scrobble" : "scrobbles"} · ${statusText(item)}`),
+ buttons,
+ fileInput,
+ correction,
+ ),
+ );
+}
+
+function correctionForm(item, query) {
+ const own = item.override ?? {};
+ const field = (name, label, value, hint, extra = {}) =>
+ h(
+ "div",
+ { class: "field" },
+ h("label", { for: `${name}-${query}` }, label),
+ h("input", { id: `${name}-${query}`, name, type: "text", value: value ?? "", autocomplete: "off", ...extra }),
+ hint ? h("p", { class: "hint" }, hint) : null,
+ );
+ return h(
+ "form",
+ { class: "stacked-form art-correction", hidden: true },
+ field("search_artist", "Search for artist", own.search_artist ?? item.artist),
+ field("search_album", "Search for album", own.search_album ?? item.album),
+ field(
+ "release_group_mbid",
+ "MusicBrainz release-group ID (optional)",
+ own.release_group_mbid,
+ "If you know it, paste the ID from the album's MusicBrainz page. It skips the search.",
+ { placeholder: "00000000-0000-0000-0000-000000000000", pattern: "[0-9a-fA-F-]{36}" },
+ ),
+ h("button", { type: "submit", class: "button" }, "Look it up"),
+ );
+}
diff --git a/frontend/js/art.js b/frontend/js/art.js
index 35154fb..a59f010 100644
--- a/frontend/js/art.js
+++ b/frontend/js/art.js
@@ -6,12 +6,20 @@ import { h } from "./dom.js";
const cache = new Map(); // dedupes repeat/concurrent lookups for the same album within a page
+const keyFor = (artist, album) => `${artist.toLowerCase()}␟${album.toLowerCase()}`;
+
+// Forget a looked-up album (after the user uploads or corrects its art) so the next
+// artThumb() for it asks the server again instead of reusing the stale answer.
+export function forgetArt(artist, album) {
+ cache.delete(keyFor(artist, album));
+}
+
export function artThumb(artist, album, extraClass) {
const classes = extraClass ? `art-thumb ${extraClass}` : "art-thumb";
const el = h("div", { class: `${classes} art-thumb-empty` });
if (!album) return el; // nothing to look up
- const key = `${artist.toLowerCase()}␟${album.toLowerCase()}`;
+ const key = keyFor(artist, album);
if (!cache.has(key)) {
cache.set(
key,
diff --git a/frontend/js/layout.js b/frontend/js/layout.js
index feb134d..2e5deb1 100644
--- a/frontend/js/layout.js
+++ b/frontend/js/layout.js
@@ -6,6 +6,7 @@ import { h, replace } from "./dom.js";
const NAV = [
["index.html", "Overview"],
["history.html", "History"],
+ ["art.html", "Album art"],
["apps.html", "Apps"],
["sessions.html", "Sessions"],
["import.html", "Import"],