_mpd_helper 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # variables
  2. mpc="/usr/bin/mpc -h $mpd_host"
  3. music="/music/"
  4. # functions
  5. function mpd_play_folder {
  6. tag = $1
  7. mkdir -p $music$tag
  8. # Update the directory timestamp to indicate the last tag seen
  9. # Touch the file alone will not update the directory timestamp,
  10. # so we'll need delete and re-create the file
  11. rm $music$tag/.lastplay
  12. touch $music$tag/.lastplay
  13. $mpc stop
  14. $mpc clear
  15. $mpc add $mpd_folder$tag
  16. _ensure_volume_10
  17. $mpc play
  18. }
  19. function mpd_play {
  20. $mpc stop
  21. $mpc clear
  22. $mpc add "$1"
  23. _ensure_volume_10
  24. $mpc play 1
  25. }
  26. function mpd_play_shuffle {
  27. $mpc stop
  28. $mpc clear
  29. $mpc add "$1"
  30. $mpc shuffle
  31. _ensure_volume_10
  32. $mpc play 1
  33. }
  34. function mpd_stop {
  35. $mpc stop
  36. }
  37. function mpd_pause_play {
  38. if ($mpc | grep -q playing); then # when playing
  39. $mpc pause
  40. else
  41. $mpc play
  42. fi
  43. }
  44. function vol_min {
  45. mpd_set_volume 5
  46. }
  47. function mpd_med {
  48. mpd_set_volume 50
  49. }
  50. function mpd_vol_max {
  51. mpd_set_volume 75
  52. }
  53. function mpd_set_volume {
  54. if [ -n "$1" ]; then # non-zero length
  55. $mpc volume $1
  56. fi
  57. }
  58. function _ensure_volume_10 {
  59. if (( $($mpc volume | grep -o '...%' | tr -d '%') < 10 )); then
  60. mpd_set_volume 10
  61. fi
  62. }