Skip to content

Instantly share code, notes, and snippets.

@djromero
Created March 12, 2014 17:44
Show Gist options
  • Save djromero/9512193 to your computer and use it in GitHub Desktop.
Save djromero/9512193 to your computer and use it in GitHub Desktop.
Search an artist name in Music Brainz database.
var http = require("http")
var query = require('querystring');
var term = process.argv[2];
var DEBUG = false;
var options = {
host: 'search.musicbrainz.org',
path: '/ws/2/artist/?fmt=json&query=' + query.escape(term)
};
callback = function(response) {
var data = '';
response.on('data', function (chunk) {
data += chunk;
});
response.on('end', function() {
if (DEBUG) {
console.log(data);
console.log("\n\n\n");
}
var o = JSON.parse(data);
o["artist-list"]["artist"].forEach(function(artist) {
if (parseInt(artist.score) > 80) {
console.log("Artist: " + artist.name);
console.log(" MBID: " + artist.id);
console.log(" Score: " + artist.score);
console.log("\n");
}
});
});
response.on('error', function(e) {
console.log('*** Error: ' + e.message);
});
}
http.request(options, callback).end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment