File glslideshow.sh of Package xscreensaver

#!/bin/bash
# glslideshow.sh

VIDEOS=""
VIDDIR=""

GLSLIDESHOW=/usr/lib64/xscreensaver/glslideshow
if test ! -x $GLSLIDESHOW; then
	GLSLIDESHOW=/usr/lib/xscreensaver/glslideshow
fi

usage()
{
	echo "Usage: glslideshow.sh PICdir AUDIOdir [VIDEOdir]"
	echo "makeshow.sh assumes that DISPLAY points to an X display"
	echo "with a drawable root window." 
	exit 1
}

set_picdir()
{
	if test ! -e ~/.xscreensaver; then
		echo "imageDirectory:	$1" > ~/.xscreensaver
		return
	fi
	if grep '^imageDirectory:' ~/.xscreensaver 2>&1 >/dev/null; then
		#echo "s@^imageDirectory: .*\$@imageDirectory: $1@"
		sed -i "s@^imageDirectory:.*\$@imageDirectory:	$1@"  ~/.xscreensaver
	else
		echo "imageDirectory:	$1" >> ~/.xscreensaver
	fi
}

start_glslide()
{
	$GLSLIDESHOW -root -delay 16683 -duration 10 -pan 10 -zoom 60 -titles 2>&1 >/dev/null &
	GLPID=`pidof glslideshow`
}

disable_screensaver()
{
	xset -dpms
	xset s off
	unclutter -root &
}

stop_glslide()
{
	kill -STOP $GLPID
}

continue_glslide()
{
	kill -CONT $GLPID
}

finish_glslide()
{
	kill -CONT $GLPID
	kill -TERM $GLPID
}

enable_screensaver()
{
	xset r on
	xset +dpms
	killall unclutter
}

if test -z "$VIDEXTS"; then
	VIDEXTS=".mkv .x264.avi .h264.avi .H264.avi .avi .mp4 .mov .m4v .mpg .3gp"
fi

play_movie()
{
	# if better reencoded version exists with same filename, 
	# skip unprocessed duplicate
	MOV="$1"
	MOVUP="`dirname $MOV`"; MOVUP="${MOVUP%/*}/`basename $MOV`"
	for ext in $VIDEXTS; do
		NMOV="${MOV%.*}$ext"
		if test -e $NMOV; then MOV="$NMOV"; break; fi
		NMOV="${MOVUP%.*}$ext"
		if test -e $NMOV; then MOV="$NMOV"; break; fi
	done
	if test "$MOV" != "$1"; then return 1; fi
	stop_glslide
	mplayer -fs "$MOV"
	continue_glslide
	return 0
}

video_list()
{
	#echo "find -L $1 -name '*.mkv' -o -name '*.avi' -o -name '*.mp4' -o -name '*.mov' -o -name '*.mpg' -o -name '*.3gp' | shuf"
	VIDEOS="`find -L $1 -name '*.mkv' -o -name '*.avi' -o -name '*.mp4' -o -name '*.mov' -o -name '*.mpg' -o -name '*.3gp' | shuf`"
	NRVIDEOS=`echo "$VIDEOS" | wc -l`
	echo "$NRVIDEOS videos found"
}

next_movie()
{
	NRMOV=`echo "$VIDEOS" | grep -v '^$' | wc -l`
	if test "$NRMOV" = "0"; then video_list $VIDDIR; return; fi
	NEXTMOV=`echo "$VIDEOS" | head -n1`
	#echo "$NRMOV left; next: " $NEXTMOV
	VIDEOS=`echo "$VIDEOS" | tail -n$((NRMOV-1))`
	play_movie "$NEXTMOV"
}

song_list()
{
	SONGS="`find -L $1 -name '*.ogg' -o -name '*.mp3' | shuf`"
	NRSONGS=`echo "$SONGS" | wc -l`
	echo "$NRSONGS songs found"
}

play_song()
{
	case "$1" in
		(*.ogg)
			ogg123 "$1"
			;;
		(*.mp3)
			madplay "$1"
			;;
		(*)
			echo "ERROR"
			;;
	esac
}

main_loop()
{
	#global VIDDIR
	set_picdir $1
	start_glslide
	disable_screensaver
	song_list $2
	VIDDIR="$3"
	video_list $3
	for song in $SONGS; do
		play_song "$song"
		# Try twice ...
		next_movie || next_movie
	done
	enable_screensaver
}

if test -z "$2"; then usage; fi
if test -z "$3"; then
	main_loop $1 $2 $1
else	
	main_loop $1 $2 $3
fi
openSUSE Build Service is sponsored by