Created
November 1, 2019 05:35
-
-
Save WillBrubaker/249be31fc58b55e70900c7107ea86db8 to your computer and use it in GitHub Desktop.
like a song on spotify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/node | |
//https://www.thathandsomebeardedguy.com/i'd-love-to-❤️-you-more | |
var args = process.argv.slice( 2 )[ 2 ]; | |
var trackId; | |
songURI = args.match( '^.*track:([a-zA-Z0-9]+)' )[ 1 ]; | |
//npm install fs | |
var fs = require( "fs" ); | |
var file = "token.txt"; | |
//npm install scp | |
var scp = require( 'scp' ); | |
var scpOptions = { | |
file: 'token.txt', | |
user: 'username', | |
host: 'theserverwhereyourtokenfileresides.com', | |
port: '22', | |
path: '/path/to/where/you/want/to/save/' | |
} | |
scp.get( scpOptions, function ( err, stdout, stderr ) { | |
if ( !err && songURI ) { | |
var data = fs.readFileSync( file ); | |
var token = data.toString().replace( '\n', '' ); | |
var credentials = { | |
clientId: 'some client id', | |
clientSecret: 'some client secret', | |
redirectUri: 'http://localhost:8888/callback' | |
}; | |
var SpotifyWebApi = require( 'spotify-web-api-node' ); | |
var spotifyApi = new SpotifyWebApi( credentials ); | |
spotifyApi.setAccessToken( token ); | |
spotifyApi.addToMySavedTracks( [ songURI ] ).then( function ( data ) { | |
console.log( 'Added track!' ); | |
}, function ( err ) { | |
console.log( 'Something went wrong!', err ); | |
} ); | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment