From 7910cbe38692b16c00cae866cd458d4a48c775a0 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 19 Dec 2011 12:26:28 -0500 Subject: [PATCH] Add mpc-stop-after-n-songs.sh. --- posts/MPD.mdwn | 1 + posts/MPD/mpc-stop-after-n-songs.sh | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100755 posts/MPD/mpc-stop-after-n-songs.sh diff --git a/posts/MPD.mdwn b/posts/MPD.mdwn index 625c507..fef8135 100644 --- a/posts/MPD.mdwn +++ b/posts/MPD.mdwn @@ -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 index 0000000..9e7467c --- /dev/null +++ b/posts/MPD/mpc-stop-after-n-songs.sh @@ -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 -- 2.26.2