_mpd_helper 888 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # variables
  2. mpc="/usr/bin/mpc -h $mpd_host"
  3. # functions
  4. function play_folder {
  5. tag = $1
  6. mkdir -p /music/$tag
  7. # Update the directory timestamp to indicate what was the last tag found
  8. # Touch the file alone will not update the directory timestamp,
  9. # so we'll need delete and recreate the file
  10. rm /music/$tag/.lastplay
  11. touch /music/$tag/.lastplay
  12. $mpc stop
  13. $mpc clear
  14. $mpc add $mpd_folder$tag
  15. _ensure_volume_10
  16. $mpc play
  17. }
  18. function mpd_play {
  19. $mpc stop
  20. $mpc clear
  21. $mpc add "$1"
  22. _ensure_volume_10
  23. $mpc play 1
  24. }
  25. function mpd_play_shuffle {
  26. $mpc stop
  27. $mpc clear
  28. $mpc add "$1"
  29. $mpc shuffle
  30. _ensure_volume_10
  31. $mpc play 1
  32. }
  33. function mpd_set_volume {
  34. if [ -n "$1" ]; then # non-zero length
  35. $mpc volume $value
  36. fi
  37. }
  38. function _ensure_volume_10 {
  39. if (( $($mpc volume | grep -o '...%' | tr -d '%') < 10 )); then
  40. mpd_set_volume 10
  41. fi
  42. }