album-notify 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env bash
  2. MUSIC_DIR=~/Music/ # Your music directory
  3. COVER=/tmp/cover.jpg
  4. function reset_background
  5. {
  6. printf "\e]20;;100x100+1000+1000\a"
  7. }
  8. {
  9. album="$(mpc --format %album% current -p 6600)"
  10. file="$(mpc --format %file% current -p 6600)"
  11. album_dir="${file%/*}"
  12. [[ -z "$album_dir" ]] && exit 1
  13. album_dir="$MUSIC_DIR/$album_dir"
  14. covers="$(find "$album_dir" -type d -exec find {} -maxdepth 1 -type f -iregex ".*/.*\(${album}\|cover\|folder\|artwork\|front\).*[.]\(jpe?g\|png\|gif\|bmp\)" \; )"
  15. src="$(echo -n "$covers" | head -n1)"
  16. rm -f "$COVER"
  17. # For Album Art
  18. if [[ -n "$src" ]] ; then
  19. # Resize the image's width to 300px
  20. convert "$src" -resize 300x "$COVER"
  21. if [[ -f "$COVER" ]] ; then
  22. # Scale down the cover to 62% of the original
  23. printf "\e]20;${COVER};65x65+87+00:op=keep-aspect\a"
  24. else
  25. reset_background
  26. fi
  27. else
  28. reset_background
  29. fi
  30. # For Notifications
  31. if [[ -n "$src" ]] ; then
  32. # Resize the image's width to 64px
  33. convert "$src" -resize 64x "$COVER"
  34. if [[ -f "$COVER" ]] ; then
  35. notify-send -u normal -i ${COVER} " Now Playing" "`mpc current`"
  36. fi
  37. fi
  38. } &