Created
March 21, 2017 05:17
-
-
Save una-ada/f083c7f30ce1aca91f3bea8507b8d408 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
var http = require('https'), | |
args = process.argv.splice(process.execArgv.length + 2), | |
artists = {}; | |
function search(query){ | |
http.get( | |
'https://api.spotify.com/v1/search?q=' | |
+ encodeURIComponent(query) | |
+ '&type=artist' | |
,(r0)=>{//request(0) | |
var r1 = '';//response(1) | |
r0.on('data',(d)=>{r1+=d;}); | |
r0.on('end',()=>{ | |
var s = JSON.parse(r1).artists.items; | |
for(var i of s) | |
((a)=>{ | |
if(!artists[a.id]){ | |
artists[a.id] = a; | |
http.get( | |
`https://api.spotify.com/v1/artists/${a.id}/albums` | |
,(r2)=>{//request(2) | |
var r3 = '';//response(3) | |
r2.on('data',(d)=>{r3+=d;}); | |
r2.on('end',()=>{ | |
artists[a.id].albums = JSON.parse(r3).items; | |
var as = []; | |
for(var a1 of artists[a.id].albums) | |
as.push(a1.id); | |
http.get( | |
'https://api.spotify.com/v1/albums?ids=' | |
+as.join() | |
,(r4)=>{//request(4) | |
var r5 = '';//response(5) | |
r4.on('data',(d)=>{r5+=d;}); | |
r4.on('end',()=>{ | |
var as1 = JSON.parse(r5).albums; | |
delete artists[a.id].albums; | |
artists[a.id].albums = as1; | |
printArtist(artists[a.id]); | |
}); | |
}); | |
}); | |
}); | |
} | |
})(i); | |
}) | |
}).end(); | |
} | |
function printArtist(o){ | |
console.log(o.name); | |
for(var i of o.albums){ | |
console.log('\t'+i.name); | |
for(var j of i.tracks.items) | |
console.log('\t\t'+j.name); | |
} | |
} | |
search(args.length>0?args.join(" "):"Kero Kero Bonito"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment