mmpd_check.sh 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. ## spotify-tui
  35. #if [ "${MMPD_CHECK}" = "none" ] && [ $(command -v spotify-tui) ]; then
  36. #MMPD_CHECK="$(pgrep spotifyd >/dev/null && spotify-tui playback --status 2>/dev/null | awk 'BEGIN {PLAY=0} {if($1=="▶"){PLAY=1};if($2=="▶"){PLAY=1}} END {if(PLAY==1){print " " $0} else {print "none"}}')"
  37. #fi
  38. ### End Music Player Checks ### }}}
  39. ## If no music, return fancy none icon
  40. if [ "${MMPD_CHECK}" = "none" ]; then
  41. MMPD_CHECK="×"
  42. fi
  43. ## Return results
  44. echo "${MMPD_CHECK}"