lookup

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package lookup finds out what an audio CD is, from MusicBrainz and the Cover Art Archive, using nothing but its table of contents: no names, no audio, and nothing about the person or their files. No key is needed.

It needs no image and no server. A program reading a real drive can fill in a wittycd.TOC from the drive's own table of contents and ask the same way.

matches, err := (&lookup.Client{UserAgent: "MyPlayer/1.0 ( https://example.org )"}).Find(ctx, toc)

The services ask for a client that names itself and for at most one request a second. Every Client in a program shares one gate, so that holds however many there are. Their data is CC0; cover pictures belong to their owners. Show Attribution wherever their data is used.

Index

Constants

View Source
const Attribution = "Album data from MusicBrainz (CC0). Covers from the Cover Art Archive."

Attribution is what to show wherever their data is used.

Variables

View Source
var ErrBusy = errors.New("MusicBrainz can't be reached just now")

ErrBusy says the service asked to slow down or can't be reached. Try again later.

Functions

func SameAlbum

func SameAlbum(ms []Match) bool

SameAlbum says whether matches all name one album with the same tracks, as the many pressings of a disc do, so any of them will do without asking anyone.

func ValidID

func ValidID(id string) bool

ValidID says whether this is a MusicBrainz release ID.

Types

type Client

type Client struct {
	// HTTP is the client to use; nil means one with no special limits. A server
	// should give one that can't be redirected onto its own network.
	HTTP *http.Client
	// UserAgent names your program, with a way to contact you, as the service asks:
	// "MyPlayer/1.0 ( https://example.org )".
	UserAgent string
	// Base and CoverBase replace the services' addresses in tests.
	Base, CoverBase string
}

Client asks the services. The zero value works.

func (*Client) Cover

func (c *Client) Cover(ctx context.Context, releaseID string, size int) ([]byte, error)

Cover fetches a release's front cover, 250, 500 or 1200 pixels across.

func (*Client) Find

func (c *Client) Find(ctx context.Context, toc wittycd.TOC) ([]Match, error)

Find returns the releases a disc could be, the likeliest first: those listing its disc ID, or, when none does, those whose track lengths match. An empty answer means nobody knows the disc yet.

func (*Client) Release

func (c *Client) Release(ctx context.Context, releaseID string, toc wittycd.TOC) (*Match, error)

Release asks for one release by its ID, for when a person picked it.

type Match

type Match struct {
	ReleaseID string `json:"releaseId"`
	Title     string `json:"title"`
	Artist    string `json:"artist"`
	Date      string `json:"date,omitempty"`
	Country   string `json:"country,omitempty"`
	Barcode   string `json:"barcode,omitempty"`
	Label     string `json:"label,omitempty"`
	// Disc is which disc of the release this one is, of Discs.
	Disc  int `json:"disc"`
	Discs int `json:"discs"`
	// Exact: the release lists this very disc ID. Otherwise its track lengths are
	// only close, so it could be another pressing, or a different album.
	Exact    bool        `json:"exact"`
	HasCover bool        `json:"hasCover"`
	Tracks   []TrackName `json:"tracks"`
	Group    string      `json:"group,omitempty"`
	URL      string      `json:"url"`
}

Match is one release a disc could be.

func (*Match) Year

func (m *Match) Year() int

Year is the year of a match, or 0 when it doesn't say.

type TrackName

type TrackName struct {
	Number int    `json:"number"`
	Title  string `json:"title"`
	Artist string `json:"artist,omitempty"`
}

TrackName is a track's name. Artist is empty when it is the album's.

Jump to

Keyboard shortcuts

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