Public domain
#!/bin/bash
# History file
TMP="/tmp/PlayRandom"
touch ${TMP}
while :; do
# find number of files
COUNT=$(find .| wc -l)
# Create a random number between 1 and total number of files
number=$RANDOM
let "number %= $COUNT"
let "number += 1"
# Find exact filename of that random number
FILENAME=$(find . | head -n $number | tail -n 1)
# Check if it is file or directory
LIST=$(ls -lh "$FILENAME")
DIR=$(echo $LIST | egrep '^total')
# If it is a directory start again
if [ "${DIR}" != "" ]; then
continue
fi
# Check if it is played before
PWD=$(pwd)
FILENAME=$(echo ${FILENAME} | sed -e "s,\.,${PWD},")
EXIST=$(grep -q "${FILENAME}" "${TMP}";echo $?)
if [ "${EXIST}" == "0" ]; then
echo "\"${FILENAME}\" Played Before ..."
continue
fi
# Play the file
echo "Total Songs : $COUNT"
echo "play number : $number"
echo "Filename : \"$FILENAME\""
mplayer "$FILENAME"
RET=$(echo $?)
# If played completely save it to history
if [ "$RET" == "0" ]; then
echo $FILENAME >> ${TMP}
fi
# make space for break
echo;echo;echo;sleep 1
done
BY: Pejman Moghadam
TAG: bash, bash-script, random
DATE: 2009-05-26 13:40:34