summaryrefslogtreecommitdiffhomepage
path: root/yt-music-dl-web/src/features/library
diff options
context:
space:
mode:
Diffstat (limited to 'yt-music-dl-web/src/features/library')
-rw-r--r--yt-music-dl-web/src/features/library/LibraryMetadataSidebar.svelte12
-rw-r--r--yt-music-dl-web/src/features/library/logic.test.ts31
-rw-r--r--yt-music-dl-web/src/features/library/logic.ts9
3 files changed, 48 insertions, 4 deletions
diff --git a/yt-music-dl-web/src/features/library/LibraryMetadataSidebar.svelte b/yt-music-dl-web/src/features/library/LibraryMetadataSidebar.svelte
index 99d7121..aef4165 100644
--- a/yt-music-dl-web/src/features/library/LibraryMetadataSidebar.svelte
+++ b/yt-music-dl-web/src/features/library/LibraryMetadataSidebar.svelte
@@ -222,7 +222,17 @@
<span class="text-[10px] text-base-content/40">current</span>
{/if}
</div>
- <p class="mt-1 truncate text-sm font-medium">{item.title || "(untitled)"}</p>
+ <div class="mt-1 flex items-center gap-1.5">
+ {#if item.artUrl}
+ <img
+ src={item.artUrl}
+ alt=""
+ class="h-5 w-5 shrink-0 rounded object-cover"
+ loading="lazy"
+ />
+ {/if}
+ <p class="truncate text-sm font-medium">{item.title || "(untitled)"}</p>
+ </div>
<p class="truncate text-xs text-base-content/70">{item.artist}</p>
<p class="truncate text-xs text-base-content/50">
{#if item.album}{item.album}{:else}<span class="italic">no album</span>{/if}
diff --git a/yt-music-dl-web/src/features/library/logic.test.ts b/yt-music-dl-web/src/features/library/logic.test.ts
index 4f84bef..388d76e 100644
--- a/yt-music-dl-web/src/features/library/logic.test.ts
+++ b/yt-music-dl-web/src/features/library/logic.test.ts
@@ -418,6 +418,37 @@ describe("library logic (pure)", () => {
expect(req).toEqual({ title: "T", artist: "A", album: "Al" });
expect("track" in req).toBe(false);
});
+
+ it("includes artUrl when the result has one", () => {
+ const r: MetadataResult = {
+ id: "m1",
+ type: "recording",
+ title: "T",
+ artist: "A",
+ score: 70,
+ artUrl: "https://coverartarchive.org/release/abc/front",
+ };
+ const items = trackSidebarItems(base, [r]);
+ const mbItem = items[1];
+ if (!mbItem) throw new Error("expected an MB item");
+ const req = toUpdateRequestFromItem(mbItem);
+ expect(req.artUrl).toBe("https://coverartarchive.org/release/abc/front");
+ });
+
+ it("omits artUrl when the result has none", () => {
+ const r: MetadataResult = {
+ id: "m1",
+ type: "recording",
+ title: "T",
+ artist: "A",
+ score: 70,
+ };
+ const items = trackSidebarItems(base, [r]);
+ const mbItem = items[1];
+ if (!mbItem) throw new Error("expected an MB item");
+ const req = toUpdateRequestFromItem(mbItem);
+ expect("artUrl" in req).toBe(false);
+ });
});
// ─── Match Album helpers (pure) ────────────────────────────────────────────
diff --git a/yt-music-dl-web/src/features/library/logic.ts b/yt-music-dl-web/src/features/library/logic.ts
index fc29b37..4d3676c 100644
--- a/yt-music-dl-web/src/features/library/logic.ts
+++ b/yt-music-dl-web/src/features/library/logic.ts
@@ -234,9 +234,11 @@ export function trackSidebarItems(track: Track, results: MetadataResult[]): Side
* Build a PATCH /api/library/:id body (UpdateTrackRequest) from a clicked
* sidebar item. The "Current tags" entry (source: "youtube") produces an empty
* body (no-op); an MB result sets title + artist always, album + track only
- * when the result actually carries them. Mirrors fillActions from metadata.ts
- * but produces an UpdateTrackRequest (a PATCH body) instead of EditAction[]
- * (in-memory draft edits). Pure: (item) → request.
+ * when the result actually carries them. When the result has a Cover Art
+ * Archive `artUrl`, it is included so the backend downloads + embeds the
+ * front cover. Mirrors fillActions from metadata.ts but produces an
+ * UpdateTrackRequest (a PATCH body) instead of EditAction[] (in-memory draft
+ * edits). Pure: (item) → request.
*/
export function toUpdateRequestFromItem(item: SidebarItem): UpdateTrackRequest {
if (item.source === "youtube") return {}; // no-op — current tags
@@ -246,6 +248,7 @@ export function toUpdateRequestFromItem(item: SidebarItem): UpdateTrackRequest {
};
if (item.album !== undefined) req.album = item.album;
if (item.trackNumber !== undefined) req.track = item.trackNumber;
+ if (item.artUrl !== undefined) req.artUrl = item.artUrl;
return req;
}