Skip to content

Instantly share code, notes, and snippets.

@h2oota
Created December 25, 2016 10:19
Show Gist options
  • Save h2oota/5fd74eddfd515a6f23dc5d14bc2731eb to your computer and use it in GitHub Desktop.
Save h2oota/5fd74eddfd515a6f23dc5d14bc2731eb to your computer and use it in GitHub Desktop.
mpdのプレイリストを再生します。 irexecから実行するために作りました。
#!/bin/sh
case $1 in
!!!\ locked\ !!!)
shift
;;
*)
case $1 in
[-+] | forward | backward | [1-9] | [1-9][0-9])
;;
*)
exec 1>&2
cat <<EOF
Usage: ${0##*/} + | - | forward | backward | NUM
+ or forward : next playlist
- or backward : prev playlist
NUM : playlist number
EOF
exit 1
;;
esac
exec flock "/tmp/!!! ${0##*/}.lock" $0 '!!! locked !!!' "$@"
;;
esac
mpd()
{
echo "$@" |nc localhost 6600 2>/dev/null
}
rev()
{
local a
a=$1
shift
[ $# -gt 0 ] && rev "$@"
echo $a
}
play_playlist()
{
mpc stop >/dev/null 2>&1
mpc clear >/dev/null 2>&1
mpc load $1
mpc play >/dev/null 2>&1
}
get_playlists()
{
mpd listplaylists |sed -e '/playlist:/!d' -e 's/playlist: *//'
}
current=$(mpd playlistinfo|grep file: | md5sum)
case $1 in
[1-9] | 1[0-2])
set -- $1 $(get_playlists)
shift $1
[ -n "$1" ] && play_playlist $1
exit
;;
+ | forward)
set -- $(get_playlists)
;;
- | backward)
set -- $(rev $(get_playlists))
;;
esac
found=no
for pl in "$@"; do
case ${found} in
yes)
set -- $pl
break
;;
esac
if [ "$(mpd listplaylist "$pl" |grep file:| md5sum)" = "${current}" ]; then
found=yes
fi
done
play_playlist $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment