Skip to content

Instantly share code, notes, and snippets.

@WillBrubaker
Created November 1, 2019 05:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WillBrubaker/249be31fc58b55e70900c7107ea86db8 to your computer and use it in GitHub Desktop.
Save WillBrubaker/249be31fc58b55e70900c7107ea86db8 to your computer and use it in GitHub Desktop.
like a song on spotify
#!/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