spotify control
This commit is contained in:
@@ -62,16 +62,61 @@ function Spotify(config) {
|
||||
});
|
||||
};
|
||||
|
||||
this.getPlaybackState = () => {
|
||||
spotifyApi.getMyCurrentPlaybackState({
|
||||
})
|
||||
.then(function(data) {
|
||||
// Output items
|
||||
console.log("Now Playing: ",data.body);
|
||||
}, function(err) {
|
||||
console.log('Something went wrong!', err);
|
||||
this.getCurrentSong = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
spotifyApi.getMyCurrentPlaybackState({}, (err, data) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
let state = data.body;
|
||||
resolve({
|
||||
artists: state.item.artists,
|
||||
name: state.item.name,
|
||||
album: state.item.album.name,
|
||||
url: state.item.external_urls.spotify
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
this.getCurrentPlaylist = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
spotifyApi.getMyCurrentPlaybackState({}, (err, data) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
let state = data.body;
|
||||
if (state.context) {
|
||||
resolve(state.context.external_urls.spotify);
|
||||
} else {
|
||||
resolve(state.item.album.external_urls.spotify);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
this.skip = () => {
|
||||
return spotifyApi.skipToNext();
|
||||
};
|
||||
|
||||
this.pause = () => {
|
||||
return spotifyApi.pause();
|
||||
};
|
||||
|
||||
this.resume = () => {
|
||||
return spotifyApi.play();
|
||||
};
|
||||
|
||||
this.setVolume = (volume) => {
|
||||
volume = parseInt(volume);
|
||||
if (volume < 0) volume = 0;
|
||||
if (volume > 100) volume = 100;
|
||||
return spotifyApi.setVolume(volume);
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = Spotify;
|
||||
|
||||
Reference in New Issue
Block a user