--- /dev/null
+#!/bin/bash
+
+
+playlist=.playlist.tmp
+player="/usr/bin/mplayer"
+if [ -x "/usr/bin/mplayer2" ]; then
+ player="/usr/bin/mplayer2"
+fi
+
+playeropts="-af-add bs2b"
+
+optRandom=""
+optRepeat=""
+optRecursive=0
+optRemove=0
+optQuiet=""
+optVerbose=0
+optReverse=0
+optSorttime=0
+
+
+function showHelp
+{
+ echo "Plays mp3 files in all subdirectories."
+ echo "Usage: ./mp-play.sh [-h|--help] [-R|--random] [-r|--repeat] "
+ echo " [-a|-recursive] [--reverse] [--time]"
+ echo " [--remove] [-q|--quiet] [-v|--verbose] [DESTINATION]"
+ echo ""
+ echo "Options:"
+ echo " --time sort by age of file"
+ echo " -R, --random randomize files"
+ echo " -r, --repeat repeat playing infintely"
+ echo " -a, --recursive recursively find files to play"
+ echo " --reverse reverse playing order"
+ echo " --remove ask to remove played files after playing"
+ echo " -q, --quiet do not produce output when playing"
+ echo " -v, --versbose produce more output"
+}
+
+#Parse the arguments
+while [ $# -gt 0 ]
+do
+ case "$1" in
+ -h|--help) showHelp; exit 0 ;;
+ -R|--random) optRandom="-shuffle" ;;
+ -r|--repeat) optRepeat="-loop 0" ;;
+ -a|--recursive) optRecursive=1 ;;
+ -v|--verbose) optVerbose=1 ;;
+ -q|--quiet) optQuiet="-quiet" ;;
+ --remove) optRemove=1 ;;
+ --reverse) optReverse=1 ;;
+ --time) optSorttime=1 ;;
+ *) break ;;
+ esac
+ shift
+done
+
+
+
+if [ "$optRecursive" == "1" ]; then
+ maxlevel=9999
+else
+ maxlevel=1
+fi
+
+
+# Create playlist
+find "$@" -maxdepth $maxlevel -type f \
+ -iname "*.mp3" -or -iname "*.avi" -or -iname "*.flv" \
+ -or -iname "*.mp4" -or -iname "*.ogg" \
+ | sort > $playlist
+
+[ "$optSorttime" == "1" ] && cat "$playlist" | xargs ls --sort=time | sponge "$playlist"
+[ "$optReverse" == "1" ] && cat "$playlist" | tac | sponge "$playlist"
+
+
+cntfiles=`wc -l $playlist | cut -d " " -f 1`
+
+#No files found...
+if [ "$cntfiles" == "0" ]
+then
+ echo "No files found."
+ exit 1
+fi
+
+
+
+echo "Playing $cntfiles files..."
+echo ""
+
+# Print playlist, if we ask for removing files later
+if [ "$optRemove" == "1" -o "$optVerbose" == "1" ]; then
+ cat $playlist
+fi
+
+
+# Play it
+$player $playeropts $optQuiet $optRandom $optRepeat -playlist "$playlist"
+
+
+# Remove the files in the playlist
+if [ "$optRemove" == "1" ]; then
+ echo ""
+ echo -n "Removing played files? (y/a/N) "
+ read isdel
+ if [ x"y" == x"$isdel" ]; then
+ rm -v `cat $playlist`
+ elif [ x"a" == x"$isdel" ]; then
+ rm -v -i `cat $playlist`
+ fi
+fi
+
+#Remove the playlist itself
+rm -f $playlist
+