_mpd_helper 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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_stop {
  34. $mpc stop
  35. }
  36. function vol_min {
  37. mpd_set_volume 5
  38. }
  39. function mpd_med {
  40. mpd_set_volume 50
  41. }
  42. function mpd_vol_max {
  43. mpd_set_volume 75
  44. }
  45. function mpd_set_volume {
  46. if [ -n "$1" ]; then # non-zero length
  47. $mpc volume $value
  48. fi
  49. }
  50. function _ensure_volume_10 {
  51. if (( $($mpc volume | grep -o '...%' | tr -d '%') < 10 )); then
  52. mpd_set_volume 10
  53. fi
  54. }