#!/bin/bash

#find "$(pwd -P)" -type f -name "*.mp3" (gives absolute path)

version=0.7

currentpid=`echo $$`
ps aux | grep FFPLAY_GTK | grep -v grep | tr -s ' ' | cut -f 2 -d ' ' | grep -v $currentpid | while read pidtokill; do
	#pkill -P $pidtokill
	kill -9 $pidtokill 2>/dev/null
done

ffplay-gtk-timer kill
ffplay-gtk-timer ffkill

who=`whoami`
tmpfile=/tmp/$who-ffplay-gtk
if [ -f "$tmpfile"/user-playlist ]; then	
	find $tmpfile/ -type f -not -name playlist -not -name user-playlist -delete
else	
	rm -r $tmpfile 2>/dev/null
fi
mkdir $tmpfile 2>/dev/null
touch $tmpfile/human #if file doesn't exist immediately when gui loads it will never load once it appears
touch $tmpfile/chapter-title #same as above

if [ "`which ffplay`" = "" ] || [ "`which ffmpeg`" = "" ]; then
	echo $(gettext 'you need to install ffmpeg and ffplay from the ffmpeg package')
	exit
fi

##find a suitable version of gtkdialog (needs 0.7.20 or greater) currently (as of puppy 4 and maybe before)
##the executable is named gtkdialog3. Exit with a warning incase gtkdialog isn't found.
GTKDIALOG=""
if [ "`which gtkdialog4`" != "" ]; then
	GTKDIALOG=gtkdialog4
elif [ "`which gtkdialog3`" != "" ]; then
	GTKDIALOG=gtkdialog3
elif [ "`which gtkdialog`" != "" ]; then
	GTKDIALOG=gtkdialog
elif [ "$GTKDIALOG" = "" ]; then
	echo $(gettext 'you need to install gtkdialog')
	exit 1
fi

if ! [ -f "$1" ]; then
			export FFPLAY_GTK="
		<window title=\"ffplay-gtk $version\"icon-name=\"gtk-media-play\" resizable=\"true\">
				<frame $(gettext 'Select a media file supported by ffmpeg to play or a playlist of files with absolute paths')>
				<hbox>
  			   <chooser>
    <height>500 resizable=\"true\"</height><width>850 resizable=\"true\"</width>
    <variable>file-entry</variable>
  </chooser>	
				</hbox>
				
								<hbox>
				
					<button>
					<input file icon=\"gtk-apply\"></input>
					<label>$(gettext 'ok')</label>
					<action type=\"exit\">Exit-now</action>
				</button>

					<button>
						<input file stock=\"gtk-quit\"></input>
							<label>$(gettext 'quit')</label>
								<action type=\"exit\">KILL_THIS_SCRIPT</action>
					</button>
			
				</hbox>
				
				</frame>
			</window>
		"
	results="`$GTKDIALOG --program=FFPLAY_GTK`"
	
	if [ "`echo $results | grep KILL_THIS_SCRIPT`" != "" ]; then
		exit
	fi

	if [ "`echo $results | grep EXIT | grep abort`" != "" ]; then
		exit
	fi

	r2=`echo "$results" | sed 's/=\"/|\"/'`	
	filetoplay=`echo "$r2" | grep ^file-entry\| | cut -f 2 -d '|' | sed 's/\"//g'`
	rm -f $tmpfile/user-playlist 2>/dev/null
	rm -f $tmpfile/playlist 2>/dev/null

fi

if [ "$filetoplay" = "" ]; then
	filetoplay="$1"
fi

if ! [ -f "$filetoplay" ]; then
	echo "$filetoplay" $(gettext 'is not a file')
	exit
fi

if [ "`file "$filetoplay" | grep text$`" != "" ]; then
	cat "$filetoplay" | while read line; do
		if [ -f "$line" ]; then
			echo "$line" >> $tmpfile/playlist
		fi
	done
	filetoplay=`cat $tmpfile/playlist | head -n 1`
	touch $tmpfile/user-playlist
else
	if [ -f "$tmpfile"/user-playlist ]; then
		playlistfile=`cat $tmpfile/playlist | grep "$filetoplay"`
		if ! [ -f "$playlistfile" ]; then
			rm -f $tmpfile/user-playlist 2>/dev/null
			rm -f $tmpfile/playlist 2>/dev/null
		fi
	fi
fi

width=400
height=150

file=`basename "$filetoplay"`

echo 00:00 > $tmpfile/human 2>/dev/null

if [ "$2" != "" ]; then
	timetostart="$2"
else
	timetostart=0
fi

ff=`ffmpeg -i "$filetoplay" 2>&1`
meta=`echo "$ff" | grep -A 99 'Metadata:' | grep -v 'Metadata:' | grep -v 'At least one output file must be specified' | grep -v 'Side data:' | grep -v "Cover (front)" | grep 'Chapter #' -A 2 | sed 's/,\ end/|/' | sed 's/start\ /|/' | cut -f 2 -d '|' | awk '{$1=$1};1' | sed 's/title\ :\ //' | grep -v ^'Stream #'`
if  [ "$meta" != "" ]; then
	echo "$meta" | while read line; do
		d1=`date -u -d @"$line" +"%T" 2>/dev/null | sed 's/^0*//' | sed 's/^:*//'`
		if [ "$d1" != "" ]; then
			t1=`echo "$line" | cut -f 1 -d '.'`
			title=`echo "$meta" | grep "$line" -A 1 | grep -v "$line" | head -n 1 | sed 's/\ /_/g'`
			echo "$d1"\|"$t1"\|"$title" >> $tmpfile/specifics
		fi
	done
fi

videoinfo=`echo "$ff" | grep 'Stream #' | grep 'Video:' | grep -v mjpeg | grep -v 'Video: png,' | sed 's/Stream\ #0:0:\ Video:\ //'`
if [ "$videoinfo" != "" ]; then
	if [ "`which xdotool`" != "" ]; then
		xyear=`xdotool version | cut -f 2 -d '.' | tr -d -c 0-9 | head -c 4`
		if [ "$xyear" -lt 2019 ]; then
			echo $(gettext 'your version of xdotool is from') "$xyear" $(gettext 'and may be buggy')
			echo $(gettext 'you may want to think about upgrading it')
		fi
	fi
	ffplay -ss "$timetostart" "$filetoplay" 2> $tmpfile/timecount &
	touch $tmpfile/video
else
	ffplay -ss "$timetostart" "$filetoplay" -nodisp 2> $tmpfile/timecount &
fi
ffplay_pid=$!
sleep 0.1

if [ "`which xdotool`" != "" ]; then
	win=`xdotool search --all --name --pid $ffplay_pid ffplay 2>/dev/null`
	if [ "$win" = "" ]; then
		sleep 0.2
		win=`xdotool search --pid $ffplay_pid 2>/dev/null`
	fi
fi

seconds=`ffprobe -i "$filetoplay" -show_entries format=duration -v quiet -of csv="p=0"`
nofraction=`echo $seconds | cut -f 1 -d '.'`

if ! [ -f $tmpfile/specifics ] || [ "`cat $tmpfile/specifics | wc -l | cut -f 1 -d ' '`" = 1 ]; then
	t1=`echo "scale=2;$seconds/10" | bc -l`
	d1=`date -u -d @$t1 +"%T" | sed 's/^0*//' | sed 's/^:*//'`
	t2=`echo "scale=2;$t1*2" | bc -l`
	d2=`date -u -d @$t2 +"%T" | sed 's/^0*//' | sed 's/^:*//'`
	t3=`echo "scale=2;$t1*3" | bc -l`
	d3=`date -u -d @$t3 +"%T" | sed 's/^0*//' | sed 's/^:*//'`
	t4=`echo "scale=2;$t1*4" | bc -l`
	d4=`date -u -d @$t4 +"%T" | sed 's/^0*//' | sed 's/^:*//'`
	t5=`echo "scale=2;$t1*5" | bc -l`
	d5=`date -u -d @$t5 +"%T" | sed 's/^0*//' | sed 's/^:*//'`	
	t6=`echo "scale=2;$t1*6" | bc -l`
	d6=`date -u -d @$t6 +"%T" | sed 's/^0*//' | sed 's/^:*//'`
	t7=`echo "scale=2;$t1*7" | bc -l`
	d7=`date -u -d @$t7 +"%T" | sed 's/^0*//' | sed 's/^:*//'`
	t8=`echo "scale=2;$t1*8" | bc -l`
	d8=`date -u -d @$t8 +"%T" | sed 's/^0*//' | sed 's/^:*//'`
	t9=`echo "scale=2;$t1*9" | bc -l`
	d9=`date -u -d @$t9 +"%T" | sed 's/^0*//' | sed 's/^:*//'`
	t10=`echo "scale=2;$t1*10" | bc -l`
	d10=`date -u -d @$t10 +"%T" | sed 's/^0*//' | sed 's/^:*//'`
	t11=`echo "scale=2;$t1*.5" | bc -l`
	d11=`date -u -d @$t11 +"%T" | sed 's/^0*//' | sed 's/^:*//'`
	t12=`echo "scale=2;$t1*1.5" | bc -l`
	d12=`date -u -d @$t12 +"%T" | sed 's/^0*//' | sed 's/^:*//'`
	t13=`echo "scale=2;$t1*2.5" | bc -l`
	d13=`date -u -d @$t13 +"%T" | sed 's/^0*//' | sed 's/^:*//'`
	t14=`echo "scale=2;$t1*3.5" | bc -l`
	d14=`date -u -d @$t14 +"%T" | sed 's/^0*//' | sed 's/^:*//'`
	t15=`echo "scale=2;$t1*4.5" | bc -l`
	d15=`date -u -d @$t15 +"%T" | sed 's/^0*//' | sed 's/^:*//'`
	t16=`echo "scale=2;$t1*5.5" | bc -l`
	d16=`date -u -d @$t16 +"%T" | sed 's/^0*//' | sed 's/^:*//'`
	t17=`echo "scale=2;$t1*6.5" | bc -l`
	d17=`date -u -d @$t17 +"%T" | sed 's/^0*//' | sed 's/^:*//'`
	t18=`echo "scale=2;$t1*7.5" | bc -l`
	d18=`date -u -d @$t18 +"%T" | sed 's/^0*//' | sed 's/^:*//'`
	t19=`echo "scale=2;$t1*8.5" | bc -l`
	d19=`date -u -d @$t19 +"%T" | sed 's/^0*//' | sed 's/^:*//'`
	t20=`echo "scale=2;$t1*9.5" | bc -l`
	d20=`date -u -d @$t20 +"%T" | sed 's/^0*//' | sed 's/^:*//'`

	echo "00:00|0" > $tmpfile/specifics
	echo "$d11"\|"$t11" >> $tmpfile/specifics
	echo "$d1"\|"$t1" >> $tmpfile/specifics
	echo "$d12"\|"$t12" >> $tmpfile/specifics
	echo "$d2"\|"$t2" >> $tmpfile/specifics
	echo "$d13"\|"$t13" >> $tmpfile/specifics
	echo "$d3"\|"$t3" >> $tmpfile/specifics
	echo "$d14"\|"$t14" >> $tmpfile/specifics
	echo "$d4"\|"$t4" >> $tmpfile/specifics
	echo "$d15"\|"$t15" >> $tmpfile/specifics
	echo "$d5"\|"$t5" >> $tmpfile/specifics
	echo "$d16"\|"$t16" >> $tmpfile/specifics
	echo "$d6"\|"$t6" >> $tmpfile/specifics
	echo "$d17"\|"$t17" >> $tmpfile/specifics
	echo "$d7"\|"$t7" >> $tmpfile/specifics
	echo "$d18"\|"$t18" >> $tmpfile/specifics
	echo "$d8"\|"$t8" >> $tmpfile/specifics
	echo "$d19"\|"$t19" >> $tmpfile/specifics
	echo "$d9"\|"$t9" >> $tmpfile/specifics
	echo "$d20"\|"$t20" >> $tmpfile/specifics
	echo "$d10"\|"$t10" >> $tmpfile/specifics

fi

total=`date -u -d @$seconds +"%T" 2>/dev/null`
echo 0 > $tmpfile/newwidth
sleep 0.2

echo even > $tmpfile/pause

#meta=`echo "$ff" | grep -B 30 'Duration:' | grep -A 30 'Metadata:' | grep -v 'Metadata:' | grep -v 'At least one output file must be specified' | grep -v 'Side data:' | grep -v "Cover (front)" | awk '{$1=$1};1'`
meta=`echo "$ff" | grep -A 99 'Metadata:' | grep -v 'Metadata:' | grep -v 'At least one output file must be specified' | grep -v 'Side data:' | grep -v "Cover (front)" | awk '{$1=$1};1'`
tracktitle=`echo "$meta" | grep -i ^title | head -n 1 | sed 's/:\ /|/' | cut -f 2 -d '|'`
artist=`echo "$meta" | grep -i ^artist | head -n 1 | sed 's/:\ /|/' | cut -f 2 -d '|'`
if [ "$tracktitle" = "" ]; then
	tracktitle="$(gettext 'Title Not Found')"
fi
if [ "$artist" = "" ]; then
	artist="$(gettext 'Artist Not Found')"
fi

chapter=`cat $tmpfile/specifics | cut -f 3 -d '|' | head -n 1`
if [ "$chapter" != "" ]; then
	meta=`echo "$ff" | grep -B 30 'Duration:' | grep -A 30 'Metadata:' | grep -v 'Metadata:' | grep -v 'At least one output file must be specified' | grep -v 'Side data:' | grep -v "Cover (front)" | awk '{$1=$1};1'`
	lines=`wc -l $tmpfile/specifics | cut -f 1 -d ' '`
	num=1
	cat $tmpfile/specifics | cut -f 3 -d '|' | while read chnew; do
		chnew2=`echo "$chnew" | sed 's/_/\ /g'`
		start=`cat $tmpfile/specifics | grep "|$chnew$" | head -n 1 | cut -f 2 -d '|'`
		end1=`cat $tmpfile/specifics | grep "|$start|" -A1 | tail -n 1 | cut -f 2 -d '|'`
		end=`expr $end1 - 1`
		if [ "$num" = "$lines" ]; then
			end=$nofraction
		fi
		if [ "`cat $tmpfile/chapter | grep ^$chnew2$`" != "" ]; then
			y=2
			z=1
			while [ "$z" = 1 ]; do
				chnew2="$chnew2 $y"
				if [ "`cat $tmpfile/chapter | grep ^$chnew2$`" = "" ]; then
					z=2
				fi
				y=`expr $y + 1`
			done
		fi
		echo "$chnew2"\|$start\|$end >> $tmpfile/chapter
		num=`expr $num + 1`
	done
fi

ffplay-gtk-timer $timetostart $nofraction &
fgt=$!

dir=`dirname "$filetoplay"`
cd "$dir"

if [ "$videoinfo" = "" ]; then
	ffmpeg -y -i "$file" -nostats -loglevel 0 -map 0:v -vf scale=150:150 $tmpfile/cover.jpg < /dev/null
fi

echo "$file" > $tmpfile/currentfile

ext="${file##*.}"
if ! [ -f "$tmpfile"/playlist ]; then
	find . -maxdepth 1 -type f -name "*.$ext" | sort -V | sed 's/^.\///' > $tmpfile/playlist
fi	
pnumtotal=`cat $tmpfile/playlist | wc -l | tr -s ' ' | cut -f 1 -d ' '`
pnum=1
while [ "$pnum" -le "$pnumtotal" ]
do
	newplaylist=`cat $tmpfile/playlist | sed -n "$pnum"p`
	playlist="$playlist<item>$newplaylist</item>"
	pnum=`expr $pnum + 1`
done
	
previous=`cat $tmpfile/playlist | grep "$file" -B 1 | head -n 1`
next=`cat $tmpfile/playlist | grep "$file" -A 1 | tail -n 1`

specifics=""
	for specificlist in `cat $tmpfile/specifics | sed 's/|.*|/|/'`
	do
		specifics="$specifics<item>$specificlist</item>"
	done
	
export FFPLAY_GTK='

	<window title="ffplay-gtk '$version' '$file' "icon-name="gtk-media-play" width-request="660" height-request="230" resizable="true" scrollable="true">
	
	<hbox>
	'
	if [ -f $tmpfile/cover.jpg ]; then
		FFPLAY_GTK=$FFPLAY_GTK'
		<pixmap><input file>'$tmpfile'/cover.jpg</input><height>150</height><width>150</width></pixmap>
		'
	fi
	FFPLAY_GTK=$FFPLAY_GTK'
	<vbox>

				<text use-markup="true"><label>'$artist' - '$tracktitle'</label></text>
				
				<hbox>
					<entry editable="false" file-monitor="true" auto-refresh="true">
						<variable>timeentry</variable>
						<input file>'$tmpfile'/human</input>
						<action type="refresh">timeentry</action>
					</entry>
					<text use-markup="true"><label>'$total'</label></text>
					'
					if [ "$chapter" != "" ]; then
						FFPLAY_GTK=$FFPLAY_GTK'
					<entry editable="false" file-monitor="true" auto-refresh="true">
						<variable>chapter</variable>
						<input file>'$tmpfile'/chapter-title</input>
						<action type="refresh">chapter</action>
					</entry>
					'
					fi
					
					FFPLAY_GTK=$FFPLAY_GTK'
				</hbox>
	
	<hbox>

							
				<text><label>'$(gettext 'Specific Times')':</label></text>
				<combobox>
					<variable>specific</variable>
					'$specifics'
				</combobox>
				
				<button tooltip-text="'$(gettext 'select a time to the left and click the button')'">
					<input file icon="gtk-ok"></input>
					<label>go to specific time</label>
						<action>ffplay-gtk-timer kill</action>
					   	<action>ffplay-gtk-timer ffkill</action>
					   	<action>ffplay-gtk-timer specific '\"$file\"' $specific '$nofraction' '\"$videoinfo\"'</action>
				</button>
				
	</hbox>
	
		<hbox>

							
				<text><label>'$(gettext 'Select file')':</label></text>
				<combobox>
					<variable>play</variable>
					'$playlist'
				</combobox>
				
				<button tooltip-text="'$(gettext 'select a file to play and click the button')'">
					<input file icon="gtk-ok"></input>
					<label>'$(gettext 'play file')'</label>
						<action>ffplay-gtk-timer kill</action>
					   	<action>ffplay-gtk-timer ffkill</action>
					   	<action>ffplay-gtk "$play" &</action>
				</button>
				
	</hbox>
	
					<hbox>
						<menubar>
					<menu>
						<menuitem icon="gtk-media-pause">
							<label>'$(gettext 'pause / play')'</label>
					'
					if [ "$videoinfo" != "" ]; then
						if [ "`which xdotool`" != "" ]; then
							FFPLAY_GTK=$FFPLAY_GTK'
							<action>xdotool key --clearmodifiers --window '$win' p</action>
							'
						else
							FFPLAY_GTK=$FFPLAY_GTK'
							<action>ffplay-gtk-timer check '\"$file\"' video</action>
							'
						fi
					 else
						FFPLAY_GTK=$FFPLAY_GTK'
						<action>ffplay-gtk-timer check '\"$file\"'</action>
						'
						fi
						FFPLAY_GTK=$FFPLAY_GTK'
					 <action>ffplay-gtk-timer kill</action>
					 <action>ffplay-gtk-timer even</action>
					 	<action>ffplay-gtk-timer `cat '$tmpfile'/timer` '$nofraction' '$fgt' play &</action>
					   <action>sleep 0.2</action>
					    <action type="refresh">timeentry</action>
						</menuitem>
						
						<menuitem icon="gtk-media-next">
					<label>'$(gettext 'go forward 10 seconds')'</label>
					<action>ffplay-gtk-timer pausecheck '$win'</action>
						<action>ffplay-gtk-timer ffkill</action>
					'
					if [ "$videoinfo" != "" ]; then
						FFPLAY_GTK=$FFPLAY_GTK'
						<action>ffplay-gtk-timer audio 10 '\"$file\"' video</action>
					'
					 else
						FFPLAY_GTK=$FFPLAY_GTK'
						<action>ffplay-gtk-timer audio 10 '\"$file\"'</action>
						'
					fi
					FFPLAY_GTK=$FFPLAY_GTK'
						<action>ffplay-gtk-timer kill</action>
					   <action>ffplay-gtk-timer `cat '$tmpfile'/timer` '$nofraction' &</action>
					   <action>sleep 0.2</action>
						</menuitem>
						
						<menuitem icon="gtk-media-next">
					<label>'$(gettext 'go forward 1 minute')'</label>
					<action>ffplay-gtk-timer pausecheck '$win'</action>
						<action>ffplay-gtk-timer ffkill</action>
					'
					if [ "$videoinfo" != "" ]; then
						FFPLAY_GTK=$FFPLAY_GTK'
						<action>ffplay-gtk-timer audio 60 '\"$file\"' video</action>
					'
					 else
						FFPLAY_GTK=$FFPLAY_GTK'
						<action>ffplay-gtk-timer audio 60 '\"$file\"'</action>
						'
					fi
					
					FFPLAY_GTK=$FFPLAY_GTK'
					   <action>ffplay-gtk-timer kill</action>
					   <action>ffplay-gtk-timer `cat '$tmpfile'/timer` '$nofraction' &</action>
					   <action>sleep 0.2</action>
						</menuitem>
						
						<menuitem icon="gtk-jump-to">
					<label>'$(gettext 'go backward 1 minute')'</label>
					<action>ffplay-gtk-timer pausecheck '$win'</action>
						<action>ffplay-gtk-timer ffkill</action>
					'
					if [ "$videoinfo" != "" ]; then
						FFPLAY_GTK=$FFPLAY_GTK'
						<action>ffplay-gtk-timer audio -60 '\"$file\"' video</action>
					'
					 else
						FFPLAY_GTK=$FFPLAY_GTK'
						<action>ffplay-gtk-timer audio -60 '\"$file\"'</action>
						'
					fi
					
					FFPLAY_GTK=$FFPLAY_GTK'
					   <action>ffplay-gtk-timer kill</action>
					   <action>ffplay-gtk-timer `cat '$tmpfile'/timer` '$nofraction' &</action>
					   <action>sleep 0.2</action>
						</menuitem>
						
						<menuitem icon="gtk-jump-to">
					<label>'$(gettext 'go backward 10 seconds')'</label>
					<action>ffplay-gtk-timer pausecheck '$win'</action>
						<action>ffplay-gtk-timer ffkill</action>
					'
					if [ "$videoinfo" != "" ]; then
						FFPLAY_GTK=$FFPLAY_GTK'
						<action>ffplay-gtk-timer audio -10 '\"$file\"' video</action>
					'
					 else
						FFPLAY_GTK=$FFPLAY_GTK'
						<action>ffplay-gtk-timer audio -10 '\"$file\"'</action>
						'
					fi
					
					FFPLAY_GTK=$FFPLAY_GTK'
						<action>ffplay-gtk-timer kill</action>
					   <action>ffplay-gtk-timer `cat '$tmpfile'/timer` '$nofraction' &</action>
					   <action>sleep 0.2</action>
						</menuitem>
						
						<menuitem icon="gtk-add">
					<label>'$(gettext 'new file')'</label>
					<action>ffplay-gtk-timer kill</action>
					   	<action>ffplay-gtk-timer ffkill</action>
					 <action>ffplay-gtk &</action>
						</menuitem>
						
					'
					if [ "`which fftag`" != "" ]; then
						FFPLAY_GTK=$FFPLAY_GTK'
						
						<menuitem icon="gtk-edit">
					<label>'$(gettext 'edit metadata in fftag')'</label>
					<action>fftag '\"$file\"' &</action>
						</menuitem>
						
					'
					fi
					FFPLAY_GTK=$FFPLAY_GTK'
						
						
						<label>[ '$(gettext 'options')' ]</label>
					</menu>
				</menubar>
					'
					if [ "$videoinfo" != "" ]; then
					if [ "`which xdotool`" != "" ]; then
						FFPLAY_GTK=$FFPLAY_GTK'				
								<button tooltip-text="'$(gettext 'if full screen goes over your dock bar hit the f key to get back to the gui')'">
					<input file icon="gtk-zoom-fit"></input>
					<label>'$(gettext 'full screen toggle')'</label>
					 <action>xdotool key --clearmodifiers --window '$win' f</action>
				 </button>
				 '
				 fi
				 fi
					FFPLAY_GTK=$FFPLAY_GTK'
					
					<button tooltip-text="'$(gettext 'play previous file')' '$previous'">
					<input file icon="gtk-media-previous"></input>
					<label>'$(gettext 'previous')'</label>
					 <action>ffplay-gtk-timer kill</action>
					   	<action>ffplay-gtk-timer ffkill</action>
					 <action>ffplay-gtk '\"$previous\"' &</action>
				 </button>
				 
				 <button tooltip-text="'$(gettext 'play next file')' '$next'">
					<input file icon="gtk-media-next"></input>
					<label>'$(gettext 'next')'</label>
					 <action>ffplay-gtk-timer kill</action>
					   	<action>ffplay-gtk-timer ffkill</action>
					 <action>ffplay-gtk '\"$next\"' &</action>
				 </button>
				
				<button>
					<input file icon="gtk-quit"></input>
					<label>'$(gettext 'quit')'</label>
					 <action>ffplay-gtk-timer ffkill</action>
					<action>ffplay-gtk-timer kill</action>
					 <action type="exit">EXIT_NOW</action>
				</button>
				
				</hbox>
				
				<hbox>
				<hscale width-request="480" height-request="50" range-value="0" tooltip-text="select percentage of file to move to">
			<variable>percent</variable>
			 <action>ffplay-gtk-timer kill</action>
			<action>ffplay-gtk-timer ffkill</action>
			'
			if [ "$videoinfo" = "" ]; then
			FFPLAY_GTK=$FFPLAY_GTK'
			<action>ffplay-gtk-timer percent $percent '$nofraction' '\"$file\"' &</action>
			'
			else
			FFPLAY_GTK=$FFPLAY_GTK'
			<action>ffplay-gtk-timer percent $percent '$nofraction' '\"$file\"' video &</action>
			'
			fi
			FFPLAY_GTK=$FFPLAY_GTK'
		</hscale>
		<hseparator></hseparator>
				</hbox>

</vbox>
</hbox>
	
	</window>
		'
results="`$GTKDIALOG --program=FFPLAY_GTK  --geometry +650+780`" 

ffplay-gtk-timer kill

exit


