Aug 25, 2004 21:40
cron + a simple random file selection/detection shell script + a directory full of symlinks to mp3s = ALARM CLOCK.
I need a life.
#!/bin/bash
# where to look for your tracks
TRACKPATH=~/wakeup/tracks
# now seed the random generator...
RANDOM=$$$(date +%s)
# check tracks
NUMTRACKS=$(ls $TRACKPATH | wc -l)
# get a random number within range
TRACKNUM=$(echo "$RANDOM % $NUMTRACKS + 1" | bc)
# get that track
TRACK=$(ls $TRACKPATH | sed -n $(echo -n $TRACKNUM)p)
TRACKTYPE=$(file -b -L "$TRACKPATH/$TRACK"| cut -c 1-3)
# play the file using a type dependant player
case $TRACKTYPE in
MP3)
mpg123 "$TRACKPATH/$TRACK"
;;
Ogg)
ogg123 "$TRACKPATH/$TRACK"
;;
*)
echo "unknown file type: $TRACKTYPE"
echo "caused by track: $TRACK"
;;
esac