3
0
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:
Scritches 2018-03-24 16:20:33 -04:00
parent b87175e665
commit 354c0935b9
4 changed files with 20 additions and 17 deletions

View File

@ -288,13 +288,13 @@ var lastfm = function(dbot) {
} }
} }
/* dbot.api.spotify.spotifySearch(term, function(body, t) { dbot.api.spotify.spotifySearch(term, function(body, url, uri) {
if(body) { if(body) {
output += ' - ' + t; output += ' - ' + url + ' - ' + uri;
} }
});*/ event.reply(output);
event.reply(output); });
}); });
} else { } else {
if(err == 'no_user') { if(err == 'no_user') {

View File

@ -6,6 +6,10 @@ Various Spotify functionality.
This module posts information on Spotify links, as well as providing Spotify This module posts information on Spotify links, as well as providing Spotify
search functionality. 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 ## Commands
### ~spotify [query] ### ~spotify [query]

View File

@ -1,5 +1,7 @@
{ {
"dependencies": [ "link" ], "dependencies": [ "link" ],
"ignorable": true, "ignorable": true,
"outputPrefix": "\u00039spotify\u000f" "outputPrefix": "\u00039spotify\u000f",
"api_key_clientid": "blah",
"api_key_clientsecret": "blah"
} }

View File

@ -21,16 +21,15 @@ var spotify = function(dbot) {
this.spotifyText = '\u00039spotify\u000f'; this.spotifyText = '\u00039spotify\u000f';
this.spotifyAuthUrl = 'https://accounts.spotify.com/api/token'; 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.auth = false;
this.spotifyClientID = 'e2491c50879a4d7f900dcefcc74b7c90';
this.spotifyClientSecret = 'b29da299612e4e659099ab3367ffa3f4';
this.spotifyAuth = new Buffer(this.spotifyClientID + ":" + this.spotifyClientSecret).toString("base64");
this.authenticate = function(callback) { this.authenticate = function(callback) {
this.auth = this.auth || new Buffer(this.config.api_key_clientid + ":" + this.config.api_key_clientsecret).toString("base64");
request({ request({
url: this.spotifyAuthUrl, url: this.spotifyAuthUrl,
method: "POST", method: "POST",
headers: { Authorization: "Basic " + this.spotifyAuth }, headers: { Authorization: "Basic " + this.auth },
form: { grant_type: "client_credentials" } form: { grant_type: "client_credentials" }
}, function(error, response, body) { }, function(error, response, body) {
if (!error && response.statusCode == 200) { if (!error && response.statusCode == 200) {
@ -83,11 +82,9 @@ var spotify = function(dbot) {
}, function(error, response, body) { }, function(error, response, body) {
if(!error && response.statusCode == 200) { if(!error && response.statusCode == 200) {
if(_.has(body, 'tracks') && body.tracks.items[0] && _.has(body.tracks.items[0], 'href')) { if(_.has(body, 'tracks') && body.tracks.items[0] && _.has(body.tracks.items[0], 'href')) {
var t = body.tracks.items[0].href; var url = body.tracks.items[0].href;
///*t = t.replace(/:/g, '/'); url = url.replace(/api.spotify.com\/v1\/tracks/, 'open.spotify.com/track');
t = t.replace(/api.spotify.com\/v1\/tracks/, callback(body, url, body.tracks.items[0].uri);
'open.spotify.com/track');
callback(body, t);
} else { } else {
callback(false); callback(false);
} }