forked from GitHub/dbot
Merge pull request #672 from Scritches/master
Some more music module fixes
This commit is contained in:
commit
fbc4ac5afe
@ -92,6 +92,7 @@ var lastfm = function(dbot) {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/*
|
||||||
'tasteCompare': function(user, oUser, callback) {
|
'tasteCompare': function(user, oUser, callback) {
|
||||||
request.get(this.ApiRoot, {
|
request.get(this.ApiRoot, {
|
||||||
'qs': {
|
'qs': {
|
||||||
@ -105,6 +106,7 @@ var lastfm = function(dbot) {
|
|||||||
},
|
},
|
||||||
'json': true
|
'json': true
|
||||||
}, function(err, res, body) {
|
}, function(err, res, body) {
|
||||||
|
console.log(body);
|
||||||
if(_.has(body, 'error') && body.error == 6 || body.error == 7) {
|
if(_.has(body, 'error') && body.error == 6 || body.error == 7) {
|
||||||
callback('no_user', user, null);
|
callback('no_user', user, null);
|
||||||
} else if(_.has(body, 'comparison') && _.has(body.comparison, 'result')) {
|
} else if(_.has(body, 'comparison') && _.has(body.comparison, 'result')) {
|
||||||
@ -114,6 +116,7 @@ var lastfm = function(dbot) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
*/
|
||||||
|
|
||||||
'getInfo': function(lfm, callback) {
|
'getInfo': function(lfm, callback) {
|
||||||
request.get(this.ApiRoot, {
|
request.get(this.ApiRoot, {
|
||||||
@ -220,29 +223,54 @@ var lastfm = function(dbot) {
|
|||||||
'artist': track.artist.name
|
'artist': track.artist.name
|
||||||
});
|
});
|
||||||
var term = track.name + ' ' + track.artist.name;
|
var term = track.name + ' ' + track.artist.name;
|
||||||
|
|
||||||
dbot.api.youtube.search(term, function(body) {
|
async.parallel({
|
||||||
if(_.isObject(body) && _.has(body, 'items') && body.items.length > 0) {
|
youtube: function(cb) {
|
||||||
var link = body.items[0].id.videoId
|
dbot.api.youtube.search(term, function(body) {
|
||||||
if(link) {
|
if(_.isObject(body) && _.has(body, 'items') && body.items.length > 0) {
|
||||||
output += ' - http://youtu.be/' + link;
|
var link = body.items[0].id.videoId
|
||||||
}
|
if(link) {
|
||||||
|
cb(null,"https://youtu.be/" + link);
|
||||||
|
} else {
|
||||||
|
cb(null, undefined);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
spotify: function(cb) {
|
||||||
|
dbot.api.spotify.spotifySearch(term, function(body, url, uri) {
|
||||||
|
if(body) {
|
||||||
|
if (!dbot.modules.minify) {
|
||||||
|
cb(null, { url: url, uri:uri });
|
||||||
|
} else {
|
||||||
|
dbot.modules.minify.api.minify(url, "bitly", function(mini) {
|
||||||
|
cb(null, { url:mini || url, uri:uri });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cb(null, undefined);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
}, function(err, results) {
|
||||||
dbot.api.spotify.spotifySearch(term, function(body, t) {
|
if (results.youtube || results.spotify) output += " - "
|
||||||
if(body) {
|
|
||||||
output += ' - ' + t;
|
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 {
|
||||||
event.reply('something broke');
|
event.reply('Couldn\'t get any suggested tracks.');
|
||||||
|
console.log(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
event.reply('something broke');
|
event.reply('Couldn\'t find any similar artists to what you\'re listening to.');
|
||||||
|
console.log(err);
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
} else {
|
} else {
|
||||||
@ -262,7 +290,7 @@ var lastfm = function(dbot) {
|
|||||||
user = event.res[0].user;
|
user = event.res[0].user;
|
||||||
lfm = event.res[0].lfm;
|
lfm = event.res[0].lfm;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.api.getListening(lfm, function(err, track) {
|
this.api.getListening(lfm, function(err, track) {
|
||||||
if(!err) {
|
if(!err) {
|
||||||
var term = track.name + ' ' + track.artist['#text'],
|
var term = track.name + ' ' + track.artist['#text'],
|
||||||
@ -327,10 +355,12 @@ var lastfm = function(dbot) {
|
|||||||
} else if(err == 'no_listen') {
|
} else if(err == 'no_listen') {
|
||||||
event.reply(dbot.t('no_listen', { 'user': user.currentNick }));
|
event.reply(dbot.t('no_listen', { 'user': user.currentNick }));
|
||||||
}
|
}
|
||||||
|
console.log(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/*
|
||||||
'~taste': function(event) {
|
'~taste': function(event) {
|
||||||
var u1 = event.rUser,
|
var u1 = event.rUser,
|
||||||
lfm1 = event.rProfile.lastfm,
|
lfm1 = event.rProfile.lastfm,
|
||||||
@ -431,6 +461,7 @@ var lastfm = function(dbot) {
|
|||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
*/
|
||||||
|
|
||||||
'~artists': function(event) {
|
'~artists': function(event) {
|
||||||
var u1 = event.rUser,
|
var u1 = event.rUser,
|
||||||
@ -456,7 +487,7 @@ var lastfm = function(dbot) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.commands['~taste'].regex = [/^taste ([\d\w[\]{}^|\\`_-]+?)/, 2];
|
//this.commands['~taste'].regex = [/^taste ([\d\w[\]{}^|\\`_-]+?)/, 2];
|
||||||
this.commands['~artists'].regex = [/^artists ([\d\w[\]{}^|\\`_-]+?)/, 2];
|
this.commands['~artists'].regex = [/^artists ([\d\w[\]{}^|\\`_-]+?)/, 2];
|
||||||
|
|
||||||
_.each(this.commands, function(command) {
|
_.each(this.commands, function(command) {
|
||||||
|
@ -6,16 +6,6 @@ var request = require('request'),
|
|||||||
_ = require('underscore')._;
|
_ = require('underscore')._;
|
||||||
|
|
||||||
var spotify = function(dbot) {
|
var spotify = function(dbot) {
|
||||||
/* Examples:
|
|
||||||
* http://open.spotify.com/track/42SYMWISn7xUpTNPLw9V5E
|
|
||||||
* spotify:track:42SYMWISn7xUpTNPLw9V5E
|
|
||||||
* http://open.spotify.com/artist/3yY2gUcIsjMr8hjo51PoJ8
|
|
||||||
* spotify:artist:3yY2gUcIsjMr8hjo51PoJ8
|
|
||||||
* http://open.spotify.com/album/30g571JKoxs8AnsgAViV2J
|
|
||||||
* spotify:album:30g571JKoxs8AnsgAViV2J
|
|
||||||
*/
|
|
||||||
this.spotifyRegex = /(\b(https?:\/\/open.spotify.com\/(artist|track|album)\/\w*|spotify:(artist|track|album):\w*)\b)/ig;
|
|
||||||
this.spotifyLookup = 'http://ws.spotify.com/lookup/1/.json';
|
|
||||||
this.spotifySearch = 'https://api.spotify.com/v1/search';
|
this.spotifySearch = 'https://api.spotify.com/v1/search';
|
||||||
this.youtubeRegex = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
|
this.youtubeRegex = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
|
||||||
this.spotifyText = '\u00039spotify\u000f';
|
this.spotifyText = '\u00039spotify\u000f';
|
||||||
@ -40,37 +30,6 @@ var spotify = function(dbot) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.lookup = function(link, callback) {
|
|
||||||
this.authenticate(function(token) {
|
|
||||||
request({
|
|
||||||
'url': this.spotifyLookup,
|
|
||||||
'qs': { 'uri': link },
|
|
||||||
'json': true,
|
|
||||||
'headers': { 'Authorization': "Bearer " + token }
|
|
||||||
}, function(error, response, body) {
|
|
||||||
if(!error && response.statusCode == 200) {
|
|
||||||
if(_.has(body, 'track')) {
|
|
||||||
callback(dbot.t('track', {
|
|
||||||
'artist': _.map(body.track.artists,
|
|
||||||
function(a) { return a.name }).join(', '),
|
|
||||||
'album': body.track.album.name,
|
|
||||||
'track': body.track.name
|
|
||||||
}));
|
|
||||||
} else if(_.has(body, 'album')) {
|
|
||||||
callback(dbot.t('album', {
|
|
||||||
'artist': body.album.artist,
|
|
||||||
'album': body.album.name
|
|
||||||
}));
|
|
||||||
} else if(_.has(body, 'artist')) {
|
|
||||||
callback(dbot.t('artist', {
|
|
||||||
'artist': body.artist.name
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}.bind(this));
|
|
||||||
};
|
|
||||||
|
|
||||||
this.api = {
|
this.api = {
|
||||||
'spotifySearch': function(query, callback) {
|
'spotifySearch': function(query, callback) {
|
||||||
this.authenticate(function(token) {
|
this.authenticate(function(token) {
|
||||||
@ -157,11 +116,6 @@ var spotify = function(dbot) {
|
|||||||
commands['~spotify'].regex = [/^spotify (.*)/, 2];
|
commands['~spotify'].regex = [/^spotify (.*)/, 2];
|
||||||
this.commands = commands;
|
this.commands = commands;
|
||||||
|
|
||||||
this.onLoad = function() {
|
|
||||||
dbot.api.link.addHandler(this.name, this.spotifyRegex, function(matches, name, callback) {
|
|
||||||
this.lookup(matches[0], callback);
|
|
||||||
}.bind(this));
|
|
||||||
}.bind(this);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.fetch = function(dbot) {
|
exports.fetch = function(dbot) {
|
||||||
|
@ -5,7 +5,7 @@ var words = function(dbot) {
|
|||||||
this.commands = {
|
this.commands = {
|
||||||
'~define': function(event) {
|
'~define': function(event) {
|
||||||
var query = event.params.slice(1).join(" ");
|
var query = event.params.slice(1).join(" ");
|
||||||
this.wn.definitions(encodeURIComponent(query), function(err, defs) {
|
this.wn.definitions(encodeURIComponent(query), { useCanonical: true }, function(err, defs) {
|
||||||
if(!err && defs[0]) {
|
if(!err && defs[0]) {
|
||||||
event.reply(dbot.t('def', {
|
event.reply(dbot.t('def', {
|
||||||
'word': query,
|
'word': query,
|
||||||
|
@ -93,6 +93,7 @@ var youtube = function(dbot) {
|
|||||||
}, function(error, response, body) {
|
}, function(error, response, body) {
|
||||||
if(_.isObject(body) && _.has(body, 'items') && body.items.length > 0) {
|
if(_.isObject(body) && _.has(body, 'items') && body.items.length > 0) {
|
||||||
event.reply(this.internalAPI.formatLink(body.items[0]));
|
event.reply(this.internalAPI.formatLink(body.items[0]));
|
||||||
|
dbot.modules.link.links[event.channel.name] = 'https://youtu.be/' + body.items[0].id;
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user