Documentation
¶
Overview ¶
Package mbdb contains functionality related to the MusicBrainz database.
Index ¶
- Variables
- func ExtractMBID(url string) string
- func IsMBID(mbid string) bool
- func ShortenContext(ctx context.Context, t time.Duration) (context.Context, context.CancelFunc)
- type DB
- func (db *DB) GetDBRelease(ctx context.Context, mbid string) (DBRelease, error)
- func (db *DB) GetDatabaseID(ctx context.Context, mbid string) (int32, error)
- func (db *DB) GetRelease(ctx context.Context, mbid string) (Release, error)
- func (db *DB) GetURLRels(ctx context.Context, urls ...string) (map[string]EntityInfoMap, error)
- func (db *DB) SetDBReleaseForTest(mbid string, rel DBRelease)
- func (db *DB) SetDatabaseIDForTest(mbid string, id int32)
- func (db *DB) SetURLEntityInfosForTest(url string, artists, labels []EntityInfo)
- type DBMedium
- type DBRecording
- type DBRelease
- type DBTrack
- type EntityInfo
- type EntityInfoMap
- type EntityType
- type Medium
- type Option
- type Recording
- type Release
- type Track
Constants ¶
This section is empty.
Variables ¶
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
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 ¶
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 ¶
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 (*DB) GetDBRelease ¶ added in v0.1.13
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 ¶
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
GetRelease returns information about the release with the supplied MBID.
func (*DB) GetURLRels ¶ added in v0.1.13
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) SetDatabaseIDForTest ¶
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
GetTrackAtIndex returns the 0-based i-th track from rel.
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 NowFunc ¶
NowFunc injects a function that is called instead of time.Now to get the current time.
func ServerURL ¶
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".
type Recording ¶ added in v0.1.13
Recording describes the underlying recording appearing on one or more tracks.