Advertisement
Guest User

Untitled

a guest
Oct 5th, 2015
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # A simple notify script for now-playing songs on mpd. This script uses
  4. # notify-send and mpc to get the current song information.
  5.  
  6. # Requirements (* = optional)
  7. # - mpd
  8. # - mpc
  9. # - notify-send (libnotify)
  10. # * ImageMagick (convert)
  11.  
  12. # Author : Wolfgang Mueller
  13. # You can use, edit and redistribute this script in any way you like.
  14. # (Just make sure not to hurt any kittens)
  15. #
  16. # Contributors:
  17. # https://github.com/graysky2/mpdnotify
  18.  
  19. # make sure env var is setup correctly
  20. [[ -z "$XDG_CONFIG_HOME" ]] && \
  21. XDG_CONFIG_HOME="$HOME/.config"
  22.  
  23. CFG_FILE="$XDG_CONFIG_HOME/mpdnotify.conf"
  24.  
  25. if [[ ! -f "$CFG_FILE" ]]; then
  26. echo " No config file found."
  27. echo " Create $XDG_CONFIG_HOME/mpdnotify.conf for this user."
  28. exit 1
  29. else
  30. . "$CFG_FILE"
  31. fi
  32.  
  33. #--------------------------------------------------------------------
  34.  
  35. escape() {
  36. echo "$1" | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g;'
  37. }
  38.  
  39. # determine file
  40. file="$(mpc current -f %file%)"
  41.  
  42. # check if anything is playing at all
  43. [[ -z $file ]] && exit 1
  44.  
  45. # Get title info
  46. title="$(mpc current -f "$A_FORMAT")"
  47.  
  48. # Get song info
  49. song="$(mpc current -f "$T_FORMAT")"
  50.  
  51. # Art directory
  52. art="$MUSIC_DIR/${file%/*}"
  53.  
  54. # find every file that matches IMG_REG set the first matching file to be the
  55. # cover.
  56. cover="$(find "$art/" -maxdepth 1 -type f | egrep -i -m1 "$IMG_REG")"
  57.  
  58. # when no cover is found, use DEFAULT_ART as cover
  59. cover="${cover:=$DEFAULT_ART}"
  60.  
  61. text="$(escape "$title\n$song")"
  62.  
  63. # check if art is available
  64. # --hint=int:transient:1 is needed, because gnome-shell will keep the notification in its bar.
  65. # using 'hint' they'll be removed automatically (gnome-shell 3.01)
  66. if [[ -n $cover ]]; then
  67.  
  68. if [[ -n $COVER_RESIZE ]]; then
  69. convert "$cover" -thumbnail $COVER_RESIZE -gravity center \
  70. -background "$COVER_BACKGROUND" -extent $COVER_RESIZE "$TEMP_PATH" >> "$LOGFILE" 2>&1
  71. cover="$TEMP_PATH"
  72. fi
  73.  
  74. notify-send -u $URGENCY -t 5000 --hint=int:transient:1 "$NOTIFY_TITLE" "$text" -i "$cover" >> "$LOGFILE" 2>&1
  75. else
  76. notify-send -u $URGENCY -t 5000 --hint=int:transient:1 "$NOTIFY_TITLE" "$text" >> "$LOGFILE" 2>&1
  77. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement