musicbrainz

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package musicbrainz is the library behind the musicbrainz command line: the HTTP client, request shaping, and typed data models for the MusicBrainz open music metadata database (https://musicbrainz.org/ws/2).

MusicBrainz is rate-limited to 1 request per second. The Client paces requests at 1100 ms intervals and retries 503/429/5xx with exponential backoff. A descriptive User-Agent header is required by the API Terms of Service.

Index

Constants

View Source
const Host = "musicbrainz.org"

Host is the site this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Artist

type Artist struct {
	Rank      int    `json:"rank"`
	MBID      string `json:"mbid"`
	Name      string `json:"name"`
	Type      string `json:"type"`       // Group, Person, Orchestra, Choir, Other
	Country   string `json:"country"`    // ISO 3166-1 alpha-2 country code
	Area      string `json:"area"`       // area name
	BeginDate string `json:"begin_date"` // YYYY or YYYY-MM or YYYY-MM-DD
	EndDate   string `json:"end_date"`
	Score     int    `json:"score"` // relevance 0-100
	URL       string `json:"url"`   // https://musicbrainz.org/artist/{id}
}

Artist is one result from a MusicBrainz artist search.

type ArtistDetail added in v0.2.0

type ArtistDetail struct {
	MBID      string        `json:"mbid"`
	Name      string        `json:"name"`
	Type      string        `json:"type"`
	Country   string        `json:"country"`
	Area      string        `json:"area"`
	BeginDate string        `json:"begin_date"`
	EndDate   string        `json:"end_date"`
	URL       string        `json:"url"`
	Releases  []ReleaseStub `json:"releases"`
}

ArtistDetail is the full artist record from a lookup by MBID.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to MusicBrainz over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) Artists

func (c *Client) Artists(ctx context.Context, query string, limit int) ([]Artist, error)

Artists searches MusicBrainz for artists matching query. Returns at most limit results (pass 0 for default of 10; max 100).

func (*Client) GetArtist added in v0.2.0

func (c *Client) GetArtist(ctx context.Context, mbid string) (*ArtistDetail, error)

GetArtist fetches a full artist record by MBID, including their releases.

func (*Client) Labels added in v0.2.0

func (c *Client) Labels(ctx context.Context, query string, limit int) ([]Label, error)

Labels searches MusicBrainz for labels matching query. Returns at most limit results (pass 0 for default of 10; max 100).

func (*Client) Recordings

func (c *Client) Recordings(ctx context.Context, query string, limit int) ([]Recording, error)

Recordings searches MusicBrainz for recordings matching query. Returns at most limit results (pass 0 for default of 10; max 100).

func (*Client) ReleaseGroups added in v0.2.0

func (c *Client) ReleaseGroups(ctx context.Context, query string, limit int) ([]ReleaseGroup, error)

ReleaseGroups searches MusicBrainz for release groups matching query. Returns at most limit results (pass 0 for default of 10; max 100).

func (*Client) Releases added in v0.2.0

func (c *Client) Releases(ctx context.Context, query string, limit int) ([]Release, error)

Releases searches MusicBrainz for releases matching query. Returns at most limit results (pass 0 for default of 10; max 100).

type Config

type Config struct {
	BaseURL   string
	UserAgent string
	Rate      time.Duration
	Timeout   time.Duration
	Retries   int
}

Config holds all tunable parameters for the Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with the MusicBrainz public API base URL, a descriptive User-Agent, and a 1100 ms rate floor (10% above the 1 req/s limit).

type Domain

type Domain struct{}

Domain is the musicbrainz driver.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns an input into the canonical (type, id). MusicBrainz entities live at /{type}/{uuid}.

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate returns the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

type Label added in v0.2.0

type Label struct {
	Rank    int    `json:"rank"`
	MBID    string `json:"mbid"`
	Name    string `json:"name"`
	Type    string `json:"type"`    // Original Production, Bootleg Production, etc.
	Country string `json:"country"` // ISO 3166-1 alpha-2
	Score   int    `json:"score"`
	URL     string `json:"url"` // https://musicbrainz.org/label/{id}
}

Label is one result from a MusicBrainz label search.

type Recording

type Recording struct {
	Rank         int    `json:"rank"`
	MBID         string `json:"mbid"`
	Title        string `json:"title"`
	ArtistCredit string `json:"artist_credit"` // primary artist-credit name(s)
	ReleaseTitle string `json:"release_title"`
	ReleaseDate  string `json:"release_date"`
	LengthMs     int    `json:"length_ms"` // duration in ms (0 if unknown)
	Score        int    `json:"score"`     // relevance 0-100
	URL          string `json:"url"`       // https://musicbrainz.org/recording/{id}
}

Recording is one result from a MusicBrainz recording search.

type Release added in v0.2.0

type Release struct {
	Rank         int    `json:"rank"`
	MBID         string `json:"mbid"`
	Title        string `json:"title"`
	Status       string `json:"status"`        // Official, Promotional, Bootleg, Pseudo-Release
	Date         string `json:"date"`          // YYYY or YYYY-MM or YYYY-MM-DD
	Country      string `json:"country"`       // ISO 3166-1 alpha-2
	Label        string `json:"label"`         // first label name
	Type         string `json:"type"`          // Album, Single, EP, Compilation, etc.
	ArtistCredit string `json:"artist_credit"` // primary artist-credit name(s)
	Score        int    `json:"score"`
	URL          string `json:"url"` // https://musicbrainz.org/release/{id}
}

Release is one result from a MusicBrainz release search.

type ReleaseGroup added in v0.2.0

type ReleaseGroup struct {
	Rank             int    `json:"rank"`
	MBID             string `json:"mbid"`
	Title            string `json:"title"`
	Type             string `json:"type"`               // Album, Single, EP, Broadcast, Other
	FirstReleaseDate string `json:"first_release_date"` // YYYY or YYYY-MM or YYYY-MM-DD
	ArtistCredit     string `json:"artist_credit"`
	Score            int    `json:"score"`
	URL              string `json:"url"` // https://musicbrainz.org/release-group/{id}
}

ReleaseGroup is one result from a MusicBrainz release-group search.

type ReleaseStub added in v0.2.0

type ReleaseStub struct {
	MBID   string `json:"mbid"`
	Title  string `json:"title"`
	Date   string `json:"date"`
	Status string `json:"status"`
}

ReleaseStub is a brief release summary embedded in ArtistDetail.

Jump to

Keyboard shortcuts

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