Skip to content

Instantly share code, notes, and snippets.

@bwll
Created September 9, 2016 04:48
Show Gist options
  • Save bwll/3edf0371ca7f517d0601659971afc376 to your computer and use it in GitHub Desktop.
Save bwll/3edf0371ca7f517d0601659971afc376 to your computer and use it in GitHub Desktop.
// 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