simple-lastfm
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -359,2 +359,53 @@ var http = require('http'); | ||
Lastfm.prototype.getTracks = function(opt) { | ||
// var the_callback = opt.callback; | ||
var page = opt.page ? opt.page : 1; | ||
http.get({ | ||
host: 'ws.audioscrobbler.com', | ||
port: 80, | ||
path: '/2.0/?method=user.getartisttracks&page=' + page + '&api_key=' + this.api_key + '&autocorrect=1&user=' + this.username + '&artist=' + encodeURIComponent(opt.artist) | ||
}, function(res) { | ||
var body = ''; | ||
res.on('data', function(chunk) { | ||
body += chunk; | ||
}); | ||
res.on('end', function() { | ||
var parser = new xml2js.Parser(); | ||
parser.parseString(body, function(err, result) { | ||
if (typeof opt.callback == 'function') { | ||
opt.callback(result); | ||
} | ||
}); | ||
}); | ||
}); | ||
}; | ||
Lastfm.prototype.getAllTracks = function(opt) { | ||
var lastfm = this; | ||
var the_callback = opt.callback; | ||
var tracks = []; | ||
opt.callback = function(result) { | ||
if(result['@'].status == 'failed') { | ||
the_callback({ | ||
success: false, | ||
reason: result.error['#'] | ||
}); | ||
} else { | ||
var numPages = result.artisttracks['@'].totalPages; | ||
for(var i=0;i<result.artisttracks.track.length;i++) { | ||
if(tracks.indexOf(result.artisttracks.track[i].name) < 0) | ||
tracks.push(result.artisttracks.track[i].name); | ||
} | ||
if(result.artisttracks['@'].page < numPages) { | ||
opt.page++; | ||
lastfm.getTracks(opt); | ||
} else { | ||
the_callback({success: true, artist: result.artisttracks['@'].artist, tracks: tracks}); | ||
} | ||
} | ||
}; | ||
opt.page = 1; | ||
this.getTracks(opt); | ||
}; | ||
function now() { | ||
@@ -361,0 +412,0 @@ return new Date().getTime(); |
{ | ||
"name": "simple-lastfm", | ||
"description": "simple last.fm api for node.js", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "type": "git", |
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
16661
391
1