mmpd_check.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/sh
  2. ## This is my (demuredemeanor) polybar script for handling Multi Music Player Display.
  3. ## Displays playing song for:
  4. ## (control)pianobar
  5. ## cmus
  6. ## mpd
  7. ## mocp
  8. ## audacios
  9. ## Initialize variable
  10. MMPD_CHECK="none"
  11. ### Music Player Checks ### {{{
  12. ## NOTE: These are listed in order of what I might actually use (so things I don't are later)
  13. ## NOTE: if an earlier music player reports a song (or paused) later players will not be tested
  14. ## (control)pianobar
  15. if [ "${MMPD_CHECK}" = "none" ] && [ $(command -v pianobar) ]; then
  16. MMPD_CHECK="$(grep -qxs 1 ${HOME}/.config/pianobar/isplaying && cat ${HOME}/.config/pianobar/nowplaying || echo 'none')"
  17. fi
  18. ## cmus
  19. if [ "${MMPD_CHECK}" = "none" ] && [ $(command -v cmus-remote) ]; then
  20. MMPD_CHECK="$(cmus-remote -Q 2>/dev/null | awk 'BEGIN {STATUS=0;STREAM=0;TITLE=0;ARTIST=0} {match($0, /^(status|stream|tag title|tag artist)\s(.*)/, m); if(m[1]=="status"){STATUS=m[2]};if(m[1]=="stream"){STREAM=m[2]}; if(m[1]=="tag title"){TITLE=m[2]}; if(m[1]=="tag artist"){ARTIST=m[2]}} END {if(STATUS!=0){if(STATUS=="playing"){if(STREAM!=0){print STREAM} else if(ARTIST!=0&&TITLE!=0){print ARTIST " - " TITLE} else if(TITLE!=0){print TITLE}else {print "cmus: no meta data"}} else if(STATUS=="paused"){print "cmus: paused"} else {print "none"}} else {print "none"}}')"
  21. fi
  22. ## mpd
  23. if [ "${MMPD_CHECK}" = "none" ] && [ $(command -v mpc) ]; then
  24. MMPD_CHECK="$(mpc status 2>/dev/null | awk 'BEGIN {STATUS=0;INFO=0} !/^volume/ {match($0, /^(\w+.*)/, p); match($0, /(\[playing\]|\[paused\])/, m); if(m[0]!=""){STATUS=m[1]}; if(p[0]!=""){INFO=p[0]}} END {if(STATUS!=0){if(STATUS=="[paused]"){print "mpd: paused"} else {print INFO}} else {print "none"}}')"
  25. fi
  26. ## mocp
  27. if [ "${MMPD_CHECK}" = "none" ] && [ $(command -v mocp) ]; then
  28. MMPD_CHECK="$(mocp --info 2>/dev/null | awk 'BEGIN {STATE=0; TITLE=0; ARTIST=0} {match($0, /^(State|Title|Artist):\s(.*)/, m); if(m[1]=="State"){STATE=m[2]}; if(m[1]=="Artist"&&m[2]!=""){ARTIST=m[2]}; if(m[1]=="Title"&&m[2]!=""){TITLE=m[2]}} END {if(STATE!=0){if(STATE=="PLAY"){if(TITLE!=0){print TITLE} else {print "mocp: no meta data"}} else if(STATE=="PAUSE"){print "mocp: paused"} else {print "none"}} else {print "none"}}')"
  29. fi
  30. ## audacios
  31. if [ "${MMPD_CHECK}" = "none" ] && [ $(command -v audtool) ]; then
  32. MMPD_CHECK="$(audtool --playback-status --current-song 2>/dev/null | awk 'BEGIN {STATUS=0; INFO=0} {if($0=="playing"||$0=="paused"){STATUS=$0}; if(STATUS=="playing"){INFO=$0}} END {if(INFO!=0){print INFO} else if(STATUS=="paused"){print "audacios: paused"} else {print "none"}}')"
  33. fi
  34. ### End Music Player Checks ### }}}
  35. ## If no music, return fancy none icon
  36. if [ "${MMPD_CHECK}" = "none" ]; then
  37. MMPD_CHECK="×"
  38. fi
  39. ## Return results
  40. echo "${MMPD_CHECK}"