mbdb

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2025 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Overview

Package mbdb contains functionality related to the MusicBrainz database.

Index

Constants

This section is empty.

Variables

View Source
var DisallowQueries = func(db *DB) { db.disallowQueries = true }

DisallowQueries is an Option that configures DB to report an error when it would need to perform a query over the network.

Functions

func ExtractMBID added in v0.1.13

func ExtractMBID(url string) string

ExtractMBID returns the first plausible MBID found after spliting the supplied string on slashes. It returns an empty string if no MBID is found. It is safe to call with a bare MBID.

func IsMBID

func IsMBID(mbid string) bool

IsMBID returns true if mbid looks like a correctly-formatted MBID (i.e. a UUID). Note that this method does not check that the MBID is actually assigned to anything.

func ShortenContext

func ShortenContext(ctx context.Context, t time.Duration) (context.Context, context.CancelFunc)

ShortenContext returns a context derived from ctx with its deadline shortened by t. If ctx does not have a deadline, a derived deadline-less context is returned. The caller must call the returned cancel function to release resources.

Types

type DB

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

DB queries the MusicBrainz database using its API. See https://musicbrainz.org/doc/MusicBrainz_API.

func NewDB

func NewDB(opts ...Option) *DB

NewDB returns a new DB object.

func (*DB) GetDBRelease added in v0.1.13

func (db *DB) GetDBRelease(ctx context.Context, mbid string) (DBRelease, error)

GetDBRelease uses the internal, undocumented /ws/js API to fetch information about the release with the supplied MBID. The only reason to use this is to get internal database row IDs for entities rather than their MBIDs.

func (*DB) GetDatabaseID

func (db *DB) GetDatabaseID(ctx context.Context, mbid string) (int32, error)

GetDatabaseID returns the database ID (e.g. artist.id) corresponding to the entity with the specified MBID (e.g. artist.gid).

func (*DB) GetRelease added in v0.1.13

func (db *DB) GetRelease(ctx context.Context, mbid string) (Release, error)

GetRelease returns information about the release with the supplied MBID.

func (*DB) GetURLRels added in v0.1.13

func (db *DB) GetURLRels(ctx context.Context, urls ...string) (map[string]EntityInfoMap, error)

GetURLRels returns entities related to the supplied URLs. The returned map is keyed by URL.

func (*DB) SetDBReleaseForTest added in v0.1.13

func (db *DB) SetDBReleaseForTest(mbid string, rel DBRelease)

func (*DB) SetDatabaseIDForTest

func (db *DB) SetDatabaseIDForTest(mbid string, id int32)

SetDatabaseIDForTest hardcodes an ID for GetDatabaseID to return.

func (*DB) SetURLEntityInfosForTest added in v0.1.13

func (db *DB) SetURLEntityInfosForTest(url string, artists, labels []EntityInfo)

SetURLEntityInfosForTest hardcodes entities for GetURLRels to return.

type DBMedium added in v0.1.13

type DBMedium struct {
	Tracks []DBTrack `json:"tracks"`
}

DBMedium describes a medium loaded from the internal /ws/js service.

type DBRecording added in v0.1.13

type DBRecording struct {
	ID     int32  `json:"id"`
	Name   string `json:"name"`
	Length int64  `json:"length"`
}

DBRecording describes a recording loaded from the internal /ws/js service.

type DBRelease added in v0.1.13

type DBRelease struct {
	Mediums []DBMedium `json:"mediums"`
}

DBRelease describes a release loaded from the internal /ws/js service.

func (*DBRelease) GetTrackAtIndex added in v0.1.13

func (rel *DBRelease) GetTrackAtIndex(i int) *DBTrack

GetTrackAtIndex returns the 0-based i-th track from rel.

func (*DBRelease) NumTracks added in v0.1.13

func (rel *DBRelease) NumTracks() int

NumTracks returns the number of tracks in rel across all mediums.

type DBTrack added in v0.1.13

type DBTrack struct {
	ID        int32       `json:"id"`
	Name      string      `json:"name"`
	Length    int64       `json:"length"`
	Recording DBRecording `json:"recording"`
}

DBTrack describes a track loaded from the internal /ws/js service.

type EntityInfo

type EntityInfo struct {
	// MBID contains the entity's UUID.
	MBID string
	// Name contains the entity's name as it appears in the database.
	Name string
}

EntityInfo contains high-level information about an entity (e.g. artist or label). It sadly doesn't seem possible to request aliases here; /ws/2/url is documented as only supporting relationship includes.

func MakeEntityInfosForTest

func MakeEntityInfosForTest(mbidNamePairs ...string) []EntityInfo

MakeEntityInfosForTest is a helper function for tests that creates EntityInfo objects given a sequence of MBID and name pairs.

type EntityInfoMap added in v0.1.13

type EntityInfoMap map[EntityType][]EntityInfo

EntityInfoMap maps from entity type to info about entities of that type.

func (*EntityInfoMap) Size added in v0.1.13

func (m *EntityInfoMap) Size() int

Size returns the total number of EntityInfo objects in the map.

type EntityType added in v0.1.13

type EntityType string

EntityType is an entity type sent to the MusicBrainz API.

const (
	ArtistType EntityType = "artist"
	LabelType  EntityType = "label"
)

type Medium added in v0.1.13

type Medium struct {
	Tracks []Track `json:"tracks"`
}

Medium describes a medium within a release (e.g. a single compact disc).

type Option

type Option func(db *DB)

Option can be passed to NewDB to configure the database.

func MaxQPS

func MaxQPS(qps int) Option

MaxQPS overrides the default QPS limit for testing.

func NowFunc

func NowFunc(fn func() time.Time) Option

NowFunc injects a function that is called instead of time.Now to get the current time.

func ServerURL

func ServerURL(u string) Option

ServerURL returns an Option that configure DB to make calls to the specified base server URL, e.g. "https://musicbrains.org" or "https://test.musicbrainz.org".

func Version

func Version(v string) Option

Version returns an Option that sets the application version for the User-Agent header.

type Recording added in v0.1.13

type Recording struct {
	Title string `json:"title"`
	ID    string `json:"id"`
}

Recording describes the underlying recording appearing on one or more tracks.

type Release added in v0.1.13

type Release struct {
	Media []Medium `json:"media"`
}

Release describes an individual release.

type Track added in v0.1.13

type Track struct {
	Title     string    `json:"title"`
	Recording Recording `json:"recording"`
}

Track describes a track (i.e. song) within a medium.

Jump to

Keyboard shortcuts

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