_mpd_helper 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # variables
  2. mpc="/usr/bin/mpc -h $mpd_host"
  3. # functions
  4. function mpd_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_stop {
  34. $mpc stop
  35. }
  36. function mpd_pause_play {
  37. if ($mpc | grep -q playing); then # when playing
  38. $mpc pause
  39. else
  40. $mpc play
  41. fi
  42. }
  43. function vol_min {
  44. mpd_set_volume 5
  45. }
  46. function mpd_med {
  47. mpd_set_volume 50
  48. }
  49. function mpd_vol_max {
  50. mpd_set_volume 75
  51. }
  52. function mpd_set_volume {
  53. if [ -n "$1" ]; then # non-zero length
  54. $mpc volume $1
  55. fi
  56. }
  57. function _ensure_volume_10 {
  58. if (( $($mpc volume | grep -o '...%' | tr -d '%') < 10 )); then
  59. mpd_set_volume 10
  60. fi
  61. }