artwork

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2026 License: GPL-3.0 Imports: 24 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package artwork reads a core's artwork index and decides which local artwork files to download. The index lists, per game ID, the images the artwork site serves: their type, the values that tell images of one type apart (disc number, region, variant), path relative to the index, size, and hashes. The index is used only when its signature file holds a valid signature by one of the core's artwork keys, and a downloaded image is kept only when its size and SHA-256 match the signed index. A game's images are stored in its own directory under names built from the entry's values, never from its path: <type>[_<disc>][_<region>][_<variant>].<ext>.

Index

Constants

View Source
const IndexFile = "index.json"

IndexFile is the index's name, relative to the artwork base URL.

View Source
const IndexVersion = 1

IndexVersion is the index format this package reads.

View Source
const MaxImageDimension = 4096

MaxImageDimension is the largest width or height of an artwork image that is decoded.

View Source
const MaxImageSize = 10 * 1024 * 1024

MaxImageSize is the largest image accepted: 10 MiB.

View Source
const MaxIndexSize = 16 * 1024 * 1024

MaxIndexSize is the largest index accepted: 16 MiB.

View Source
const SignatureFile = "index.sig"

SignatureFile is the name of the index's signature file, relative to the artwork base URL. See the signing package for its format.

Variables

This section is empty.

Functions

func BoxArtPath

func BoxArtPath(dir, preferred string) string

BoxArtPath returns the path of the front cover shown for a game in its game directory dir: the first front in LocalFiles order for preferred, one of region.All. That is the preferred region's front, then the other regions' in regionRank order, then a front with no region, then the legacy boxart.png. When the game has no front, the boxart.webp path is returned.

func Caption

func Caption(f LocalFile) string

Caption returns the on-screen name of a local image, such as "Front", "Disc 2 (USA)" or "Flyer B". A region other than USA, Japan and Europe is shown as "Other".

func Download

func Download(baseURL, dir string, f File) error

Download fetches f from baseURL, checks it against the index entry, and writes it atomically to the game directory dir under LocalName. Nothing is written when the download fails or does not match.

func DownloadTypes

func DownloadTypes(setting string) []string

DownloadTypes returns the image types a scan downloads for an artwork download setting (storage.ArtworkDownload*): every type this build knows, the front cover, the covers, or none. Any other value downloads every type.

func FileURL

func FileURL(baseURL, p string) (string, error)

FileURL returns the URL of an index path under baseURL, which must be an absolute HTTPS URL with a host. The path's segments are escaped, so names with spaces are fetched correctly.

func Load

func Load(path string) (image.Image, error)

Load decodes the artwork image file at path. The dimensions are read from the image header first and an image larger than MaxImageDimension on either side is refused before it is decoded, so the memory a file can take is bounded by the dimension limit, whatever the file size.

func LocalName

func LocalName(f File) string

LocalName returns the file name an image is stored under in its game's directory, built from the entry's values and its path's extension: <type>[_<disc>][_<region>][_<variant>].<ext>, such as "disc_2_eu.webp". Parse has checked the values, so the name is a plain file name.

func NeedsDownload

func NeedsDownload(dir string, f File) bool

NeedsDownload reports whether the game directory dir lacks f or holds a copy whose size or CRC-32 differs from the index.

func Size

func Size(path string) (width, height int, err error)

Size returns the width and height of the artwork image file at path, read from its header alone, so it is cheap enough to call before deciding on a layout. It returns an error for a file Load refuses on its dimensions.

func SupersededBoxArt

func SupersededBoxArt(dir string) (path string, ok bool)

SupersededBoxArt returns the legacy boxart.png in the game directory dir when boxart.webp is also there, the only artwork Clean Library removes. ok is false when either file is missing.

func ValidPath

func ValidPath(p string) bool

ValidPath reports whether p is a relative path of plain segments: no leading slash, no backslashes or control characters, and no empty, "." or ".." segments.

func Verify

func Verify(data []byte, f File) error

Verify checks downloaded image data against its index entry by size and SHA-256. CRC-32 is used only to notice changed local files; it does not show a download is the vetted image.

Types

type File

type File struct {
	Type    string `json:"type"`
	Path    string `json:"path"`
	Disc    int    `json:"disc,omitempty"`    // disc number, 1 and up
	Region  string `json:"region,omitempty"`  // lower case letters, such as "us"
	Variant string `json:"variant,omitempty"` // one lower case letter
	Size    int64  `json:"size"`
	CRC32   string `json:"crc32"`
	SHA256  string `json:"sha256"`
}

File is one image in the index. Disc, Region and Variant tell images of one type apart; each is set only on the types it applies to (see typeFields). Disc is set when the game has more than one disc, Region when the game was released in more than one region (even when only one region's image is available), and Variant when the game has more than one image of that type.

type Index

type Index struct {
	Version int               `json:"version"`
	Games   map[string][]File `json:"games"`
}

Index is a parsed artwork index.

func FetchIndex

func FetchIndex(baseURL string, keys signing.Keys) (*Index, error)

FetchIndex downloads the index and its signature file under baseURL, checks that the signature file holds a valid signature of the index by one of keys, and only then parses the index. Without keys, or when the signature does not verify, no index is returned.

func Parse

func Parse(data []byte) (*Index, error)

Parse decodes an index and checks its version and every entry. An index with an unknown version or any invalid entry is rejected as a whole.

func (*Index) Files

func (ix *Index) Files(gameID string, types []string) []File

Files returns a game's index entries whose type is one of types, in index order. Types this build does not know are never returned.

type LocalFile

type LocalFile struct {
	Path    string
	Type    string
	Disc    int
	Region  string
	Variant string
}

LocalFile is an artwork image in a game's directory, with the values its name carries

func LocalFiles

func LocalFiles(dir, preferred string) []LocalFile

LocalFiles returns the artwork images in the game directory dir whose names follow LocalName for a known type, in display order: the covers, then the discs, flyers and posters. Covers are grouped by region, each region's front before its back; discs are grouped by region, each in disc number order; flyers and posters are in variant order. Regions are ordered by regionRank with preferred, a storage.BoxArtRegion* setting, first. The legacy boxart.png is listed only when the game has no other front, after the other covers. When two files carry the same values, the .webp one is used. Other files are ignored. A missing or empty directory gives nil.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL