Skip to content

✨ Artist art, bios and album extras from the library's own files (plan 072, Phase 1, server) - #121

Merged
simonhull merged 11 commits into
mainfrom
feat/artist-art-local
Nov 21, 2026
Merged

simonhull merged 11 commits into
mainfrom
feat/artist-art-local

Conversation

@simonhull

Copy link
Copy Markdown
Owner

Plan 072, Phase 1, server half: artist art, bios and album extras read from the library's own files. No network, no keys. The UI half waits for the boards; the web client only learns the new types.

What it does

  • PruneOrphans fixed first. It deleted every artwork row no album used, so it would have wiped artist images at the end of the first scan. Once the new tables reference artwork, it would have failed every scan instead, on the foreign key. It now keeps anything an artist image or album extra uses, and prunes artists before images, so an artist that goes frees its own images.
  • Migration 0026_artist_art:
    • artwork rebuilt (create, copy, drop, rename): source gains remote, and a new alpha column (copied as 0) says the renditions are PNG.
    • New tables artist_images, album_images and artist_bios, all STRICT, cascading with their artist or album. A folder's row records its file (root, path, size, mtime) under a CHECK. A pinned row is the administrator's, and no scan touches it.
    • albums.release_group_mbid added.
    • scrape_state is left to Phase 2: reading local files needs none.
  • internal/artwork:
    • Each kind has its own ladder: cover, thumb and back at 128/512/1024; background and banner at 128/640/1920/3840; logo and disc at 128/400/800.
    • A logo or disc art with transparency stays PNG; everything else is JPEG flattened onto the ground.
    • Colors come from the 128 rendition on both paths. Pixels less than half opaque don't count.
  • The scan:
    • The walk keeps Kodi/Jellyfin-named files. After songs and playlists, an extras step works out each album's folder (the one folder all its songs share, disc folders folded in) and each artist's folder (the folder above an album's, when everything in it belongs to that one artist alone).
    • Artist folder: artist|thumb|folder, fanart*|backdrop*|background, clearlogo|logo, banner and artist.nfo. Album folder: cdart|discart|disc for every disc, cd2/discart-2 for one disc, and back.
    • Files are read through os.Root. An unchanged file isn't read again except by a full scan. A bad file is logged by its root-relative path, remembered until it changes, and the next name is tried. A pin is never touched. Embedded pictures are not read.
    • Targeted (watcher) scans run the step only when it can change something.
    • The release group's MBID is read onto the album, verified per format (FLAC, MP3 v2.3/v2.4, M4A).
  • API (contract first):
    • ArtistDetail.images (thumb, background, logo and banner, each with colors, alpha, source and credit), bio and mbid.
    • ArtistEntry.thumb.
    • AlbumDetail.extras: discs, back and coverSource.
    • GET /artwork/{hash} takes every ladder's sizes and answers image/png for alpha images.
    • Responses are built field by field, and no response names a path or a root.
  • The artists event (ids only, to everyone) when a scan changes an artist's images or bio. It has a schema in the contract, a case in events_test.go, and a place in TestNoEventHoldsASecret, whose nfo holds the secret.
  • Kept rows: a prune, or a delete of missing tracks, that deletes nothing no longer counts as a library write. On main, every scan threw away the index's kept rows this way. Here it would also have made every quick scan re-read the layout (168 ms at 50k songs, against 1.2 ms kept).

Numbers

Measured on this box (Ryzen 9 5950X) while it carried other load (load average 4 to 14). Main's numbers come from a scratch worktree at f8df1fb, run back to back.

main this branch
GET /library/index, 50k songs (budget 250) median 178 ms, p95 216 median 178 ms, p95 193
GET /library/index?artist= (budget 24) 12.9 / 15.1 ms 14.0 / 16.5 ms
GET /artists/{id}, 50k songs 0.67 / 0.81 ms (no art) no art 0.47 / 0.67 ms; all four images and a bio 0.62 / 0.72 ms
GET /artists, 2,000 artists, 50k songs 184 / 190 ms no thumbs 183 / 192 ms; every artist with a thumb 192 / 204 ms
Quick scan, 500 unchanged songs 3.39 ms 3.64 ms
Quick scan, 500 songs, 50 artist folders and 50 album folders of unchanged art — 6.9 to 8.5 ms (median), against 4.5 to 5.8 ms for the same library without art
Stream first byte (budget 0.5 ms) p95 0.52 ms p95 0.53 ms
Watcher's scan of a 10k-song .m3u8 (budget 150) p95 155 ms p95 127 ms

Stream first byte is over its budget on main too, under this load. Nothing on the play path changed.

Rendering and disk:

  • First scan of the art library (300 distinct images and 50 bios beside 500 songs): 6.8 to 8.5 s, against 80 to 90 ms without art. That is about 25 ms per image, two renders at a time.

  • Per image, from BenchmarkPutKinds on photo-like sources:

    Kind Render On disk
    Thumb, 1000² 88 ms 287 KB
    Background, 1920×1080 150 ms 546 KB
    Background, 3840×2160 720 ms 2.28 MB
    Banner, 1000×185 17 ms 66 KB
    Logo, 800×310 PNG 30 ms 134 KB
    Disc, 1000² PNG 133 ms 369 KB
  • Per artist, with all four kinds: about 1.0 MB with a 1080p background, about 2.8 MB with a 4K one. The plan estimated 1 to 2.5 MB.

New budgets in perf/budgets.json, about 1.5x what was measured:

Budget p95
artist-detail 1.3 ms
artists-list 320 ms
quick-scan-art 15 ms, and held to the same scan without art

scrape-artist waits for Phase 2. The browser suite wasn't run: the client changes are types only, and nothing on the play path moved.

Decisions made where the plan left room

  • The PruneOrphans fix comes right after the migration. Its regression test needs the new tables, so the fix couldn't go first. The migration commit alone is safe, because nothing writes those tables until the fix is in.
  • Album extras cover only the album's own folder, not disc subfolders.
  • Disc 0 means "every disc", not NULL, because it is part of the key.
  • Width and height live on artwork only, not repeated on artist_images.
  • Folder rows record their file in file_root, file_path, file_size and file_mtime.
  • artist_bios gains a license_url column, since the API has licenseUrl.
  • The library root can be an artist folder when it holds one artist's albums alone.
  • One artist with several folders: each kind comes from the first folder (by root order, then path) that has a file of that kind.
  • The nfo bio uses <biography> and <musicBrainzArtistID> directly under <artist>, names matched ignoring case. Each line is a paragraph, and the summary is the first. An nfo naming a different MusicBrainz ID than the artist's is ignored.
  • Pins: Phase 4 builds them, so only the schema and the rule are here: source = 'pinned' and pinned_by exist, and no scan replaces or removes a pin (tested by writing one directly).
  • No new serving route. GET /artwork/{hash} serves every kind.
  • coverSource is only ever files for now. The Cover Art Archive arrives in Phase 3.
  • Search's artist hits stay ArtistLink, without thumbs. Giving them thumbs means the name index carrying them.
  • Logos and disc art prefer PNG files over JPEG; every other kind prefers JPEG.
  • Without an artwork cache, the scan still reads bios.

@simonhull
simonhull merged commit 9d407bf into main Nov 21, 2026
10 checks passed
@simonhull
simonhull deleted the feat/artist-art-local branch November 21, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant