exec 3<> /dev/tcp/vapier/8001
send() { echo "$*" 1>&3 ; }
-recv() { local l; read l <&3; echo ${l%$'\r'} ; }
+recv() { local l; read l <&3; echo ${l%$'\r'} | sed 's:\r$::' ; }
+
+shell() {
+ cat <&3 &
+ trap "kill $!" 0
+ send "${*:-help}"
+ sleep 1
+ while read -p "vlc$ " -e l ; do
+ [[ -z $l ]] && continue
+ case $l in
+ "?") l="help" ;;
+ esac
+ send "$l"
+ case $l in
+ quit) break ;;
+ esac
+ sleep 1
+ done
+}
case $1 in
f|fullscreen)
send f $2
;;
-help)
- send $1
- cat <&3
- ;;
pause|quit)
send $1
;;
send vol$*
;;
seek)
- off=( 0 5 15 30 60 )
- [[ -z $2 || -n ${2//[-+]} ]] && exit 0
- off=${off[${#2}]}
- send get_time
- curr=$(recv)
- send seek $(( curr ${2:0:1} off ))
+ if [[ -n $2 && -z ${2//[-+]} ]] ; then
+ off=( 0 5 15 30 60 )
+ off=${off[${#2}]}
+ send get_time
+ curr=$(recv)
+ set -- seek $(( curr ${2:0:1} off ))
+ send "$@"
+ else
+ shell "$@"
+ fi
+ ;;
+strack)
+ if [[ $2 == "n" ]] ; then
+ set -f
+ send strack
+ e="+----[ end of Subtitles Track ]"
+ while l=$(recv) ; do
+ set -- $l
+ if [[ $l == "$e" ]] ; then
+ break
+ elif [[ $l == "| "* ]] ; then
+ [[ -z $s ]] && s=$2
+ if [[ $l == *" *" ]] ; then
+ l=$(recv)
+ if [[ $l != "$e" ]] ; then
+ set -- $l
+ s=$2
+ fi
+ break
+ fi
+ fi
+ done
+ kdialog --msgbox "$l" &
+ set -- strack $s
+ send "$@"
+ else
+ shell "$@"
+ fi
;;
*)
- send "$@"
+ shell "$@"
;;
esac