commit - 289051ee3ce04da6c07f5374fa5ba1c7606cf9d7
commit + bebbb737a532680e092afccedb7e91aaa37be124
blob - ac0ced07c00da77075897439b5c526f27a5071e9
blob + 5320d5c62c13ac98f61939a0fc9146e2d2606ed8
--- mpc-notify
+++ mpc-notify
#!/bin/sh -e
# Based on:
# https://wiki.archlinux.org/title/Ncmpcpp#With_album_art
-
-# Sends notification of currently playing MPD music with album cover art.
+#
+# mpc-notify: sends notification of currently playing MPD music accompanied
+# by album cover art.
+#
# Dependencies:
# mpc
# ffmpeg
# notify-send
# and my other script, notify-replace.
# recommended: a home directory setup with xdg-user-dirs (for finding your
-# music directory
-# For notification on song change:
-# Assign execute_on_song_change to this script in ncmpcpp's config file.
-# For notification on media keys:
-# Bind media key to a call to mpc with the approprite command.
+# music directory)
+#
+# For getting notifications on media keys:
+# Bind media key to calls to mpc-notify instead of mpc or other media
+# controllers.
+# For getting notifications on song change, add:
+# execute_on_song_change = "mpc-notify"
+# to your ncmpcpp's configuration file.
# exit early if we're in tty
if [ -z "$WAYLAND_DISPLAY" ] && [ -z "$DISPLAY" ]; then
"off")
song_head="Single Mode: Off";;
esac
+ # TODO: consider a more appropriate icon
song_icon="multimedia-player"
;;
"random")
"off")
song_head="Random Mode: Off";;
esac
+ # TODO: consider a more appropriate icon
song_icon="media-eject"
;;
"repeat")
*)
mpc -q "$command"
# don't notify if mpc changed song because ncmpcpp would notify on
- # song change anway
+ # song change anyway
[ "$command" = "next" ] || [ "$command" = "prev" ] && exit
;;
esac
# get preview filename
song_filename="$(mpc --format "${xdg_music_dir}/%file%" current)"
- song_album="$(mpc --format %album% current)"
- if [ -z "$song_album" ]; then
- # fallback to default for empty album name
+ song_album_name="$(mpc --format %album% current)"
+ if [ -z "$song_album_name" ]; then
+ # fallback to the default icon for an empty album name
song_icon="$default_song_icon"
else
- preview_path="${preview_dir}/$(echo "$song_album" | base64).png"
+ preview_path="${preview_dir}/$(echo "$song_album_name" | base64).png"
if [ -f "$preview_path" ]; then
# use cached preview
song_icon="$preview_path"
fi
unset preview_path
fi
-unset xdg_music_dir song_filename song_album
+unset xdg_music_dir song_filename song_album_name
-# send the actual notification
+# now send the actual notification
song_body="$(mpc --format '[%title%[ \n%artist% - %album%]]|[%file%]' current)"
notify-replace 'mpc-notify' "$song_head" "$song_body" -i "$song_icon" -u low