2016-12-25 16:08:06 -08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
if ! pgrep mpd >/dev/null; then
|
|
|
|
>&2 echo "mpd isn't running."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-01-16 19:29:24 -08:00
|
|
|
info=$(mpc -f ";%artist%;%album%;%title%;%file%")
|
2017-01-03 21:40:36 -08:00
|
|
|
if [[ -z $info || ${info:0:1} != ";" ]]; then
|
2016-12-25 16:08:06 -08:00
|
|
|
>&2 echo "nothing is playing."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2017-01-03 21:40:36 -08:00
|
|
|
artist=$(awk -F';' '{ print $2 }' <<<"$info")
|
|
|
|
album=$(awk -F';' '{ print $3 }' <<<"$info")
|
|
|
|
title=$(awk -F';' '{ print $4 }' <<<"$info")
|
2017-01-16 19:29:24 -08:00
|
|
|
file=$(awk -F';' '{ print $5 }' <<<"$info")
|
2017-01-03 21:40:36 -08:00
|
|
|
|
2017-01-08 21:41:55 -08:00
|
|
|
artist="${artist:-No Artist}"
|
2017-01-16 19:29:24 -08:00
|
|
|
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
|
2017-01-08 21:41:55 -08:00
|
|
|
|
2016-12-25 16:08:06 -08:00
|
|
|
case $OSTYPE in
|
|
|
|
darwin*)
|
2017-01-16 19:29:24 -08:00
|
|
|
rating="[$rating] "
|
|
|
|
killall terminal-notifier
|
|
|
|
terminal-notifier -title "$rating$title" -message "by $artist :: $album" -appIcon "/Applications/iTunes.app/Contents/Resources/iTunes.icns"
|
2016-12-25 16:08:06 -08:00
|
|
|
;;
|
|
|
|
linux*)
|
2017-01-16 19:29:24 -08:00
|
|
|
notify-send --icon="media-playback-start" --app-name="ncmpcpp" "$title" "${artist}\n<i>${album}</i>\n$rating"
|
2016-12-25 16:08:06 -08:00
|
|
|
;;
|
2017-01-16 19:29:31 -08:00
|
|
|
esac &
|