2ck

dxmms2

2ck
Aug 4th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.30 KB | None | 0 0
  1. #!/bin/bash
  2. ##########################
  3. # simple xmms2 script    #
  4. # for dmenu              #
  5. ##########################
  6.  
  7. CONFIG=$HOME/.config/dxmms2
  8. # default configs
  9. # {{{
  10. TITLE_WIDTH=190
  11. BG_COLOR=#002b36
  12. FG_COLOR=#657b83
  13. SEL_BG_COLOR=$FG_COLOR
  14. SEL_FG_COLOR=$BG_COLOR
  15. FONT=Sazanami Mincho-8
  16. # }}}
  17.  
  18. if [ -e $CONFIG ] ; then
  19.     source $CONFIG
  20. fi
  21.  
  22. my_dmenu ()
  23. {
  24.     local prompt=${1:-">"}
  25.     local height=${2:-4}
  26.     LANG=en_US.UTF-8 dmenu -p $prompt -nf $FG_COLOR -nb $BG_COLOR -sb $SEL_BG_COLOR -sf $SEL_FG_COLOR -i -l $height -fn "$FONT"
  27. }
  28.  
  29. my_printf=/usr/bin/printf
  30.  
  31. commands="toggle list +fav prev next stop info change-playlist clear"
  32. fields="artist album title"
  33. nfields="rating duration"
  34.  
  35. pipe=/tmp/dxmms2-pipe
  36. if [ ! -e $pipe ] ; then
  37.     mkfifo $pipe
  38. fi
  39.  
  40. while [ 1 ] ; do
  41. command=`echo ${commands} | sed "s/ /\n/g" | my_dmenu`
  42. case $command in
  43.     list)
  44.         # requires
  45.         #  CLASSIC_LIST=true
  46.         #  CLASSIC_LIST_FORMAT=${artist}::${title}
  47.         # in .config/xmms2/clients/nycli.conf
  48.         morestring=--More--
  49.         backstring=--Back--
  50.         listoff=0
  51.         listing=1
  52.         while [ $listing -eq 1 ] ; do
  53.             current=`xmms2 list "-1" | egrep -o "\[([[:digit:]]+)/"|egrep -o "[[:digit:]]+"`
  54.             current=$((current + 1 + listoff))
  55.  
  56.             xmms2 list $current-$((current + 15)) > $pipe &
  57.             disown
  58.             items=`cat $pipe | head -n -2 |
  59.               sed "s/^.\+] \(.*\)::\(.*\) (..:..) \?$/\1\x00\2\x00/; s/%/%%/" |
  60.               xargs --null $my_printf "%-70s%${TITLE_WIDTH}s" |
  61.               nl -v$((listoff+1)) -w2 -s ". "| head -n -1`
  62.             items="$items
  63. $backstring
  64. $morestring"
  65.             nitems=`echo "${items}" | wc -l`
  66.             pos=`echo "${items}" | my_dmenu "Track: " ${nitems} |
  67.             egrep -o "^[[:space:]]*-?[[:digit:]]+|$morestring|$backstring" |
  68.             sed -E 's/^[[:space:]]*(.*)[[:space:]]*$/\1/'`
  69.             if [ x$pos == x$morestring ] ;then
  70.                 listoff=$((listoff + 15))
  71.             elif [ x$pos == x$backstring ] ;then
  72.                 listoff=$((listoff - 15))
  73.             else
  74.                 listing=0
  75.             fi
  76.         done
  77.         if [ ${pos} ] ; then
  78.             xmms2 jump `printf "%+d" $((pos - 1))`
  79.             echo $pos
  80.             xmms2 play
  81.         fi
  82.         break;;
  83.     info)
  84.         info=`xmms2 info | egrep -e "artist|title|album|tracknr|favorite|url"|
  85.         sed -E 's/^[^]]*\][[:space:]]*// ; s/ = /\n/'`
  86.         echo "$info" | zenity --height=300 --width=400 --title="XMMS2 Track Info" --list --text="Track info" --column "field" --column "value"
  87.         break;;
  88.     +fav)
  89.         id=`xmms2 info | grep "server.* id " | grep -o "[[:digit:]]*$"`
  90.         fav=`xmms2 info | grep "cli.* favorite " | grep -o "[[:digit:]]*$"`
  91.         fav=$((fav + 1))
  92.         xmms2 server property $id favorite $fav
  93.         break;;
  94.     search)
  95.         field=`echo ${fields} ${nfields} | sed "s/ /\n/g" | my_dmenu`
  96.         break;;
  97.     change-playlist)
  98.         pls=`xmms2 playlist list`
  99.         nitems=`echo "$pls"|wc -l`
  100.         pl=`echo "$pls" | cut -c 3- | my_dmenu "Playlist: " ${nitems}`
  101.         xmms2 playlist switch $pl
  102.         break;;
  103.     *)
  104.         if [ $command ] ; then
  105.             xmms2 $command
  106.         fi
  107.         break;;
  108. esac
  109. done
Advertisement
Add Comment
Please, Sign In to add comment