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

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

parents a7dcd416 6d3a5033
# EthReal
A command line utility that will display the current market values of the Cryptocurrencies you care most about right in your terminal. EthReal utilizes data from the [coinmarketcap.com](https://coinmarketcap.com) top 100.
# Spotiko
A command line utility for adding your current playing song to a pre-existing playlist. This is primarily a
convenience program so you dont have to keep leaving your development environment to save songs you like.
- [Install](#install)
- [Useage](#useage)
- [Configuration](#configuration)
- [Following a Cryptocurrency](#following-a-cryptocurrency)
- [Colors](#colors)
- [Options](#options)
- [Supported Cryptocurrencies](#supported-cryptocurrencies)
- [Useage](#useage)
### Install
```
npm install ethreal -g
```
### Useage
```
ethreal
```
### Output
```
╔══════════════╤══════════╤════════╤════════╤═══════════╤══════════╗
║ Crypto │ USD │ 24h │ 7d │ Holding │ USD ║
╟──────────────┼──────────┼────────┼────────┼───────────┼──────────╢
║ Bitcoin │ $15477.3 │ 8.5 │ -19.49 │ - │ - ║
╟──────────────┼──────────┼────────┼────────┼───────────┼──────────╢
║ Ethereum │ $759.211 │ 9.31 │ 9.0 │ 2 │ $1518.42 ║
╟──────────────┼──────────┼────────┼────────┼───────────┼──────────╢
║ Bitcoin Cash │ $3448.4 │ 19.08 │ 90.88 │ 1 │ $3448.40 ║
╟──────────────┼──────────┼────────┼────────┼───────────┼──────────╢
║ Litecoin │ $304.587 │ 9.87 │ 0.93 │ 0.1194417 │ $36.38 ║
╚══════════════╧══════════╧════════╧════════╧═══════════╧══════════╝
npm install spotiko -g
```
### Configuration
All the configuration data is stored in a `json` file in your home directory `~/.ethreal`
All the configuration data is stored in a `json` file in your home directory `~/.spotiko`
### Holdings
You can now calculate the value of your holdings automatically with EthReal. Holdings data is stored in the configuration file `~/.ethreal` as a type float. No private data is saved or stored, just a number.
The first time you run spotiko it will prompt you for the following details. obtaining them
can be found at the spotify documentation for developers https://developer.spotify.com/dashboard/
- client id
- client secret
##### Add Holdings
Example adding `0.001234` to your bitcoin holdings
```
ethreal -a 0.001234 -s btc
```
##### Remove Holdings
Example removing `0.001234` from your bitcoin holdings
### Useage
Add current track to a playlist
```
ethreal -r 0.001234 -s btc
spotiko -a
```
### Following a Cryptocurrency
###### Follow
Example, start following Bytecoin. the color option is optional. `red` will be used by default
View the current configuration
```
ethreal -f bcn -c yellow
spotiko -s
```
###### Un-follow
Example, stop following Bytecoin
View details about the current track
```
ethreal -u bcn
spotiko -c
```
### Colors
Changing the color of a cryptocurrency row is easy.
View the tracks in a playlist
```
ethreal -s btc -c blue
spotiko -p
```
##### Available colors
black, red, green, yellow, blue, magenta, cyan, white, gray, grey,
bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite,
reset, bold, dim, italic, underline, inverse, hidden, strikethrough,
rainbow, zebra, america, trap, random
### Additional Options
```
ethreal -h
spotiko -h
```
### Supported Cryptocurrencies
EthReal is currently able to display the current market value in USD for the [coinmarketcap.com](https://coinmarketcap.com) top 100:
{
"name": "spotiko",
"version": "0.0.4",
"version": "0.1.0",
"description": "a node CLI app for working with the spotify API",
"main": "spotiko",
"bin": {
......
......@@ -7,20 +7,23 @@ const home = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE
const inquirer = require('inquirer');
const request = require('request');
const querystring = require('querystring');
//const readlineLib = require('readline');
const opn = require('opn');
/*const readline = readlineLib.createInterface({
input: process.stdin,
output: process.stdout
});*/
table = new Table({
head: ['Title', 'Artist', 'Album'],
chars: { 'top': '' , 'top-mid': '' , 'top-left': '' , 'top-right': ''
, 'bottom': '' , 'bottom-mid': '' , 'bottom-left': '' , 'bottom-right': ''
, 'left': '' , 'left-mid': '' , 'mid': '' , 'mid-mid': ''
, 'right': '' , 'right-mid': '' , 'middle': '' },
colWidths: [40, 20, 20]
});
program
.version('0.0.4')
.version('0.1.0')
.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)
.option('-p, --playlist', 'Display the default playlist', 0)
.option('-p, --playlist', 'Display playlist tracks', 0)
.parse(process.argv);
console.reset = function () {
......@@ -146,26 +149,49 @@ const exchangeAuthorizationCodeForTokens = function(code) {
});
}
const addTrackToPlaylist = function(track,playlist) {
trackString = querystring.stringify({
uris: track.track_uri,
});
const addTrackToPlaylist = function(track, playlist) {
trackString = querystring.stringify({
uris: track.track_uri,
});
let options = {
url: ' https://api.spotify.com/v1/playlists/'+playlist.id+'/tracks?'+trackString,
auth: {
'bearer': config.access_token
},
json: true
}
let options = {
url: ' https://api.spotify.com/v1/playlists/'+playlist.id+'/tracks?'+trackString,
auth: {
'bearer': config.access_token
},
json: true
}
return new Promise(function(resolve, reject) {
request.post(options, function(error, response, body) {
if (!error && response.statusCode >= 200 && response.statusCode < 300) {
resolve(true);
}
});
});
return new Promise(function(resolve, reject) {
request.post(options, function(error, response, body) {
if (!error && response.statusCode >= 200 && response.statusCode < 300) {
resolve(playlist);
}else{
reject(error);
}
})
})
}
const selectPlaylist = function(){
console.log('\n');
return getAllPlaylists()
.then( (pl) => {
let playlists = pl.items.map(p => p.name)
return inquirer
.prompt([
{
type: 'list',
name: 'playlist',
message: 'Select a playlist?',
choices: playlists
}
])
.then(answers => {
let list = pl.items.filter( p => p.name == answers.playlist )
return list.shift()
});
})
}
const getCurrentTrack = function() {
......@@ -191,27 +217,6 @@ const getCurrentTrack = function() {
})
}
const getDefinedPlaylist = function() {
let options = {
url: 'https://api.spotify.com/v1/me/playlists',
auth: {
'bearer': config.access_token
}
}
return new Promise(function(resolve, reject) {
request(options, function(error, response, body){
let playlists = JSON.parse(body)
let use = playlists.items.filter(function(playlist) {
return (playlist.name == 'Bi Weekly Build')
})
playlist = use.shift()
resolve(playlist);
})
})
}
const getAllPlaylists = function() {
let options = {
url: 'https://api.spotify.com/v1/me/playlists',
......@@ -227,6 +232,21 @@ const getAllPlaylists = function() {
})
}
const getPlaylistTracks = function(playlist) {
let options = {
url: 'https://api.spotify.com/v1/playlists/'+playlist.id+'/tracks',
auth: {
'bearer': config.access_token
},
json: true
}
return new Promise(function(resolve, reject) {
request(options, function(error, response, body){
resolve(body);
})
})
}
const ensureClientId = function() {
if(!config.client_id){
var questions = [
......@@ -308,40 +328,65 @@ const ensureTokens = function() {
}
}
const ProgramPlaylist = function(playlist=null) {
if(!playlist){
console.log('no playlist');
dynpl = selectPlaylist()
}else{
console.log('yes playlist');
dynpl = new Promise(resolve => reslove())
}
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
})
}
const runProgram = function(){
if(program.add){
refreshAccessToken()
.then( () => {
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);
return track
})
.then( (track) => {
return getDefinedPlaylist()
.then( (playlist) => {
console.log(colors.cyan('\n[Playlist]'))
console.log(colors.magenta(' Name: ')+playlist.name)
console.log(colors.magenta(' ID: ')+playlist.id)
return playlist
}).then( (playlist) => {
return addTrackToPlaylist(track, playlist)
refreshAccessToken()
.then( () => {
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);
return track
})
.then( track => {
return selectPlaylist()
.then( playlist => {
return addTrackToPlaylist(track, playlist)
})
.then(tst => {
return tst
})
})
.finally( () => {
console.log('\nTrack added to playlist\n');
process.exit()
.then( playlist => {
ProgramPlaylist(playlist)
process.exit()
})
})
})
}
else if(program.current){
......@@ -362,16 +407,7 @@ const runProgram = function(){
}
else if(program.playlist){
refreshAccessToken()
.then( () => {
return getDefinedPlaylist()
.then( (playlist) => {
console.log(colors.cyan('\n[Playlist]'))
console.log(colors.magenta(' Name: ')+playlist.name)
console.log(colors.magenta(' ID: ')+playlist.id)
})
})
.finally( () => process.exit())
ProgramPlaylist()
}
else if(program.settings){
......@@ -383,10 +419,7 @@ const runProgram = function(){
}
}
getAllPlaylists()
.then(pl => console.log(pl))
/*ensureClientId()
ensureClientId()
.then(ensureClientSecret)
.then(ensureTokens)
.finally(runProgram)*/
\ No newline at end of file
.finally(runProgram)
\ 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