Add mpc-stop-after-n-songs.sh.
authorW. Trevor King <wking@drexel.edu>
Mon, 19 Dec 2011 17:26:28 +0000 (12:26 -0500)
committerW. Trevor King <wking@drexel.edu>
Mon, 19 Dec 2011 17:26:28 +0000 (12:26 -0500)
posts/MPD.mdwn
posts/MPD/mpc-stop-after-n-songs.sh [new file with mode: 0755]

index 625c5074f9ca467d660e7d58ff6d77a08260096a..fef8135114481fac79fada66c089e4139e710722 100644 (file)
@@ -3,6 +3,7 @@ to use, but there are always tricks to make things a bit more
 comfortable.
 
 * Calculating [[MPD playlist duration]].
+* Stopping MPD after *N* songs with [[mpc-stop-after-n-songs.sh]].
 * Group-writable playlists with [[ACL]].
 * [[Replay gain]].
 
diff --git a/posts/MPD/mpc-stop-after-n-songs.sh b/posts/MPD/mpc-stop-after-n-songs.sh
new file mode 100755 (executable)
index 0000000..9e7467c
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+LAST_SONG=$(mpc current)
+REMAINING="${1:-1}"
+
+echo "${REMAINING} ${LAST_SONG}"
+while [ "${REMAINING}" -gt 0 ]; do
+       SONG=$(mpc current --wait)
+       if [ "${SONG}" != "${LAST_SONG}" ]; then
+               let "REMAINING -= 1"
+               LAST_SONG="${SONG}"
+               echo "${REMAINING} ${LAST_SONG}"
+       fi
+done
+
+mpc stop