#!/bin/bash LOOP=1 RECURSIVE=0 VERBOSE=0 NOTDONE=0 help() { echo "Usage: afspil [OPTION]... [-] FILE..." echo "Play movie or audio files." echo echo " -l, --loop loop play" echo " -R, --recursive play subdirectories recursively" echo " -v, --verbose be more verbose (twice: be very verbose)" echo " --help display this help and exit" echo " --version output version information and exit" echo echo "Report bugs to ." exit } version() { echo "afspil 1.4" exit } error() { echo "afspil: $1" echo "Try \`afspil --help' for more information." exit } warning() { echo "afspil: cannot play \`$1: $2" } display() { if [ $VERBOSE -gt $1 ]; then echo -ne "$2" fi } doneplay() { display 0 "\n" } playing() { display 0 "Playing $1-file: \`$2'..." } filtererror() { if [ "$1" != "" ]; then display 0 "\nFilter had errors. Continuing." display 1 "\n$1" fi } _afspil() { OPTS="--notdone " temp=$VERBOSE while [ $temp -gt 0 ]; do OPTS=$OPTS"--verbose " temp=$[$temp-1] done temp=$RECURSIVE while [ $temp -gt 0 ]; do OPTS=$OPTS"--recursive " temp=$[$temp-1] done OPTS=$OPTS"- " for afile in "$@"; do afile=`echo $afile | sed -e 's/"/\\"/g'` afspil $OPTS "$afile" done } while [ $# != 0 -a `echo $1 | grep -c "^-"` != 0 ]; do case "$1" in (-l|--loop) LOOP=-1 ;; (-R|--recursive) RECURSIVE=1 ;; (-v|--verbose) VERBOSE=$[$VERBOSE+1] ;; (--notdone) NOTDONE=1 ;; (--help) help ;; (--version) version ;; (-) shift break ;; (*) error "unrecognized option \`$1'" ;; esac shift done if [ $# = 0 ]; then error "too few arguments" fi while [ $LOOP -gt 0 -o $LOOP -eq -1 ]; do for file in "$@"; do file=`echo $file | sed -e 's/"/\\"/g'` if [ -f "$file" ]; then case "$file" in (*.mpg|*.MPG|*.mpeg|*.MPEG|*.mpe|*.MPE|*.dat|*.DAT) playing "MPEG" "$file" filtererror "`gtv "$file" 2>&1 > /dev/null`" doneplay ;; (*.AVI|*.avi) playing "AVI" "$file" filtererror "`aviplay "$file" 2>&1 > /dev/null`" doneplay ;; (*.ASF|*.asf) playing "DivX" "$file" filtererror "`aviplay "$file" 2>&1 > /dev/null`" doneplay ;; (*.MOV|*.mov) playing "MOV" "$file" filtererror "`xanim +Ak +b +c +f +Zpe "$file" 2>&1 > /dev/null`" doneplay ;; (*.qt|*.QT) playing "QuickTime" "$file" filtererror "`xanim +Ak +b +c +f +Zpe "$file" 2>&1 > /dev/null`" doneplay ;; (*.fli|*.FLI) playing "FLI" "$file" filtererror "`xanim +Ak +b +c +f +Zpe "$file" 2>&1 > /dev/null`" doneplay ;; (*.rm|*.RM) playing "RealMovie" "$file" filtererror "`realplay "$file" 2>&1 > /dev/null`" doneplay ;; (*.ra|*.RA) playing "RealAudio" "$file" filtererror "`realplay "$file" 2>&1 > /dev/null`" doneplay ;; (*.mp3|*.MP3) playing "MP3" "$file" filtererror "`mpg123 -q "$file" 2>&1 > /dev/null`" doneplay ;; (*.m3u|*.M3U) playing "playlist" "$file" lines=`cat "$file" | tr "\r" "\n" | grep -v "^$" | wc -l` i="0" doneplay while [ $i -lt $lines ]; do i=$[$i+1] thisfile="`cat "$file" | tr "\r" "\n" | grep -v "^$" | head -n $i | tail -n 1`" _afspil "$thisfile" done ;; (*) warning "$file" "File format not supported" ;; esac else if [ -d "$file" ]; then if [ $RECURSIVE -gt 0 ]; then display 0 "Recursing into: \`$file'...\n" cd "$file" lines=`ls | grep -i "[.]m3u$" | grep -v "^$" | wc -l` if [ $lines -gt 0 ]; then i=0 while [ $i -lt $lines ]; do i=$[$i+1] thisfile="`ls | grep -i "[.]m3u$" | grep -v "^$" | head -n $i | tail -n 1`" _afspil "$thisfile" done else _afspil * fi cd .. else warning "$file" "Recursive play not enabled" fi else warning "$file" "No such file" fi fi done LOOP=$[$LOOP-1] if [ $LOOP -lt 0 ]; then LOOP=-1; fi done if [ $NOTDONE -eq 0 ]; then display 0 "Playing is done.\n" fi