From a869ac4a30f5f19b00e2eab9c4d99150a0c4b49b Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 16 Jan 2017 22:29:24 -0500 Subject: [PATCH] shell/mpd (notify-song.sh): add ratings; fix artist-only message; more reliable on macos --- shell/mpd/bin/notify-song.sh | 38 +++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/shell/mpd/bin/notify-song.sh b/shell/mpd/bin/notify-song.sh index 405686ef..7cb7e461 100755 --- a/shell/mpd/bin/notify-song.sh +++ b/shell/mpd/bin/notify-song.sh @@ -5,7 +5,7 @@ if ! pgrep mpd >/dev/null; then exit 1 fi -info=$(mpc -f ";%artist%;%album%;%title%") +info=$(mpc -f ";%artist%;%album%;%title%;%file%") if [[ -z $info || ${info:0:1} != ";" ]]; then >&2 echo "nothing is playing." exit @@ -14,16 +14,44 @@ fi artist=$(awk -F';' '{ print $2 }' <<<"$info") album=$(awk -F';' '{ print $3 }' <<<"$info") title=$(awk -F';' '{ print $4 }' <<<"$info") +file=$(awk -F';' '{ print $5 }' <<<"$info") artist="${artist:-No Artist}" -album="${artist:-No Album}" -title="${artist:-Untitled}" +album="${album:-No Album}" +title="${title:-Untitled}" +rating= + +stars=$(cd ~/music/.db/playlists/ && grep "$file" ./*-star.m3u) +if [[ $stars ]]; then + case $stars in + ./1-star.m3u*) starn=1 ;; + ./2-star.m3u*) starn=2 ;; + ./3-star.m3u*) starn=3 ;; + ./4-star.m3u*) starn=4 ;; + ./5-star.m3u*) starn=5 ;; + esac + + if [[ $starn ]]; then + star_filled_icon="★" + star_empty_icon="☆" + + for ((i=1;i<=5;i++)); do + if (( "$starn" >= "$i" )); then + rating="${rating}${star_filled_icon}" + else + rating="${rating}${star_empty_icon}" + fi + done + fi +fi case $OSTYPE in darwin*) - terminal-notifier -title "$title" -message "by $artist :: $album" -appIcon "/Applications/iTunes.app/Contents/Resources/iTunes.icns" + rating="[$rating] " + killall terminal-notifier + terminal-notifier -title "$rating$title" -message "by $artist :: $album" -appIcon "/Applications/iTunes.app/Contents/Resources/iTunes.icns" ;; linux*) - notify-send --icon="media-playback-start" --app-name="ncmpcpp" "$title" "${artist}\n${album}" + notify-send --icon="media-playback-start" --app-name="ncmpcpp" "$title" "${artist}\n${album}\n$rating" ;; esac