Documentation
¶
Overview ¶
Package meta fetches game metadata and art: descriptions, developers, genres, controller support, covers, hero banners, logos and icons, from Steam (no key needed), GOG and, with the user's key, SteamGridDB. Every image is downloaded from an allowlisted host, decoded, resized and re-encoded before it is stored, so nothing but plain pixels reaches the interface.
Index ¶
- Constants
- Variables
- func Accent(img image.Image) string
- func ArtHandler(artDir string) func(http.Handler) http.Handler
- func ImageHandler(prefix, dir string) func(http.Handler) http.Handler
- func IsStoredArt(artDir, url string) bool
- func PruneArt(artDir string, keep map[string]bool, grace time.Duration) (removed int, freed int64)
- func SetArt(m *library.Meta, kind Kind, art string, artDir string) bool
- func StoreImage(dir string, data []byte, kind Kind) (string, error)
- type Choice
- type Client
- func (c *Client) ArtChoices(ctx context.Context, r Request, kind Kind, current *library.Meta) ([]Choice, error)
- func (c *Client) BaseGame(ctx context.Context, appID int) (StoreHit, bool)
- func (c *Client) Fetch(ctx context.Context, r Request) (*library.Meta, error)
- func (c *Client) FetchImage(ctx context.Context, src, dir string, kind Kind) (string, error)
- func (c *Client) PCGamingWiki(ctx context.Context, title string) (*PCGW, error)
- func (c *Client) SearchSteam(ctx context.Context, term string) ([]StoreHit, error)
- func (c *Client) UseTransport(rt http.RoundTripper)
- type Kind
- type PCGW
- type Request
- type StoreHit
Constants ¶
const Version = 4
Version marks what Fetch gathers; metadata from an older version is fetched again (2: backdrops; 3: full-size backdrops, round tiles, Steam's own art files when its store lists none; 4: PCGamingWiki's controller support, the Epic store's art for games only Epic sells, backdrops picked from several and kept up to 4K).
Variables ¶
var ErrNotAllowed = errors.New("host not allowed")
ErrNotAllowed means a URL points somewhere Seaglass doesn't fetch from.
var ErrRateLimited = errors.New("rate limited")
ErrRateLimited means a source asked us to slow down.
Functions ¶
func Accent ¶
Accent picks a lively colour from an image: the most prominent hue among saturated, bright-enough pixels, brought to a lightness that reads on a dark background. "" when the image is too grey.
func ArtHandler ¶
ArtHandler serves stored art under /art/ to the interface, and passes every other request on.
func ImageHandler ¶ added in v1.6.0
ImageHandler serves the images stored in dir (content-addressed, as StoreImage names them) under prefix, and passes every other request on.
func IsStoredArt ¶
IsStoredArt reports whether url names an image stored in artDir.
func PruneArt ¶
PruneArt deletes stored images no game uses anymore (art replaced by a refresh, games removed) and leftovers of cut-short writes. keep holds the art URLs in use. Files younger than grace stay: a fetch may be about to use them.
Types ¶
type Choice ¶
type Choice struct {
Art string `json:"art"` // /art/… URL
Source string `json:"source"`
Width int `json:"width"`
Height int `json:"height"`
}
Choice is one picture a game's art can be changed to: already stored (the interface only shows local art), with where it came from.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the metadata sources.
func (*Client) ArtChoices ¶
func (c *Client) ArtChoices(ctx context.Context, r Request, kind Kind, current *library.Meta) ([]Choice, error)
ArtChoices gathers the pictures a game's cover, backdrop, hero or logo could be: what Steam has (its library art and every screenshot), the Epic store's page for a game only Epic sells, PCGamingWiki's cover and, with a key, SteamGridDB's community art. Each is downloaded and stored the way fetched art is. The current picture comes first.
func (*Client) BaseGame ¶
BaseGame is the game a DLC belongs to; false when appID is a game itself (or the store doesn't say). A folder named after a game's expansion ("Cyberpunk 2077 Phantom Liberty") holds the game.
func (*Client) Fetch ¶
Fetch gathers metadata and art for one game. Missing pieces are simply left empty; an error means nothing at all could be fetched (and is ErrRateLimited when the caller should back off).
func (*Client) FetchImage ¶ added in v1.6.0
FetchImage downloads an image from an allowlisted host and stores it like StoreImage.
func (*Client) PCGamingWiki ¶
PCGamingWiki looks a game up by title. The wiki's redirects cover most other spellings ("Alan Wake 2" → "Alan Wake II"); a title ending in a number is also tried with the other kind of numeral.
func (*Client) SearchSteam ¶
SearchSteam looks a title up on the Steam store.
func (*Client) UseTransport ¶
func (c *Client) UseTransport(rt http.RoundTripper)
UseTransport sends requests through rt and drops the waits between them: for tests that record and replay the sources' answers (rt then spaces out the requests that really go out).
type Kind ¶
type Kind string
Kind is which picture of a game an image is.
const ( Cover Kind = "cover" // portrait, 2:3 Hero Kind = "hero" // wide banner behind the details Backdrop Kind = "backdrop" // 16:9, sharp enough to fill the big picture screen Tile Kind = "tile" // square: key art with the logo, for round tiles Logo Kind = "logo" // transparent title logo Icon Kind = "icon" )
type PCGW ¶
type PCGW struct {
Title string // the page's name: the game's usual title
SteamAppID int
GogID string
EpicSlug string // the Epic store page (store.epicgames.com/p/<slug>)
Cover string // file name on the wiki
Developers []string
ReleaseDate string
Genres []string
// Controllers: DualSense is "yes" (DualSense or DualSense Edge
// supported), "dualshock" (DualShock 4 only), "no" (no PlayStation
// controllers) or "" (the page doesn't say); Controller is "full",
// "partial" or "".
DualSense string
Controller string
}
PCGW is what a PCGamingWiki page says about a game.
type Request ¶
type Request struct {
Title string
SteamAppID int
GogID string
EpicApp string // namespace:item:appName, for games Steam doesn't have
Keep *library.Meta // previous metadata: user-chosen art is kept
// PCGW is the game's PCGamingWiki page when the caller already looked
// it up; otherwise Fetch looks it up by Title.
PCGW *PCGW
}
Request says which game to fetch metadata for.