Files
minstrel/internal/coverart/provider.go
T
bvandeusenandClaude Opus 5.5 e1f270362d
release / go (push) Successful in 2m7s
release / web (push) Successful in 1m25s
release / govulncheck (push) Successful in 21s
release / integration (push) Successful in 4m30s
release / android (push) Successful in 4m39s
release / Build signed APK (push) Successful in 5m10s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 29s
release / Verify release artifacts (tag releases only) (push) Skipped
chore(release): everything that ships points at GitHub and GHCR (#7897)
- Module path: github.com/Fabled-Sword/minstrel, in go.mod, every
  import and the Dockerfile's version ldflags.
- buildinfo.ProjectURL, the contact outside services see in Minstrel's
  User-Agent: https://github.com/Fabled-Sword/minstrel.
- README's compose example pulls ghcr.io/fabled-sword/minstrel:latest.
- docs/security.md sends problem reports to the GitHub issues.
- The demo-library stack builds Minstrel from the checkout, since :dev
  is not published to GHCR.
- hygiene.go's same-site example uses example.com names.

The workbench CI (.gitea/, ci/, export-ignored) still builds and
publishes :dev to the private registry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 19:28:16 -05:00

109 lines
4.2 KiB
Go

package coverart
import (
"context"
"github.com/Fabled-Sword/minstrel/internal/apierror"
"github.com/Fabled-Sword/minstrel/internal/providers"
)
// Provider is the base shape every cover-art source implements; the
// capability interfaces below say what it can fetch. Providers register at
// init() via Register(). Its ID is persisted in cover_art_source /
// artist_art_source and keyed in cover_art_provider_settings.
type Provider = providers.Provider
// ProviderSettings is what Configure receives. TheAudioDB falls back to
// its public test key on an empty APIKey; MBCAA ignores the key.
type ProviderSettings = providers.Settings
// ArtistRef is the lookup key passed to ArtistArtProvider.FetchArtistArt.
// MBID is preferred when present; Name is the always-populated fallback
// for providers that support name-based search (Deezer, Last.fm).
// MBID-only providers (TheAudioDB) return ErrNotFound when MBID is empty.
type ArtistRef struct {
MBID string
Name string
}
// AlbumRef is the lookup key passed to AlbumCoverProvider.FetchAlbumCover.
// Same MBID-preferred semantics as ArtistRef; ArtistName + AlbumTitle
// support name-based providers.
type AlbumRef struct {
MBID string
ArtistName string
AlbumTitle string
}
// AlbumCoverProvider is an opt-in capability: providers implementing
// it can fetch album cover art. MBID-only providers use ref.MBID and
// return ErrNotFound when it is empty; name-based providers (Deezer,
// Last.fm) fall back to ref.ArtistName + ref.AlbumTitle.
type AlbumCoverProvider interface {
Provider
// FetchAlbumCover returns the image bytes for the given album ref,
// or ErrNotFound (terminal — no art available) /
// ErrTransient (retry-eligible failure).
FetchAlbumCover(ctx context.Context, ref AlbumRef) ([]byte, error)
}
// ArtistArtProvider is an opt-in capability: providers implementing
// it can fetch artist images. Returns thumb + fanart atomically at
// the JSON metadata step (one round-trip yields both URLs); the two
// image GETs are independent — partial success returns whatever bytes
// landed and the source is still stamped, so the enricher persists
// asymmetric results (thumb-only or fanart-only) gracefully.
type ArtistArtProvider interface {
Provider
FetchArtistArt(ctx context.Context, ref ArtistRef) (thumb, fanart []byte, err error)
}
// TestableProvider can answer the admin Test-Connection button. MBCAA and
// TheAudioDB implement it.
type TestableProvider = providers.Testable
// ErrNotTestable and ErrProviderNotFound are the shared providers errors,
// so a handler can test for either family's with one errors.Is.
var (
ErrNotTestable = providers.ErrNotTestable
ErrProviderNotFound = providers.ErrProviderNotFound
)
// ErrNotFound indicates the upstream confirmed there is no art for
// this MBID — a terminal-this-pass result. The enricher treats this
// as "try the next provider in the chain"; if all providers return
// ErrNotFound, the row settles to cover_art_source='none'.
//
// Aliased to apierror.ErrNotFound so handler error mapping (errors.Is
// against the shared sentinel) and existing per-package callsites both
// resolve to the same pointer.
var ErrNotFound = apierror.ErrNotFound
// ErrTransient indicates a temporary failure (5xx, network, timeout,
// auth issue). The enricher leaves the row's source NULL so the next
// scan pass can retry.
var ErrTransient = providers.ErrTransient
// registry is every compiled-in cover-art provider. The enricher iterates
// it filtered by the current settings.
var registry = providers.NewRegistry("coverart")
// Register adds a provider. Call it from a provider file's init(); a
// duplicate ID panics.
func Register(p Provider) { registry.Register(p) }
// AllProviders returns a snapshot of every registered provider in
// registration order.
func AllProviders() []Provider { return registry.All() }
// ProviderByID returns the registered provider with id, or
// ErrProviderNotFound.
func ProviderByID(id string) (Provider, error) { return registry.ByID(id) }
// resetRegistryForTests empties the registry. Tests only.
func resetRegistryForTests() { registry.ResetForTests() }
// ResetRegistryForTests empties the registry, for tests in other packages
// (internal/api). Tests only.
func ResetRegistryForTests() { registry.ResetForTests() }