Commit fd80c43f authored by Deac Karns's avatar Deac Karns
Browse files

Merge branch 'dev' of git.karnsonline.com:karns-online/spotiko into dev

parents f849eab9 7911c9f7
{
"name": "spotiko",
"version": "0.1.0",
"version": "0.1.1",
"description": "a node CLI app for working with the spotify API",
"main": "spotiko",
"bin": {
......
......@@ -19,7 +19,7 @@ table = new Table({
});
program
.version('0.1.0')
.version('0.1.1')
.option('-a, --add', 'Add current track to default playlist', 0)
.option('-s, --settings', 'Display the current configuration', 0)
.option('-c, --current', 'Display the current playing track', 0)
......@@ -133,20 +133,21 @@ const exchangeAuthorizationCodeForTokens = function(code) {
},
json: true
}
return new Promise(function(resolve, reject) {
request.post(options, function(error, response, body) {
if (!error && response.statusCode === 200) {
writeToConfig(
{
access_token:body.access_token,
refresh_token:body.refresh_token
}
);
resolve(true);
}
return new Promise(function(resolve, reject) {
return request.post(options, function(error, response, body) {
if (!error && response.statusCode === 200) {
writeToConfig(
{
access_token:body.access_token,
refresh_token:body.refresh_token
}
);
config.access_token = body.access_token;
config.refresh_token = body.refresh_token
resolve(config);
}
});
});
});
}
const addTrackToPlaylist = function(track, playlist) {
......@@ -262,6 +263,7 @@ const ensureClientId = function() {
writeToConfig({
client_id: answers.answer
});
config.client_id = answers.answer;
return answers.answer;
});
}else{
......@@ -286,6 +288,7 @@ const ensureClientSecret = function() {
writeToConfig({
client_secret: answers.answer
});
config.client_secret = answers.answer;
return answers.answer;
});
}else{
......@@ -298,68 +301,64 @@ const ensureClientSecret = function() {
const ensureTokens = function() {
if(!config.authorization_code){
return new Promise(function(resolve, reject) {
return new Promise(function(resolve) {
console.reset()
displayAuthorizeUrl()
.then( (authorizeUrl) => {
return new Promise(function(resolve, reject) {
opn(authorizeUrl)
resolve(true)
});
})
.then( () => {
return promptForAuthorizationCode()
})
.then( (code) => {
writeToConfig({authorization_code:code});
return code;
})
.then( (code) => {
return exchangeAuthorizationCodeForTokens(code)
})
return displayAuthorizeUrl()
.then( (authorizeUrl) => {
return new Promise(function(resolve, reject) {
opn(authorizeUrl)
resolve(true)
});
})
.then( () => {
return promptForAuthorizationCode()
})
.then( (code) => {
writeToConfig({authorization_code:code});
return code;
})
.then( (code) => {
resolve(exchangeAuthorizationCodeForTokens(code))
})
});
}
else{
return new Promise(function(resolve, reject) {
resolve(config.authorization_code)
return new Promise(function(resolve) {
resolve(config)
});
}
}
const ProgramPlaylist = function(playlist=null) {
if(!playlist){
console.log('no playlist');
dynpl = selectPlaylist()
}else{
console.log('yes playlist');
dynpl = new Promise(resolve => reslove())
dynpl = new Promise(resolve => resolve(playlist))
}
return dynpl
.then( pl => {
console.log('here');
return getPlaylistTracks(pl)
})
.then( t => {
t.items.forEach( function(i) {
table.push(
[i.track.name, i.track.artists.map( (artist) => artist.name).toString(), i.track.album.name]
);
})
return table;
})
.then( t => {
console.log(table.toString())
return t
.then( pl => {
return getPlaylistTracks(pl)
})
.then( t => {
t.items.forEach( function(i) {
table.push(
[i.track.name, i.track.artists.map( (artist) => artist.name).toString(), i.track.album.name]
);
})
return table;
})
.then( t => {
console.log(table.toString())
return t
})
}
const runProgram = function(){
if(program.add){
refreshAccessToken()
return refreshAccessToken()
.then( () => {
getCurrentTrack()
.then( track => {
......@@ -378,36 +377,32 @@ const runProgram = function(){
.then( playlist => {
return addTrackToPlaylist(track, playlist)
})
.then(tst => {
return tst
})
})
.then( playlist => {
ProgramPlaylist(playlist)
process.exit()
return ProgramPlaylist(playlist)
})
})
}
else if(program.current){
refreshAccessToken()
.then( () => {
return getCurrentTrack()
return refreshAccessToken()
.then( () => {
return getCurrentTrack()
})
.then( (track) => {
console.log(colors.cyan('\n[Track]'))
console.log(colors.magenta(' Artist: ')+track.album_artist);
console.log(colors.magenta(' Album: ')+track.album_name);
console.log(colors.magenta(' Name: ')+track.track_name);
console.log(colors.magenta(' ID: ')+track.track_id);
console.log(colors.magenta(' URI: ')+track.track_uri);
console.log(colors.magenta(' URL: ')+track.track_url);
console.log(colors.cyan('\n[Track]'))
console.log(colors.magenta(' Artist: ')+track.album_artist);
console.log(colors.magenta(' Album: ')+track.album_name);
console.log(colors.magenta(' Name: ')+track.track_name);
console.log(colors.magenta(' ID: ')+track.track_id);
console.log(colors.magenta(' URI: ')+track.track_uri);
console.log(colors.magenta(' URL: ')+track.track_url);
return true
})
})
.finally( () => process.exit())
}
else if(program.playlist){
ProgramPlaylist()
return ProgramPlaylist()
}
else if(program.settings){
......@@ -420,6 +415,7 @@ const runProgram = function(){
}
ensureClientId()
.then(ensureClientSecret)
.then(ensureTokens)
.finally(runProgram)
\ No newline at end of file
.then(ensureClientSecret)
.then(ensureTokens)
.then(runProgram)
.finally(process.exit)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment