3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-27 14:29:29 +01:00

lastfm ~listening: make youtube and spotify api calls in parallel

This commit is contained in:
Scritches 2018-03-24 19:24:57 -04:00
parent 72a4552742
commit 25d572e8cb

View File

@ -280,22 +280,41 @@ var lastfm = function(dbot) {
'artist': track.artist['#text'] 'artist': track.artist['#text']
}); });
} }
dbot.api.youtube.search(term, function(body) {
if(_.isObject(body) && _.has(body, 'items') && body.items.length > 0) { async.parallel({
var link = body.items[0].id.videoId youtube: function(cb) {
if(link) { dbot.api.youtube.search(term, function(body) {
output += ' - http://youtu.be/' + link; if(_.isObject(body) && _.has(body, 'items') && body.items.length > 0) {
} var link = body.items[0].id.videoId
if(link) {
cb(null,"http://youtu.be/" + link);
} else {
cb(null, undefined);
}
}
});
},
spotify: function(cb) {
dbot.api.spotify.spotifySearch(term, function(body, url, uri) {
if(body) {
cb(null, { url:url, uri:uri });
} else {
cb(null, undefined);
}
});
} }
}, function(err, results) {
dbot.api.spotify.spotifySearch(term, function(body, url, uri) { if (results.youtube || results.spotify) output += " - "
if(body) {
output += ' - ' + url + ' - ' + uri; if (results.youtube) output += results.youtube;
} if (results.spotify) {
if (results.youtube) output += " | ";
event.reply(output); output += results.spotify.url + " - " + results.spotify.uri;
}); }
event.reply(output);
}); });
} else { } else {
if(err == 'no_user') { if(err == 'no_user') {
event.reply('Unknown LastFM user.'); event.reply('Unknown LastFM user.');