diff --git a/modules/lastfm/lastfm.js b/modules/lastfm/lastfm.js index 9dbdfc1..ec79ec8 100644 --- a/modules/lastfm/lastfm.js +++ b/modules/lastfm/lastfm.js @@ -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) { - output += ' - ' + t; + output += ' - ' + url + ' - ' + uri; } - - });*/ - event.reply(output); + + event.reply(output); + }); }); } else { if(err == 'no_user') { diff --git a/modules/spotify/README.md b/modules/spotify/README.md index ec0839f..5e2d0b4 100644 --- a/modules/spotify/README.md +++ b/modules/spotify/README.md @@ -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] diff --git a/modules/spotify/config.json b/modules/spotify/config.json index 0b1135b..4eb225e 100644 --- a/modules/spotify/config.json +++ b/modules/spotify/config.json @@ -1,5 +1,7 @@ { "dependencies": [ "link" ], "ignorable": true, - "outputPrefix": "\u00039spotify\u000f" + "outputPrefix": "\u00039spotify\u000f", + "api_key_clientid": "blah", + "api_key_clientsecret": "blah" } diff --git a/modules/spotify/spotify.js b/modules/spotify/spotify.js index 72e6743..39ff8a8 100644 --- a/modules/spotify/spotify.js +++ b/modules/spotify/spotify.js @@ -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); }