mirror of
https://github.com/reality/dbot.git
synced 2024-11-27 06:19:24 +01:00
Move spotify api key into config; Restore spotify functionality to lastfm module ~listening command
This commit is contained in:
parent
b87175e665
commit
354c0935b9
@ -288,14 +288,14 @@ var lastfm = function(dbot) {
|
||||
}
|
||||
}
|
||||
|
||||
/* dbot.api.spotify.spotifySearch(term, function(body, t) {
|
||||
dbot.api.spotify.spotifySearch(term, function(body, url, uri) {
|
||||
if(body) {
|
||||
output += ' - ' + t;
|
||||
output += ' - ' + url + ' - ' + uri;
|
||||
}
|
||||
|
||||
});*/
|
||||
event.reply(output);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
if(err == 'no_user') {
|
||||
event.reply('Unknown LastFM user.');
|
||||
|
@ -6,6 +6,10 @@ Various Spotify functionality.
|
||||
This module posts information on Spotify links, as well as providing Spotify
|
||||
search functionality.
|
||||
|
||||
### config.json
|
||||
Edit the "api_key_clientid" setting with your Spotify API client ID. Edit the
|
||||
"api_key_clientsecret" setting with your Spotify API client secret.
|
||||
|
||||
## Commands
|
||||
|
||||
### ~spotify [query]
|
||||
|
@ -1,5 +1,7 @@
|
||||
{
|
||||
"dependencies": [ "link" ],
|
||||
"ignorable": true,
|
||||
"outputPrefix": "\u00039spotify\u000f"
|
||||
"outputPrefix": "\u00039spotify\u000f",
|
||||
"api_key_clientid": "blah",
|
||||
"api_key_clientsecret": "blah"
|
||||
}
|
||||
|
@ -21,16 +21,15 @@ var spotify = function(dbot) {
|
||||
this.spotifyText = '\u00039spotify\u000f';
|
||||
this.spotifyAuthUrl = 'https://accounts.spotify.com/api/token';
|
||||
|
||||
// ClientID and ClientSecret come from the spotify developer center; you will need to supply your own.
|
||||
this.spotifyClientID = 'e2491c50879a4d7f900dcefcc74b7c90';
|
||||
this.spotifyClientSecret = 'b29da299612e4e659099ab3367ffa3f4';
|
||||
this.spotifyAuth = new Buffer(this.spotifyClientID + ":" + this.spotifyClientSecret).toString("base64");
|
||||
this.auth = false;
|
||||
|
||||
this.authenticate = function(callback) {
|
||||
this.auth = this.auth || new Buffer(this.config.api_key_clientid + ":" + this.config.api_key_clientsecret).toString("base64");
|
||||
|
||||
request({
|
||||
url: this.spotifyAuthUrl,
|
||||
method: "POST",
|
||||
headers: { Authorization: "Basic " + this.spotifyAuth },
|
||||
headers: { Authorization: "Basic " + this.auth },
|
||||
form: { grant_type: "client_credentials" }
|
||||
}, function(error, response, body) {
|
||||
if (!error && response.statusCode == 200) {
|
||||
@ -83,11 +82,9 @@ var spotify = function(dbot) {
|
||||
}, function(error, response, body) {
|
||||
if(!error && response.statusCode == 200) {
|
||||
if(_.has(body, 'tracks') && body.tracks.items[0] && _.has(body.tracks.items[0], 'href')) {
|
||||
var t = body.tracks.items[0].href;
|
||||
///*t = t.replace(/:/g, '/');
|
||||
t = t.replace(/api.spotify.com\/v1\/tracks/,
|
||||
'open.spotify.com/track');
|
||||
callback(body, t);
|
||||
var url = body.tracks.items[0].href;
|
||||
url = url.replace(/api.spotify.com\/v1\/tracks/, 'open.spotify.com/track');
|
||||
callback(body, url, body.tracks.items[0].uri);
|
||||
} else {
|
||||
callback(false);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user