-
Notifications
You must be signed in to change notification settings - Fork 0
/
spotify.js
43 lines (34 loc) · 1.87 KB
/
spotify.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var keys = require('./keys.js');
var SpotifyWebApi = require('spotify-web-api-node');
var spotifyThis = function(type, search) {
var spotifyApi = new SpotifyWebApi(keys.spotifyKeys);
spotifyApi.clientCredentialsGrant()
.then(function(data) {
// Save the access token so that it's used in future calls
spotifyApi.setAccessToken(data.body['access_token']);
if (type === 'track') {
spotifyApi.searchTracks(search)
.then(function(data) {
console.log();
console.log('Artist: ' + data.body.tracks.items[0].album.artists[0].name);
console.log('Song: ' + data.body.tracks.items[0].name);
console.log('Link: ' + data.body.tracks.items[0].external_urls.spotify);
}, function(err) {
console.log(err);
})
} else if (type === 'artist') {
spotifyApi.searchArtists(search)
.then(function(data) {
console.log();
console.log('Artist Name: ' + data.body.artists.items[0].name);
console.log('Artist Page: ' + data.body.artists.items[0].href);
console.log('Genres: ' + data.body.artists.items[0].genres);
}, function(err) {
console.log(err);
})
}
}, function(err) {
console.log('Something went wrong when retrieving an access token', err.message);
});
}
module.exports = spotifyThis;