Created
September 9, 2016 04:48
-
-
Save bwll/3edf0371ca7f517d0601659971afc376 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jshint esversion: 6 | |
'use strict'; | |
const _ = require('lodash'); | |
const request = require('request-promise'); | |
const artist = process.argv[2]; | |
let options = { | |
url: "https://api.spotify.com/v1/search?q=" + encodeURIComponent(artist) + "&type=album", | |
json: false | |
}; | |
request(options).then((response) => { | |
let data; | |
try { | |
data = JSON.parse(response); | |
} catch(err) { | |
console.log(err.message); | |
} | |
let albums = _.map(data.albums.items); | |
_.forEach(albums, (index) => { | |
request({ | |
url: "https://api.spotify.com/v1/albums/" + index.id, | |
json: true | |
}).then((response) => { | |
console.log(response.name); | |
}).catch(function(err) { | |
console.log(err.message); | |
}); | |
}); | |
}).catch((err) => { | |
console.log(err.message); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment