a Go (Golang) MusicBrainz WS2 client library - work in progress

gomusicbrainz License MIT GoDoc GoWalker Build Status

a Go (Golang) MusicBrainz WS2 client library - a work in progress.

gopherbrainz Oo

Current state

Currently GoMusicBrainz provides methods to perform search and lookup requests. Browse requests are not supported yet.

Installation

$ go get github.com/michiwend/gomusicbrainz

Search Requests

GoMusicBrainz provides a search method for every WS2 search request in the form:

func (*WS2Client) Search<ENTITY>(searchTerm, limit, offset) (<ENTITY>SearchResponse, error)

searchTerm follows the Apache Lucene syntax and can either contain multiple fields with logical operators or just a simple search string. Please refer to lucene.apache.org for more details on the lucene syntax. In addition the [MusicBrainz website] (https://musicbrainz.org/doc/Development/XML_Web_Service/Version_2/Search) provides information about all possible query-fields.

Example

This example demonstrates a simple search requests to find the artist Parov Stelar. You can find it as a runnable go program in the samples folder.

// create a new WS2Client.
client := gomusicbrainz.NewWS2Client(
    "https://musicbrainz.org/ws/2",
    "A GoMusicBrainz example",
    "0.0.1-beta",
    "http://github.com/michiwend/gomusicbrainz")

// Search for some artist(s)
resp, _ := client.SearchArtist(`artist:"Parov Stelar"`, -1, -1)

// Pretty print Name and score of each returned artist.
for _, artist := range resp.Artists {
    fmt.Printf("Name: %-25sScore: %d\n", artist.Name, resp.Scores[artist])
}

the above code will produce the following output:

Name: Parov Stelar             Score: 100
Name: Parov Stelar Trio        Score: 80
Name: Parov Stelar & the Band  Score: 70

Lookup Requests

GoMusicBrainz provides two ways to perform lookup requests: Either the specific lookup method that is implemented for each entity that has a lookup endpoint in the form

func(*WS2Client) Lookup<ETITY>(id MBID, inc ...string) (*<ENTITY>, error)

or the common lookup method if you already have an entity (with MBID) that implements the MBLookupEntity interface:

func(*WS2Client) Lookup(entity MBLookupEntity, inc ...string) error

Example

The following example demonstrates the (specific) LookupArtist method. You can find it as a runnable go program in the samples folder.

// create a new WS2Client.
client, _ := gomusicbrainz.NewWS2Client(
    "https://musicbrainz.org/ws/2",
    "A GoMusicBrainz example",
    "0.0.1-beta",
    "http://github.com/michiwend/gomusicbrainz")

// Lookup artist by id.
artist, err := client.LookupArtist("9a709693-b4f8-4da9-8cc1-038c911a61be")

if err != nil {
    fmt.Println(err)
    return
}

fmt.Printf("%+v", artist)

Package Documentation

Full documentation for this package can be found at GoDoc and GoWalker

Owner
Michael Wendland
Consultant at ThoughtWorks
Michael Wendland
Comments
  • Can't figure out how to use Relationships

    Can't figure out how to use Relationships

    Hey!

    I've been working on this for a few days and can't really figure it out.

    In general, my goal is to give gomusicbrainz a MBID and get returned the URL relationships (Wikipedia, official website, Spotify, etc..).

    For instance, this is my best try:

        // Grab Musicbrainz artist
        musicbrainzArtist, err := musicbrainzClient.LookupArtist(
            gomusicbrainz.MBID(artist.MusicbrainzID), "url-rels",
        )
        if err != nil {
            log.Warn(err)
            continue
        }
        // List all url 
        for _, url := range musicbrainzArtist.Relations["url"] {
            fmt.Println(gomusicbrainz.URLRelation(url).Target) // error, don't know what to do here
        }
    

    My question is: How do I convert a gomusicbrainz.Relation to gomusicbrainz.URLRelation?

  • How do I get artist ID?

    How do I get artist ID?

    On the musicbrainz web site, searching for the artist Slave Raider ( https://musicbrainz.org/search?query=slave+raider&type=artist&method=indexed ), I see the Artist ID is 49950dec-e4c4-4177-808d-bab8ab028665.

    In search_artist.go, I changed the artist.

    Name: Slave Raider Score: 100

    All the 100 does is tell me how good of a match 49950dec-e4c4-4177-808d-bab8ab028665 ID is, but it doesn't provide the ID! I fail to even grasp what this purpose of this example is. How do I get the artistID?

  • Check for empty date

    Check for empty date

    Some recordings don't have a date, so Go crashes when comparing "" to "2006". This is a small workaround to prevent that and allow the program to fallback to Go's default value.

  • Library doesn't allow for handling connection errors

    Library doesn't allow for handling connection errors

    Hi! I'm starting to use gomusicbrainz in my project and encountered a quite simple but annoying issue - there are 2 cases that call log.Fatalln(err) (namely https://github.com/michiwend/gomusicbrainz/blob/master/gomusicbrainz.go#L140 and https://github.com/michiwend/gomusicbrainz/blob/master/gomusicbrainz.go#L147), and thus don't give any chance to handle these errors.

    Is there any reason to consider these errors really fatal? Looks like simple return err should be enough here.

  • Preserve HTTP headers on redirect

    Preserve HTTP headers on redirect

    This ensures things like our custom UserAgent get preserved if the server does a redirect (my mirror enforces SSL, for example).

    See golang/go#4800

    Code cribbed from gyuho/gon

  • LookupArtist request broken when given inc parameters

    LookupArtist request broken when given inc parameters

    It returns

    expected element type <metadata> but have <error>
    

    when performing a lookup like this

    artist, err := client.LookupArtist("9a709693-b4f8-4da9-8cc1-038c911a61be", "discids")
    
  • Add simple DoRequest so clients can implement auth

    Add simple DoRequest so clients can implement auth

    This is so clients can implement Basic or Digest auth. The spec mentions digest auth, but the server I'm using also supports basic auth.

    So, you can do something like this:

    client.RequestFilter = func(req *http.Request) {
        req.SetBasicAuth("username", "password")
    }
    

    However, I'm aware this is a hack... and I'm not even sure if it can be used for Digest auth... if you have any suggestions as to a better way to do this, I'd be happy to do that instead.

  • Browse requests support?

    Browse requests support?

    Hi there,

    I see there's no much activity since 2015, but I'm curious if the project is still alive. If yes, then are you planning to add support for browse requests?

    Or would you accept a PR? Thanks!

A work-in-progress implementation of MobileMe.

mobileme A work-in-progress implementation of MobileMe. At the moment, authentication is assumed to be with the username someuser and password testing

May 28, 2022
A Go client implementing a client-side distributed consumer group client for Amazon Kinesis.
A Go client implementing a client-side distributed consumer group client for Amazon Kinesis.

Kinesumer is a Go client implementing a client-side distributed consumer group client for Amazon Kinesis.

Jan 5, 2023
Clusterpedia-client - clusterpedia-client supports the use of native client-go mode to call the clusterpedia API

clusterpedia-client supports the use of native client-go mode to call the cluste

Jan 7, 2022
Client-go - Clusterpedia-client supports the use of native client-go mode to call the clusterpedia API

clusterpedia-client supports the use of native client-go mode to call the cluste

Dec 5, 2022
Go module to work with Postman Collections

go-postman-collection Go module to work with Postman Collections. This module aims to provide a simple way to work with Postman collections. Using thi

Dec 29, 2022
Go package to work with temperatures

tempconv This is an exercise of the book The Go Programming Language, by Alan A.

Dec 18, 2021
MovieWorkNow - a social network for film work made in go

Movie Work Now Movie Work Now é uma rede social para trabalho relativo a área de

Jan 11, 2022
Client-server-golang-sqs - Client Server with SQS and golang

Client Server with SQS and golang Multi-threaded client-server demo with Go What

Feb 14, 2022
Aoe4-client - Client library for aoe4 leaderboards etc

AOE4 Client Overview This is a go client used to query AOE4 data from either the

Jan 18, 2022
Go-http-client: An enhanced http client for Golang
Go-http-client: An enhanced http client for Golang

go-http-client An enhanced http client for Golang Documentation on go.dev ?? This package provides you a http client package for your http requests. Y

Jan 7, 2023
Client for the cloud-iso-client

cloud-iso-client Client for the cloud-iso-client. Register an API token Before using this client library, you need to register an API token under your

Dec 6, 2021
Nutanix-client-go - Go client for the Nutanix Prism V3 API

nutanix-client-go This repository contains portions of the Nutanix API client code in nutanix/terraform-provider-nutanix. It has been extracted to red

Jan 6, 2022
Balabola-go-client - GO client for Yandex balabola service

Balabola GO Client GO client for Yandex balabola service Yandex warning The neur

Jan 29, 2022
A Golang Client Library for building Cosmos SDK chain clients

Cosmos Client Lib in Go This is the start of ideas around how to implement the cosmos client libraries in a seperate repo How to instantiate and use t

Jan 6, 2023
Go Client Library for Amazon Product Advertising API

go-amazon-product-advertising-api Go Client Library for Amazon Product Advertising API How to Use go get -u github.com/ngs/go-amazon-product-advertisi

Sep 27, 2022
A Go client library for the Twitter 1.1 API

Anaconda Anaconda is a simple, transparent Go package for accessing version 1.1 of the Twitter API. Successful API queries return native Go structs th

Jan 1, 2023
Go(lang) client library for Cachet (open source status page system).

cachet Go(lang) client library for Cachet (open source status page system). Features Full API support Components Incidents Metrics Subscribers Various

Sep 27, 2022
Go client library for interacting with Coinpaprika's API

Coinpaprika API Go Client Usage This library provides convenient way to use coinpaprika.com API in Go. Coinpaprika delivers full market data to the wo

Dec 8, 2022
Package githubv4 is a client library for accessing GitHub GraphQL API v4 (https://developer.github.com/v4/).

githubv4 Package githubv4 is a client library for accessing GitHub GraphQL API v4 (https://docs.github.com/en/graphql). If you're looking for a client

Dec 26, 2022