aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2023-03-06 00:01:33 -0800
committerGravatar Tom Willemse2023-03-06 00:01:33 -0800
commit66547ca1139d28855917382c868ddf2723d5afd4 (patch)
treeed752e446ab886e7b3480c9ea1fd55bdade195a1
downloadmpd-notify-master.tar.gz
mpd-notify-master.zip
Initial commitHEADmaster
-rw-r--r--README.org26
-rwxr-xr-xmpd-notify25
2 files changed, 51 insertions, 0 deletions
diff --git a/README.org b/README.org
new file mode 100644
index 0000000..bc8a7b7
--- /dev/null
+++ b/README.org
@@ -0,0 +1,26 @@
+#+title: MPD Notify
+
+A simple script that listens to an =mpc idleloop= and sends a notification whenever the playing state of MPD changes. This tries to show the album art along with the notification as long as there is one of these files present in the album's directory:
+
+- =cover.jpg=
+- =cover.jpeg=
+- =cover.png=
+- =folder.jpg=
+- =folder.jpeg=
+- =folder.png=
+
+* Requirements
+
+This script needs [[https://musicpd.org/clients/mpc/][mpc]], [[https://gitlab.gnome.org/GNOME/libnotify][libnotify]] and [[https://www.zsh.org/][zsh]].
+
+* Installation
+
+Put the =mpd-notify= script anywhere in your =$PATH=.
+
+* Usage
+
+Run the =mpd-notify= script without arguments. This script assumes that your MPD music directory is =$HOME/music= and any file path it gets from MPD will be relative to that.
+
+Since this is meant to keep running in the background, you probably want it to do so by calling it as:
+
+: mpd-notify &
diff --git a/mpd-notify b/mpd-notify
new file mode 100755
index 0000000..b51184b
--- /dev/null
+++ b/mpd-notify
@@ -0,0 +1,25 @@
+#!/usr/bin/env zsh
+mpc idleloop player | while read _
+do
+ song=$(mpc current)
+ state=$(mpc status %state%)
+ directory="$HOME/music/$(dirname "$(mpc --format "%file%" current)")"
+ icon=""
+ message="$state"
+ if [[ -e "$directory/cover.jpg" ]]; then icon="$directory/cover.jpg";
+ elif [[ -e "$directory/cover.jpeg" ]]; then icon="$directory/cover.jpeg";
+ elif [[ -e "$directory/cover.png" ]]; then icon="$directory/cover.png";
+ elif [[ -e "$directory/folder.jpg" ]]; then icon="$directory/folder.jpg";
+ elif [[ -e "$directory/folder.jpeg" ]]; then icon="$directory/folder.jpeg";
+ elif [[ -e "$directory/folder.png" ]]; then icon="$directory/folder.png";
+ fi
+ case "$state" in
+ paused )
+ message="Paused ..."
+ ;;
+ playing )
+ message="Now playing ..."
+ ;;
+ esac
+ notify-send --icon "$icon" "$song" "$message"
+done