From: W. Trevor King Date: Mon, 19 Dec 2011 17:26:28 +0000 (-0500) Subject: Add mpc-stop-after-n-songs.sh. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7910cbe38692b16c00cae866cd458d4a48c775a0;p=blog.git Add 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