Skip to content

Instantly share code, notes, and snippets.

@cmbaughman
Created June 30, 2023 00:12
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 cmbaughman/af4a0b43e4e5564d2c5e0938e5db8c8d to your computer and use it in GitHub Desktop.
Save cmbaughman/af4a0b43e4e5564d2c5e0938e5db8c8d to your computer and use it in GitHub Desktop.
Spotify Bot
const SpotifyWebApi = require('spotify-web-api');
const fs = require('fs');
const os = require('os');
const readline = require('readline');
const spotify = new SpotifyWebApi({
clientId: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
redirectUri: 'http://localhost:3000',
});
const songs = fs.readFileSync('songs.txt', 'utf8').split('\n');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.on('line', async (line) => {
if (line === 'stop') {
process.exit();
} else {
for (const song of songs) {
const uri = await spotify.tracks.getTrackInfo({ id: song });
await spotify.player.play({ uri });
await new Promise((resolve, reject) => {
setTimeout(resolve, os.platform() === 'darwin' ? 3000 : 1000);
});
}
}
});
rl.on('close', () => {
console.log('Exiting...');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment