3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-26 04:32:37 +01:00

fix spotify search crash

This commit is contained in:
Thomas Menari 2013-02-12 19:31:34 +00:00
parent 9f007c906f
commit a00a5dafed
2 changed files with 13 additions and 8 deletions

View File

@ -21,15 +21,15 @@ var spotify = function(dbot) {
json: true json: true
}, function(error, response, body) { }, function(error, response, body) {
if (!error && response.statusCode == 200) { if (!error && response.statusCode == 200) {
var s = "\u00039spotify\u000f"; var spotify = "\u00039spotify\u000f";
if (body.hasOwnProperty('track')) { if (_.has(body, 'track')) {
event.reply(dbot.t("track", {s: s, artist: _.map(body.track.artists, function(a) { return a.name }).join(', '), album: body.track.album.name, track: body.track.name})); event.reply(dbot.t("track", {s: spotify, artist: _.map(body.track.artists, function(a) { return a.name }).join(', '), album: body.track.album.name, track: body.track.name}));
} }
else if (body.hasOwnProperty('album')) { else if (_.has(body, 'album')) {
event.reply(dbot.t("album", {s: s, artist: body.album.artist, album: body.album.name})); event.reply(dbot.t("album", {s: spotify, artist: body.album.artist, album: body.album.name}));
} }
else if (body.hasOwnProperty('artist')) { else if (_.has(body, 'artist')) {
event.reply(dbot.t("artist", {s: s, artist: body.artist.name})); event.reply(dbot.t("artist", {s: spotify, artist: body.artist.name}));
} }
} }
}); });
@ -44,11 +44,13 @@ var spotify = function(dbot) {
json: true json: true
}, function(error, response, body) { }, function(error, response, body) {
if (!error && response.statusCode == 200) { if (!error && response.statusCode == 200) {
if (body.hasOwnProperty('tracks')) { if (_.has(body, 'tracks') && body.tracks[0] && _.has(body.tracks[0], 'href')) {
var t = body.tracks[0].href; var t = body.tracks[0].href;
t = t.replace(/:/g, '/'); t = t.replace(/:/g, '/');
t = t.replace(/spotify/, 'http://open.spotify.com'); t = t.replace(/spotify/, 'http://open.spotify.com');
event.reply(t); event.reply(t);
} else {
event.reply(dbot.t("not-found", {s: "\u00039spotify\u000f"}));
} }
} }
}); });

View File

@ -7,5 +7,8 @@
}, },
"track": { "track": {
"english": "{s} [track] {artist} - {track} (from {album})" "english": "{s} [track] {artist} - {track} (from {album})"
},
"not-found": {
"english": "{s} No results."
} }
} }