Created
June 30, 2023 00:12
-
-
Save cmbaughman/af4a0b43e4e5564d2c5e0938e5db8c8d to your computer and use it in GitHub Desktop.
Spotify Bot
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
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