audiodb

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: 11 Imported by: 0

Documentation

Overview

Package audiodb is the library behind the audiodb command line: the HTTP client, request shaping, and the typed data models for TheAudioDB 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 the transient failures (429 and 5xx) that any public API throws under load.

Index

Constants

View Source
const Host = "www.theaudiodb.com"

Host is the site this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Album

type Album struct {
	ID         string `json:"id"`
	Name       string `json:"name"`
	ArtistID   string `json:"artist_id,omitempty"`
	ArtistName string `json:"artist,omitempty"`
	Year       string `json:"year,omitempty"`
	Genre      string `json:"genre,omitempty"`
	Label      string `json:"label,omitempty"`
	Score      string `json:"score,omitempty"`
}

Album is a music album record from TheAudioDB.

type Artist

type Artist struct {
	ID         string `json:"id"`
	Name       string `json:"name"`
	Genre      string `json:"genre,omitempty"`
	Country    string `json:"country,omitempty"`
	FormedYear string `json:"formed_year,omitempty"`
	Members    string `json:"members,omitempty"`
	Biography  string `json:"biography,omitempty"`
}

Artist is a music artist record from TheAudioDB.

type Client

type Client struct {
	HTTP *http.Client
	// contains filtered or unexported fields
}

Client talks to TheAudioDB API over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client with DefaultConfig settings.

func NewClientWithConfig

func NewClientWithConfig(cfg Config) *Client

NewClientWithConfig returns a Client configured with the given Config.

func (*Client) Discography

func (c *Client) Discography(ctx context.Context, artistName string) ([]*Album, error)

Discography returns all albums for a given artist name.

func (*Client) Get

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

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

func (*Client) SearchAlbum

func (c *Client) SearchAlbum(ctx context.Context, artistName, albumName string) ([]*Album, error)

SearchAlbum searches for albums by artist name and album name.

func (*Client) SearchArtist

func (c *Client) SearchArtist(ctx context.Context, name string) ([]*Artist, error)

SearchArtist searches for artists by name.

func (*Client) SearchTrack

func (c *Client) SearchTrack(ctx context.Context, artistName, trackName string) ([]*Track, error)

SearchTrack searches for tracks by artist name and track name.

type Config

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

Config holds all tuneable client settings.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults for the TheAudioDB free API.

type Domain

type Domain struct{}

Domain is the audiodb 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 the canonical (type, id).

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 is the inverse: 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 Track

type Track struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	AlbumID     string `json:"album_id,omitempty"`
	AlbumName   string `json:"album,omitempty"`
	Duration    string `json:"duration_ms,omitempty"`
	Genre       string `json:"genre,omitempty"`
	TrackNumber string `json:"track_number,omitempty"`
	MusicVideo  string `json:"music_video,omitempty"`
}

Track is a music track record from TheAudioDB.

Jump to

Keyboard shortcuts

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