#!/bin/bash

IFS=$'\n'
list=($@)
if [ -z "$list" ] || [ "$list" = \%U ]; then
    play=`yad --center --title="MultiPlay" --window-icon="applications-multimedia" --width=600 --borders=10 --form --item-separator="¦" --field=$"Play File(s)"":":MFL --field=$"Play Folder"":":MDIR`
    play="${play//|/}¦"
    list=()
    until [ -z "$play" ]; do
	list=(${list[@]} ${play%%¦*})
	play="${play#*¦}"
    done
fi
[ -z "$list" ] && exit
[ -d "$list" ] && play=($list"/*") && list=($(find "$list"/* -maxdepth 0 -not -type d)) || play=(${list[@]})
[ "${list[*]}" != "$(sed -r "s/\.(jpe?g|png|gif)//I" <<< "${list[*]}")" ] && pic=true || pic=false
$pic && eog -s $(for b in ${list[@]}; do
		    echo "$b"
		 done | grep -iE "\.(jpe?g|png|gif|svg)")
mplayer -fs -framedrop -quiet -shuffle -volume 100 ${play[@]}