mocp rand

music-score I’m quite sure everyone reading this must have a respectable, if not massive, music collection. In this days and age is difficult finding someone who doesn’t. It’s also difficult to choose one, and only one, disk to listen at any given moment. Until we’re upgraded to support concurrent music listening we’re better of with a random disk selector, which is exactly what this little script does:
#!/bin/bash

SEARCH_DIR='/home/nico/Música'
START_RANDOM=1
RAND_MAX=32767

while (( 1 )); do
NUM_DISCS=$(find $SEARCH_DIR -type d|wc -l)
RAND=$(($NUM_DISCS * $RANDOM / $RAND_MAX))
RAND_DISC=$(find $SEARCH_DIR -type d | head -n $RAND | tail -n 1)

# Wake up moc
mocp -FS 2>/dev/null >/dev/null &
mocp -pca "$RAND_DISC" &
echo "Playing $RAND_DISC"

# Start from a random file?
if (( $START_RANDOM )); then
mocp --on shuffle &
mocp -f &
mocp --off shuffle &
fi

read
done
Of course, it requires mocp, my favorite music (on console) player. And obviously, you’ll have to configure SEARCH_DIR but I’m sure some bash hacking is not that hard.
Beware though, using this + cron may have the undesired effect of awakening to the pleasant music of Cannibal Corpse.
0601_ozzy_osbourne_c
Advertisements

One Comment on “mocp rand”

  1. […] And now you can sort by random your output using sort -R. Why would this be useful? Well, I updated my mocp random script with a […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s