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!

golang script for bypass AV and work only in windows platform
golang script for bypass AV and work only in windows platform

antivirus bypass protection requirements golang installed usage 1 - create your payload go run create.go <ip> <port> <secret> <any url>

Nov 9, 2022
Work with remote images registries - retrieving information, images, signing content

skopeo skopeo is a command line utility that performs various operations on container images and image repositories. skopeo does not require the user

Jan 5, 2023
A simple package for executing work in parallel up to a limit.

concurrencylimiter A simple package for executing work concurrently - up to a limit. The intended usecase looks something like: func concurrentlyDo(ta

Dec 19, 2021
Vocabular checker JetBrains Academy home work Read file with bad words

Vocabulary Checker JetBrains Academy home work Read file with bad words and replace them on * in the next entered text until exitVocabulary Checker JetBrains Academy home work Read file with bad words and replace them on * in the next entered text until exit

Jan 14, 2022
Chief Client Go is a cross platform Krunker client written in Go Lang

Chief Client Go Chief Client Go is a client for Mac and Linux written in GoLang Features Ad Blocker Option to use proxy Installation To install this c

Nov 6, 2021
Yubigo is a Yubikey client API library that provides an easy way to integrate the Yubico Yubikey into your existing Go-based user authentication infrastructure.

yubigo Yubigo is a Yubikey client API library that provides an easy way to integrate the Yubikey into any Go application. Installation Installation is

Oct 27, 2022
CircleCI API (V2) Client Library in Go

go-circleci This client supports the CircleCI V2 API. Installation Installation can be done with a normal go get: go get -u github.com/grezar/go-circl

Dec 12, 2022
Go client library for Geonames Web Services (geonames.org)

geonames Go client library for Geonames Web Services (geonames.org) Usage Register your username at geonames.org Export ENV Var or read the username f

Nov 23, 2022
Golang exaroton API client

Golang exaroton API client This is the unofficial Go implementation of this I'm still learning so expect badly design code PR are appreciated. Code In

Dec 14, 2021
Arduino Firmata client for golang

go-firmata A Golang wrapper for Firmata on Arduino Installation go get github.com/kraman/go-firmata Usage package main import ( "github.com/kraman/

Aug 11, 2022
Selenium WebDriver client for Go

============================================== go-selenium - Selenium WebDriver client for Go go-selenium is a Selenium WebDriver client for Go. Note:

Dec 10, 2022
Simple Client Implementation of WebFinger

Go-Webfinger Go client for the Webfinger protocol Go-Webfinger is a Go client for the Webfinger protocol. *It is a work in progress, the API is not fr

Nov 18, 2022
An example client implementation written in GO to access the CyberVox platform API

About This is an example client implementation written in GO to access the CyberVox platform API.

Nov 7, 2022
TUI Client for Docker
TUI Client for Docker

docui - TUI Client for Docker Written in Go About docui docui is a TUI Client for Docker. It can do the following: image search/pull/remove save/impor

Dec 28, 2022
Elastic is an Elasticsearch client for the Go programming language.

Elastic is an Elasticsearch client for the Go programming language.

Jan 9, 2023
Geth client which picks the most profitable blocks to mine using a greedy algorithm

Greeden-Geth Greeden-Geth is a protocol-agnostic client which uses a greedy algorithm to pick the most profitable blocks to submit to the network out

Nov 16, 2022
A comparison of client tracing APIs

A comparison of client tracing APIs Client Usage Trace Dump go-ethereum View Nethermind View View Erigon View View Besu View Getting Started git clone

Feb 4, 2022
HackerNews client made with Kyoto
HackerNews client made with Kyoto

HackerNews demo HackerNews demo client, made with kyoto Install Clone repo: git clone https://github.com/yuriizinets/kyoto-hn Go to the cloned directo

Jul 2, 2022
Graphical small-internet client for windows, linux, MacOS X and BSDs. Supports gemini, http, https, gopher, finger.
Graphical small-internet client for windows, linux, MacOS X and BSDs. Supports gemini, http, https, gopher, finger.

Graphical small-internet client for windows, linux, MacOS X and BSDs. Supports gemini, http, https, gopher, finger.

Jan 1, 2023