# !/bin/bash # Randomly plays all albums in current directory, optionally restricting to albums added since a number of days # Usage: play_albums [numdays] # numdays: max age of album (directory timestamp) # Assumes albums are directories containing tracks # requires mplayer and bash (un*x/cygwin) if [ -z $1 ]; then # play regardless of age echo "Playing random albums from `pwd`" else # play if modified before $1 days FIND_ARGS="-mtime -$1" echo "Playing random albums from `pwd` added less than $1 days ago" fi; find -type d $FIND_ARGS > /tmp/albums # uncomment to filter sound. negative values are reduced volume, positive are increased #VOLUME="-af volume=-20.0" MPLAYER_ARGS=$VOLUME # change to false to keep gaps (and not use aplay and fifo) # gapless playback source: http://snipplr.com/view/18353/gapless-playback-for-mplayer-linux/ GAPLESS=true if [ $GAPLESS ]; then USER=`id -un` FIFO=/tmp/aufifo.$USER MPLAYER_ARGS="$MPLAYER_ARGS -ao pcm:nowaveheader:file=$FIFO" fi; while [ true ]; do ALBUM=`cat /tmp/albums | sort -R | head -n 1` echo "Playing Album: $ALBUM" ls -1 "$ALBUM/*.*" if [ $GAPLESS ]; then killall aplay mkfifo $FIFO aplay -t raw -c 2 -f S16_LE -r 44100 $FIFO &> $FIFO.log & fi; mplayer $MPLAYER_ARGS "$ALBUM"/* if [ $GAPLESS ]; then killall aplay rm $FIFO fi; echo "Waiting 3s until next album... Hit ctrl-c to quit" sleep 3s done;