Version 1 of MusicBrainz

Updated 2018-11-08 20:13:42 by bll

Instruction how to get information from MusicBrainz database.

Script above shows how to get basic information about entered artist. Script returns list of albums with release date, title, and url to front and back cover (if exits)

Tutorial for MusicBrain is here

First of all we need to check artist id

http://www.musicbrainz.org/ws/2/artist/?query=<artist>

Next we can get xml contains release-list using following link:

http://www.musicbrainz.org/ws/2/release?artist=<artistID>

According to the wiki.musicbrainz.org : cover arts are available via coverartarchive.org

http://coverartarchive.org

 Discussion

bll 2018-11-8: To get information on a known recording, I am using:

http://musicbrainz.org/ws/2/recording/2409871f-6cde-42a1-a017-722b86f87e68?inc=artists%20releases%20media%20artist-credits

Let's try to get some basic info:

package require http
package require tdom

proc ___returnArtistID {artist} {
        set r [::http::geturl http://www.musicbrainz.org/ws/2/artist/?query=$artist]
        set data [::http::data $r]
        ::http::cleanup $r
        set doc [dom parse $data]
        set root [$doc documentElement]
        set ns {xmlns http://musicbrainz.org/ns/mmd-2.0#}
        set nodesList [$root selectNodes -namespaces $ns //xmlns:artist-list//xmlns:artist]
        return [[lindex $nodesList 0] getAttribute id]
}

proc ___coverURL {type id} {
        return "http://coverartarchive.org/release/$id/$type"
}

proc ___returnReleases {artistID} {
        set r [::http::geturl http://www.musicbrainz.org/ws/2/release?artist=$artistID]
        set data [::http::data $r]
        ::http::cleanup $r
        set doc [dom parse $data]
        set root [$doc documentElement]
        set ns {xmlns http://musicbrainz.org/ns/mmd-2.0#}
        set nodesList [$root selectNodes -namespaces $ns //xmlns:release-list//xmlns:release]
        #id used in the second query
        foreach node $nodesList {
                set date ""
                set id [$node getAttribute id]
                lappend ids $id
                set titleNode [$node selectNodes -namespaces $ns //xmlns:release-list//xmlns:release\[@id='$id'\]//xmlns:title]
                set dateNodes [$node selectNodes -namespaces $ns //xmlns:release-list//xmlns:release\[@id='$id'\]//xmlns:date]
                set coverFrontNode [$node selectNodes -namespaces $ns //xmlns:release-list//xmlns:release\[@id='$id'\]//xmlns:cover-art-archive//xmlns:front]
                set coverBackNode [$node selectNodes -namespaces $ns //xmlns:release-list//xmlns:release\[@id='$id'\]//xmlns:cover-art-archive//xmlns:back]
                set frontC [expr {[$coverFrontNode text] eq "true" ? [___coverURL "front" $id] : "false" }]
                set backC [expr {[$coverFrontNode text] eq "true" ? [___coverURL "back" $id] : "false" }]
                puts "##### Title: [$titleNode text] #####"
                puts "date: [[lindex $dateNodes 0] text]"
                puts "cover front: $frontC"
                puts "cover back: $backC"
                puts "##### #####"
        }
        return $ids
}


set artistID [___returnArtistID "portishead"]
set releaseIDs [___returnReleases $artistID]

puts [___returnArtistID "portishead"]