summaryrefslogtreecommitdiffstats
path: root/mplayer
Side-by-side diff
Diffstat (limited to 'mplayer') (more/less context) (ignore whitespace changes)
-rwxr-xr-xmplayer180
1 files changed, 16 insertions, 164 deletions
diff --git a/mplayer b/mplayer
index 82cad0e..605cf51 100755
--- a/mplayer
+++ b/mplayer
@@ -1,155 +1,5 @@
#!/bin/zsh
-HIST="$HOME/.mplayer.hist"
-AUX_INVO=0
-POSITION=0
-maxplayers=1
-network=0
-stdin=0
-firstime=0
-randnum=$((${RANDOM}%${maxplayers}))
-mkdir -p /tmp/mplayer
-MPSOCKET="/tmp/mplayer/$randnum.fif"
-fixedvo=1
-typeset -A vo_map
-vo_map=(1 fixed-vo 0 nofixed-vo)
-
-pecho(){
- msg="$1"
- file="$2"
- /bin/echo "$msg" >| $file &
- sleep 0.1
- echo < $file
-}
-
-# curl for non-strict url parsing ;)
-isurl () {
- curl -I -s "$url" &>/dev/null || return 1
- return 0
-}
-
-
-check_pattern(){
- pecho "get_property filename" $1
- if tail -2 /tmp/mplayer.log | /bin/grep 'ANS_filename' | /bin/grep -v grep ;then
- pecho "get_property pause" $1
- if tail -2 /tmp/mplayer.log | /bin/grep 'ANS_pause=no' | /bin/grep -v grep ;then
- retval=0
- return 0
- fi
- retval=2
- fi
- [[ -z $retval ]] && retval=1
- return 1
-}
-
-
-parse(){
-if [[ -z "$1" ]];then
- fnum=$(awk '{ print NR" "$0 }' $HIST | cut -d ":" -f 1 | uniq -f 1 | tac | ${=DMENU})
- [[ -z "$fnum" ]] && exit
- num=$(echo "$fnum" | cut -d " " -f 1)
- FILE=$(head -${num} $HIST | tail -1 | cut -d ":" -f 1)
-
- if [[ $fnum == *: ]];then
- name="$(cut -d ' ' -f 1 <<< $FILE)"
- POSITION="$(grep $name $HIST | tail -1 | cut -d ':' -f 2)"
- fi
-
-else
- if [[ $1 == "-" ]];then
- stdin=1
- return
- fi
- if isurl "$(tr -d '.' <<< $1)";then # Fix /a/b/c/d type
- FILE="$1"
- network=1
- else
- if [[ "[email protected]" == /* ]];then
- prefix=
- else
- prefix="$pwdir/"
- fi
- FILE="${prefix}[email protected]"
- fi
-fi
-retval=$FILE
-}
-
-preplay(){
- mpc pause &>/dev/null
- ln -sf $MPSOCKET /tmp/mplayer.fif || exit 1
-}
-
-check_status(){
-if [[ $fixedvo == 1 ]];then
- pidof mplayer || return 1
- echo >>| /tmp/mplayer.log
- retval=1
- for ff in /tmp/mplayer/*.fif;do
- if check_pattern $ff;then
- return $retval
- fi
- done
- return $retval
-else
- if xdotool search --class mplayer;then
- return 1
- else
- return 0
- fi
-fi
-}
-
-aux(){
-case $1 in
- status)
- check_status
- return $?
- ;;
- clean)
- rm /tmp/mplayer/* 2>/dev/null
- rm /tmp/mplayer.fif 2>/dev/null
- killall -9 mplayer 2>/dev/null
- rm /tmp/locks/mplayer* 2>/dev/null
- mv /tmp/mplayer.log /tmp/.mplayer.log
- exit
- ;;
- pause)
- pecho 'pause' $MPSOCKET
- ;;
- snext)
- pecho 'seek +10' $MPSOCKET
- ;;
- sprev)
- pecho 'seek -10' $MPSOCKET
- ;;
- pnext)
- pecho "pt_step 1" $MPSOCKET
- ;;
- pprev)
- pecho "pt_step -1" $MPSOCKET
- ;;
- stop)
- wheret
- echo "$retval" >>| ~/.mplayer.hist
- pecho 'stop' $MPSOCKET
- echo "#STOPPED ${file}" >>| /tmp/mplayer.log
- ;;
- *)
- return 1
-esac
-}
-
-wheret(){
- pecho 'get_time_pos' $MPSOCKET
- pecho 'get_property path' $MPSOCKET
- sleep 3
- LOG="tail -5 /tmp/mplayer.log"
- position=$(${=LOG} | /bin/grep ANS_TIME_POSITION | head -1 | cut -d "=" -f 2)
- file=$(${=LOG} | /bin/grep ANS_path | head -1 | cut -d "=" -f 2)
- retval="$file:$position"
-}
+source ~/bin/mplayer.fns
if [[ $0 == *mplayeraux ]];then
AUX_INVO=1
@@ -160,37 +10,38 @@ if [[ ! -e $MPSOCKET ]] ;then
firstime=1
mkfifo $MPSOCKET
ln -sf $MPSOCKET /tmp/mplayer.fif
- #notify-send "Mplayer" "mplayer starting up....."
+ notify-send "Mplayer" "mplayer starting up....."
fi
exec &>>|/tmp/mplayer.log
-
-
pwdir=$(pwd)
-pushd $HOME
-${=LOCK}/mplayer.$randnum /usr/bin/mplayer -$vo_map[$fixedvo] -msglevel all=4 -slave -idle -input file=$MPSOCKET -input conf=$HOME/.mplayer/input.conf.mine &!
-popd
+pushd -q $HOME
+if [[ $stdin == 1 ]];then
+ fd=$(readlink -f /dev/stdin)
+ exec 3<&0
+ exec 0</dev/tty
+ ${=LOCK}/mplayer.$randnum /usr/bin/mplayer -$vo_map[$fixedvo] -msglevel all=4 -slave -idle -input file=$MPSOCKET -input conf=$HOME/.mplayer/input.conf.mine &!
+else
+ ${=LOCK}/mplayer.$randnum /usr/bin/mplayer -$vo_map[$fixedvo] -msglevel all=4 -slave -idle -input file=$MPSOCKET -input conf=$HOME/.mplayer/input.conf.mine &!
+fi
+popd -q
FILE=$retval
preplay
-[[ $firstime == 1 ]] && sleep 2
+[[ $firstime == 1 ]] && sleep 1
if [[ $stdin == 1 ]];then
- fd=$(readlink -f /dev/stdin)
- exec 3<&0
- exec 0</dev/tty
- #${=LOCK}/mplayer.$randnum /usr/bin/mplayer -$vo_map[$fixedvo] -msglevel all=4 -slave -idle -input file=$MPSOCKET -input conf=$HOME/.mplayer/input.conf.mine &!
pecho "loadfile $fd " /tmp/mplayer.fif
- #/usr/bin/mplayer -
- exit 110
+ exit 11
else
pecho "loadfile \"$FILE\" 2" $MPSOCKET
fi
+(
check_status
# Queue or play
@@ -206,4 +57,5 @@ else
fi
fi
/bin/echo "mplayer \"$FILE\"" >>| ~/.current
+) &
# vim: set foldmethod=marker: