mbdb

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: BSD-3-Clause Imports: 13 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 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) GetArtistsFromURL

func (db *DB) GetArtistsFromURL(ctx context.Context, linkURL string) ([]EntityInfo, error)

GetArtistsFromURL returns artists related to linkURL. If no artist is related to the URL, an empty slice is returned.

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) GetLabelsFromURL

func (db *DB) GetLabelsFromURL(ctx context.Context, linkURL string) ([]EntityInfo, error)

GetLabelsFromURL returns labels related to linkURL. If no label is related to the URL, an empty slice is returned.

func (*DB) SetArtistsFromURLForTest

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

SetArtistsFromURLForTest hardcodes artists for GetArtistsFromURL to return.

func (*DB) SetDatabaseIDForTest

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

SetDatabaseIDForTest hardcodes an ID for GetDatabaseID to return.

func (*DB) SetLabelsFromURLForTest

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

SetLabelsFromURLForTest hardcodes labels for GetLabelsFromURL to return.

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). TODO: Figure out if there's some way to also get artist aliases from /ws/2/url queries.

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

Jump to

Keyboard shortcuts

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