Skip to content

Add structured artist metadata, Fanart.tv BYOK, and custom artist scraper support - #543

Open
vizmoe wants to merge 1 commit into
chenqi92:mainfrom
vizmoe:issue/540-artist-metadata-scraping
Open

vizmoe wants to merge 1 commit into
chenqi92:mainfrom
vizmoe:issue/540-artist-metadata-scraping

Conversation

@vizmoe

@vizmoe vizmoe commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Closes #540

Summary

1. Public-source artist metadata, portraits & library-matched similar artists

  • MusicBrainz album-based disambiguation & structured profiles (ArtistMetadata.swift, ArtistMetadataStore.swift, LibraryInsightStore.swift): Cross-check local album titles against MusicBrainz release groups before binding homonymous artists; fetch and cache (bounded LRU) entity type, origin/country, active lifespan, band member / member-of relations, and validated external links.
  • Open-licensed Wikidata P18 / Wikimedia Commons artist portraits (WikimediaArtistPortraitPolicy.swift, ArtworkFetchService.swift): Enforce open-license and upload.wikimedia.org allowlist checks, store in dedicated artist-wikimedia-v1 namespace, and display photographer/license attribution when Wikimedia provides the active portrait.
  • Library-matched similar artists & public-source batch fill (SimilarArtistsService.swift, ArtistSimilarArtistsSectionView.swift, LibraryInsightBatchMode.swift, LibraryInsightBatchFill.swift): Resolve similar artists via Last.fm filtered strictly against artists present in the user's library (excluding self) on iOS, macOS, and Apple TV; add public-sources-first / public-sources-only batch insight fill.

2. Optional Fanart.tv BYOK support

  • Zero embedded developer keys (FanartTvPolicy.swift, FanartTvService.swift): Users provide their own Fanart.tv API Key (and optional Personal Client Key) stored exclusively in KeychainService (syncing via iCloud Keychain when enabled), with connection testing and key removal.
  • HD portraits & transparent PNG wordmark logos (ArtworkFetchService.swift, ArtistHeroArtworkView.swift): Cache HD portraits in artist-fanart-v1 and raw transparent PNG wordmark logos (hdmusiclogo / musiclogo, preserving PNG alpha without JPEG compression) in artist-fanart-logo-v1, feeding the existing iOS ArtistHeroTitleBlock.nameArtwork slot behind a user toggle.
  • Neutral settings UI across all three platforms (FanartTvSettingsView.swift, SettingsView.swift, MacSettingsView.swift, TVFanartTvSettingsView.swift, TVScraperSettingsView.swift): No external subscription or payment links.

3. Custom scraper configuration extension ("artist" capability)

  • Schema & transport security (ScraperConfig.swift, ScraperConfigStore.swift, ScraperTypes.swift, ScraperSettingsStore.swift, ScraperJSONRule.swift):
    • Add "artist" capability and optional artist: EndpointConfig endpoint, wired through import preview/review, validation, subscription refresh, CloudKit sync, and LAN QR transfer (including <id>.secrets.json sidecar secrets).
    • Allow path/query template placeholders in ScraperNetworkScope.origin(template:) while continuing to reject host/authority placeholders.
    • Extend ScraperJSONRule with optional paths fallback lists, default format = .json when omitted in JSON, and built-in fanartArtist format.
  • Declarative execution & priority chaining (CustomArtistScrapePolicy.swift, ConfigurableScraper+Artist.swift, CustomArtistScraperCoordinator.swift):
    • Support {{artist}}, {{query}}, {{mbid}}, {{album}}, {{lang}}, {{langBase}}, and {{secret.<key>}} in URL, query params, HTTP headers (CRLF-stripped), and body templates, failing closed when required secrets or MBIDs are missing.
    • Enforce endpoint-origin / declared assetHosts allowlist on all returned artwork URLs and verify artist identity on array results.
    • Run enabled custom artist scrapers in Scraping Settings priority order, merging complementary fields across sources and allowing profiles, biographies, portraits, and logos to populate even when MusicBrainz has no match.

Artwork Precedence & Cross-Platform Delivery

  • Portrait precedence: User override > Source-owned > Apple Music (AM artists only) > Enabled custom artist scrapers (priority order) > Fanart.tv BYOK > Wikimedia Commons > Borrowed song cover (CachedArtworkView.swift, TVArtistArtworkView.swift). Wikimedia Commons CC attribution (ArtistMetadataSectionView.swift, TVArtistMetadataSectionView.swift) is shown only when the cached Wikimedia portrait is active.
  • Artwork editor (WikimediaArtistArtworkButton.swift): Exposes manual fetch actions for enabled custom artist scrapers, Fanart.tv (when active), and Wikimedia Commons on iOS & macOS.
  • Platform notes: iOS renders transparent PNG wordmark logos in the existing ArtistHeroTitleBlock slot and exposes the wordmark toggle in Settings; macOS (MacDetailHeader) and Apple TV (TVArtistDetailView) use text artist headers and omit the iOS-only wordmark toggle.
  • Localization: Added localized strings across all 16 .lproj/Localizable.strings files (validated with plutil -lint).

Verification

  • PrimuseKit unit tests (re-run on top of latest origin/main c4ee8513e at e3309063f):
    • xcrun swift test --filter "ArtistMetadataTests|WikimediaArtistPortraitTests|LibraryInsightBatchModeTests|FanartTvPolicyTests|CustomArtistScrapePolicyTests|ScraperJSONRuleTests": 27/27 passed (ScraperJSONRuleTests 7/7 + 20/20 Swift Testing tests across 5 suites).
  • App-layer macOS unit tests & three-platform builds (verified on identical source diff prior to rebasing project.pbxproj onto c4ee8513e; zero source-file overlap with the 7 intervening origin/main commits):
    • xcodebuild test -scheme PrimuseMac -destination 'platform=macOS' -only-testing:PrimuseMacTests/ArtistMetadataStoreTests -only-testing:PrimuseMacTests/FanartTvServiceTests -only-testing:PrimuseMacTests/CustomArtistScraperTests: 9/9 passed (TEST SUCCEEDED).
    • xcodebuild build-for-testing -scheme Primuse -destination 'generic/platform=iOS Simulator' ONLY_ACTIVE_ARCH=YES ARCHS=arm64: TEST BUILD SUCCEEDED.
    • xcodebuild build-for-testing -scheme PrimuseTV -destination 'generic/platform=tvOS Simulator' ONLY_ACTIVE_ARCH=YES ARCHS=arm64: TEST BUILD SUCCEEDED.
  • Architecture gate (on c4ee8513e..e3309063f with XcodeGen 2.46.0):
    • python3 -I scripts/gate/gate.py --root . --require-all --strict-baselines --range origin/main..HEAD: 0 errors, 0 warnings, 0 skipped.
    • python3 -I scripts/gate/gate.py --root . --commits origin/main..HEAD: 0 errors, 0 warnings, 0 skipped.
  • Not verified locally:
    • Interactive iOS and tvOS Simulator runtime UI tests could not be executed locally because the host CoreSimulator framework (1174.9.2) is older than the installed Xcode (1174.21.0).
    • Live network requests against production Fanart.tv / MusicBrainz / third-party custom scraper endpoints were not run; HTTP parsing, header substitution, cooldowns, and fallback precedence were verified with offline mocks.

@chenqi92 chenqi92 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • On iOS and Mac the new sections never load: .task(id:) hangs off a Group { if … } that is empty until the data arrives, so the task never runs (main has a note about this in KaraokeStageView). Similar Artists never shows, and the profile card only appears after something else wrote a record.
  • Commons photos: the attribution lives only in ArtistMetadataStore (500 records, oldest evicted), while the cached portrait is used as the artist image in every list, grid and shelf on iOS, Mac and tvOS. Store author / licence / link with the image and show the credit wherever the photo appears, or use the photo only on the detail page next to its credit. Also reject GFDL-only files, read Restrictions and AttributionRequired, link the licence, and don't credit with the licence alone when the author is missing.
  • Nothing is opt-in. tvOS hard-codes allowNetwork: true: every artist page visit sends the artist name and album titles to MusicBrainz, Wikidata, Commons and Last.fm and replaces the grid artwork. On iOS / Mac the existing Wikipedia bio button now also saves a profile and portrait, and after that every visit downloads the portrait and re-runs custom artist scrapers (the done-marker is memory-only, so again after each launch). Please put profiles and photos behind a switch that is off by default, follow the app's cellular / no-network settings, and fetch on demand instead of per visit.
  • The batch "Public Sources" fill downloads a portrait for every artist, but its text only mentions introductions.
  • Removing the Fanart key, turning Fanart off or removing a custom scraper leaves its images cached and still shown. Purge them.
  • MusicBrainz: musicBrainz(_:) is re-entrant across its sleep, so concurrent callers fire together, and it doesn't share pacing with MusicBrainzScraper. Use one 1 req/s quota for both and back off on 503. Drop tags+genres from inc: they aren't CC0 and nothing shows them.
  • tvOS: the first run happens before the album shelves load, resolves to nil and sets a 6-hour retry block, so the run that has the albums never happens. The fetch task isn't cancelled with the view either.
  • In the artwork editor every failure (revoked key, 429, offline) shows as "no matching portrait".
  • ScraperJSONRule gains a case and a defaulted format, so synced configs fail to decode on older versions. Header templating now applies to every custom scraper, not just artist endpoints.
  • Main actor: ScraperSettings.load() runs inside body-computed task IDs, the 500-record file loads synchronously on first access, matchingLibraryArtists does up to 50 catalog lookups on the main actor, and failures / retryAfterByID / customEnrichedRevisionByID grow without a cap.
  • Design: on tvOS put the profile block after the albums, not between the bio and the album shelves (#549 asks for albums first). Drop the Bandcamp store link. Fanart.tv images need a fanart.tv credit next to them, and the custom-source wordmark needs the same toggle as the others.
  • The tests build the store with the real FanartTvSettingsStore.shared and CustomArtistScraperCoordinator.shared, so on a machine with a key they hit the network.
  • This is five features in one commit. Please split it (profiles, Commons photos, Fanart.tv, custom artist scrapers, similar artists) so each can be checked and merged on its own.

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.

Add structured artist metadata, portrait, and wordmark scraping (MusicBrainz/Wikimedia, Fanart.tv BYOK, and custom artist scrapers)

2 participants