Skip to content

Artist art and bios from fanart.tv and Wikipedia (plan 072, Phase 2, server) - #123

Merged
simonhull merged 8 commits into
mainfrom
feat/artist-art-fetch
Nov 24, 2026
Merged

simonhull merged 8 commits into
mainfrom
feat/artist-art-fetch

Conversation

@simonhull

Copy link
Copy Markdown
Owner

Plan 072, Phase 2, the server half: artist art and bios fetched from fanart.tv and from Wikipedia, Wikidata and Wikimedia Commons, by the MusicBrainz IDs the library holds. The UI half (Health's Metadata card, the Settings rows) follows from the boards.

What it does

  • internal/scrape, the artist pass. Scraper.Run is the app's background work: a pass at start, after every library change (a scan, an edit or a match may have given an artist an MBID) and when the next artist falls due. People's artists first, then album artists by everyone's plays, then the rest. It waits on the scan's claim before each artist and renders through the scan's artwork.Cache, sharing its two renders. Never by a name: only an artist's MBID, never Various Artists or MusicBrainz's special-purpose artists.
  • Precedence, pure (Decide, DecideBio, Pick). Pins and the library's own files are never replaced or taken away. fanart.tv (thumb, 4K then 1080p background, HD then plain logo, banner), then Commons' Wikidata portrait for a thumb fanart.tv lacks; Wikipedia's lead in metadata.language, else English, as the bio, credited CC BY-SA 4.0 with its link. A source that wasn't asked or failed keeps its own image; one goes only when its own source answered with none. Among one source's images: tier, language, likes, size, oldest ID.
  • internal/remote: the gate MusicBrainz used, moved, beside a client every source shares: people before background work, one request per key, retries on 429 and 503 honoring Retry-After, body caps, Kitsune's User-Agent, keys in headers, and errors that never quote a URL.
  • scrape/fanarttv and scrape/wikimedia clients, and matching.MusicBrainz.ArtistLinks (artist/{mbid}?inc=url-rels, kept a week) for the Wikidata item.
  • Migration 0027: scrape_state (per source and MBID: found, none or failed, failures in a row, the error in words, next ask) and scrape_feeds. Found is asked again in 27 to 33 days by a hash of the MBID; none in 7 days, then 30; failures back off 1 h, 6 h, a day, a week. A 404 is none; a 401 or 403 stops that source until a setting changes; a source down or busy rests. fanart.tv's latest feed, read once a day, brings forward every artist on it. A folder that gives up an image asks the sources again.
  • Settings: metadata.remote (off on a new server), metadata.fanarttv, metadata.wikipedia, metadata.language, and the secrets fanarttv.api_key and fanarttv.client_key. Kitsune ships no key and builds none into a release: without a project key fanart.tv is off and says so. Live through follow.go (Scraper.Configure).
  • GET /admin/metadata for Health's card: the master switch and language, each source's state and key states in words (never a value), its last failure, the pass's progress, and album artists counted (with an MBID, looked up, with art, found nothing, without an MBID for the Matching link).
  • Opening an artist with nothing yet asks for it at a person's priority without waiting; the art comes on the artists event.
  • Stand-ins fanarttvtest and wikimediatest (KITSUNE_FANARTTV_URL, KITSUNE_WIKIMEDIA_URL, read only in cmd/), and musicbrainztest gains url-rels. Each answers 429 with Retry-After, 503, a refused key, bare file names, slowly and too much.

Deviations from the plan

  • Decision 4 as chosen: no built-in project key, no ldflags, no 1Password in the build. The key states are set, missing or none (no built in).
  • metadata.lastfm_bios, metadata.coverartarchive and metadata.audiodb are left to their phases: no defs yet.
  • The pass's progress is in GET /admin/metadata, not in GET /library: it is for administrators, and the card reads it again while pass.running.
  • Wikipedia's lead comes from the REST page summary; Wikidata is asked twice (the sitelinks filtered to the two languages wanted, then P18's claims), rather than for the whole entity.
  • The answer bodies aren't kept in lookups yet (the picker of Phase 4 needs them); MusicBrainz's are, as before.
  • fanart.tv's images carry no credit; a Commons portrait carries its author, license and page.
  • The browser suite runs with lookups off (the default), so the pass doesn't run during it; the numbers below show nothing on the play path moved.

Tests

  • Pure: precedence and choice, refresh and backoff, special-purpose MBIDs.
  • The pass against all three stand-ins with a transport guard that fails a test on any request leaving httptest: art and bio fetched, Commons' credit, folders and an artist.nfo kept, a refused key, a source down and resting, bare file names, the latest feed, a person's artist first, lookups off, no project key, a scan pausing the pass, the report's counts.
  • TestNoErrorQuotesAKey in fanarttv and scrape (every fault: logs, stored errors, the report), and TestNoEventHoldsASecret with both fanart.tv keys set.
  • Store: states and backoff, remote art never over a folder or a pin, a pin surviving refreshes, asking again, the feed; TestPrefixes covers 0027.
  • Routes through openapitest: GET /admin/metadata 200, 401, 403, 503, and an artist opened asked first.
  • remote: statuses as sentinels, no URL in an error, body caps, Retry-After, a long Retry-After ending the request, people first, single flight, a timeout ending (not looping).

Speed

Numbers before and after, on the same machine, to follow in a comment here.

…nt with retries, body caps and errors that never quote a URL, and MusicBrainz looks up an artist's Wikidata item
…pass: what each source said, remote art that never replaces a folder's or a pin
… as settings, the keys secrets and lookups off on a new server
…busy, down, refused, bare names, slowly and too much
…ns and folders first, failures backed off, a refused key stopping its source
…ng asks for it first, the pass wired to its settings and the KITSUNE_FANARTTV_URL and KITSUNE_WIKIMEDIA_URL stand-ins, and its speed budget
…ute, so a busy machine can't turn too much into too slow
@simonhull

Copy link
Copy Markdown
Owner Author

Speed, before (main at f5a301c) and after, on the same idle machine

Browser suite (library, album, artist files, KITSUNE_PERF_PORT=15830), 20 runs each, ms, median / p95:

Interaction 1k before 1k after 50k before 50k after
Play a song from the Library (play-library) 24.1 / 27.5 24.9 / 26.1 23.2 / 25.6 23.3 / 24.6
Next 18.5 / 20.4 18.5 / 23.5 18.6 / 20.3 18.4 / 20.0
Library first rows (library-paint) 100.1 / 118.5 105.9 / 130.4 385.6 / 412.6 374.5 / 415.5
Open an artist with 800 songs (open-artist) 69.0 / 82.2 68.8 / 83.3 90.0 / 103.7 88.1 / 109.6

Server speed tests, median / p95:

Test before after
Stream first byte 182 µs / 292 µs 177 µs / 261 µs
GET /artists/{id} with all art (artist-detail) 572 µs / 715 µs 542 µs / 701 µs
GET /artists, 2,000 with thumbs 183 ms / 188 ms 181 ms / 186 ms
scrape-artist (new, budget 850 ms) – 450 ms / 464 ms

Everything moves within run-to-run noise. scrape-artist is mostly the 4K background's renders. Lookups are off by default, so the pass doesn't run during the suite; with them on it is background work that waits on a scan's claim and shares the scan's two renders. CI's perf jobs pass, the new budget included.

@simonhull
simonhull merged commit 66b47f8 into main Nov 24, 2026
19 of 20 checks passed
@simonhull
simonhull deleted the feat/artist-art-fetch branch November 24, 2026 17:25
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