Wednesday, November 21, 2012

Add random songs to MPD playlist

The first part puts currently playing song in a text-file for use in other programs. The second part adds random songs while there is less than 3 songs in the playlist. This probably isn't optimized or even good, to be frank, but it works. ^^

Update 1: As I have more than one mpd server running I figured it'd be more efficient catching the hostname as well as minimum tracks from stdin.
Update 2: Checks if we actually got a song to add as mpc add "" adds ALL the songs in your library.
Update 3: Cleaned up the code. Added NEXT_ON_ERROR to keep going if MPD stops while trying to play a song.
Update 4: Now backgrounds itself automagically. Also, functions are neat.
Update 5: Comments and exit 0.