discogs

package
v0.1.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: 10 Imported by: 0

Documentation

Overview

Package discogs is the library behind the discogs command line: the HTTP client, request shaping, and the typed data models for the Discogs music database API.

The Client here is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite, and retries transient failures (429 and 5xx). Build endpoint calls and JSON decoding on top of it.

Index

Constants

View Source
const BaseURL = "https://" + Host

BaseURL is the root every request is built from.

View Source
const DefaultUserAgent = "discogs-cli/0.1.0 (github.com/tamnd/discogs-cli)"

DefaultUserAgent identifies the client to Discogs. A real, honest User-Agent is both polite and the thing most likely to keep you unblocked.

View Source
const Host = "api.discogs.com"

Host is the API host this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Artist

type Artist struct {
	ID      int      `kit:"id" json:"id"`
	Name    string   `json:"name"`
	Profile string   `json:"profile"`
	URLs    []string `json:"urls"`
	Members []string `json:"members"`
}

Artist is a Discogs artist record.

type Client

type Client struct {
	HTTP      *http.Client
	UserAgent string
	// Rate is the minimum gap between requests. Zero means no pacing.
	Rate    time.Duration
	Retries int
	// contains filtered or unexported fields
}

Client talks to the Discogs API over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults: a 30s timeout, a 200ms minimum gap between requests, and three retries on transient errors.

func (*Client) Get

func (c *Client) Get(ctx context.Context, url string) ([]byte, error)

Get fetches url and returns the response body. It paces and retries according to the client's settings.

func (*Client) GetArtist

func (c *Client) GetArtist(ctx context.Context, id string) (*Artist, error)

GetArtist fetches an artist by numeric ID.

func (*Client) GetLabel

func (c *Client) GetLabel(ctx context.Context, id string) (*Label, error)

GetLabel fetches a record label by numeric ID.

func (*Client) GetMaster

func (c *Client) GetMaster(ctx context.Context, id string) (*Master, error)

GetMaster fetches a master release by numeric ID.

func (*Client) GetRelease

func (c *Client) GetRelease(ctx context.Context, id string) (*Release, error)

GetRelease fetches a release by numeric ID.

func (*Client) Search

func (c *Client) Search(ctx context.Context, query, typ string, limit int) ([]*SearchResult, error)

Search queries the Discogs database.

type Domain

type Domain struct{}

Domain is the Discogs driver. It carries no state; the per-run client is built by the factory Register hands kit.

func (Domain) Classify

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

Classify turns any accepted input into (uriType, id). - Numeric ID → default "release" type - URL path like /artists/45 → parse type+ID - Non-numeric, non-URL → "search" type

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 canonical 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

type Label struct {
	ID          int    `kit:"id" json:"id"`
	Name        string `json:"name"`
	Profile     string `json:"profile"`
	ContactInfo string `json:"contact_info"`
}

Label is a Discogs record label.

type Master

type Master struct {
	ID      int      `kit:"id" json:"id"`
	Title   string   `json:"title"`
	Year    int      `json:"year"`
	Artists []string `json:"artists"`
	Genres  []string `json:"genres"`
	Styles  []string `json:"styles"`
}

Master is a Discogs master release record.

type Release

type Release struct {
	ID        int      `kit:"id" json:"id"`
	Title     string   `json:"title"`
	Year      int      `json:"year"`
	Artists   []string `json:"artists"`
	Genres    []string `json:"genres"`
	Styles    []string `json:"styles"`
	Tracklist []Track  `json:"tracklist"`
}

Release is a Discogs release record.

type SearchResult

type SearchResult struct {
	ID    int    `kit:"id" json:"id"`
	Title string `json:"title"`
	Type  string `json:"type"`
	URI   string `json:"uri"`
	Thumb string `json:"thumb"`
}

SearchResult is one item returned by the database search endpoint.

type Track

type Track struct {
	Position string `json:"position"`
	Title    string `json:"title"`
	Duration string `json:"duration"`
}

Track is one track entry in a release or master.

Jump to

Keyboard shortcuts

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