Reputation: 1
I miss an overview of Artits in Spotify, something that iTunes for example provides. Now I wonder how would a script look like to retrieve all artists in a user library?
The code below does not do it. Suggestions very much appreciated!
function getAllAlbums() {
var albums = models.Library.albums;
var imageHTML = document.getElementById('albumsList');
for(i=0;i<albums.length;i++){
var link = document.createElement('li');
var a = document.createElement('a');
a.href = albums[i].uri;
link.appendChild(a);
a.innerHTML = albums[i].name;
imageHTML.appendChild(link);
}
}
Upvotes: 0
Views: 137
Reputation: 9293
I'm not quite sure what iTunes functionality you're looking to replicate or what you're trying to do with the HTML, but if you're just looking for a list of artists, the api provides an easy way of accessing them.
Creating a list of all the artists in the users library is straight forward:
artistArray = models.library.artists
artistNameArray = [];
for(var i=0; i<artistArray.length; i++){
artistNameArray[i] = artistArray[i].data.name;
}
Upvotes: 2