mpdconn

Pure Bash MPD Client

Simple shell functions intended to interact with Music Player Daemon via TCP-connection. Revision 2016-01-20.

mpdconn_20160120.tar.gz.

How-to (remark from mpd_conn file):

# 1. Include this file into your script:
#
#   source "$( dirname "$0" )/mpd_conn"
#
#
# 2. Estabilish a connection using open_mpd or open_mpd_or_die functions.
# The latter one will print occured error to stderr and end script.
#
#   open_mpd || { echo "$x_mpd_error"; exit }
#
# or
#
#   open_mpd_or_die
#
# Open functions take password, address and port from MPD_HOST and MPD_PORT,
# default localhost:6600, all as usual. If connection is already open,
# they do nothing and return success.
#
#
# 3. After your connection is open, invoke ask_mpd or ask_mpd_or_die with
# arbitrary MPD command as a parameter along with its arguments, if required.
# See http://www.musicpd.org/doc/protocol/ for command reference.
#
# Results are in following variables.

# In case of an error:
#
#   x_mpd_error - error message, if any. If open or ask functions return 0,
#                 this means request succeeded and x_mpd_error is unset.
#
# After successful call:
#
#   mpd_<name>[_<index>]
#               - response fields by their names (all lowercase, dashes
#                 in names replaced with underscores). If there are several
#                 groups of values in the response (search etc), the first group
#                 of values is assigned as follows: if env variable x_mpd_index0
#                 is unset, the first group goes to mpd_<name>, else it goes
#                 to mpd_<name>_0. Second and rest lines go to mpd_<name>_1,
#                 mpd_<name>_2 and so on. I don't use arrays since
#                 they cannot be exported.
#
#   x_mpd_tags  - space separated list of all mpd_<name>[_<index>] variables
#                 set within recent call in order of appearance.
#
#   x_mpd_tags_<index>
#               - space separated list of all mpd_<name>[_<index>] variables
#                 set within recent call in order of appearance, groupped
#                 by their index. Items of the first group enlisted in
#                 x_mpd_tags_0.
#
#   x_mpd_tag_index
#               - max assigned index to mpd_<name>_<index> or 0 for a single-
#                 group reply.
#
#   x_mpd_open  - set to non-empty string if connection to mpd is currently
#                 open, unset otherwise
#
# Mpdconn uses some other x_mpd_* variables, so avoid mangling with this
# namespace on your own.
#
#
# 4. After you're done, consider closing connection:
#
#   close_mpd
#
#
# 5. That's it.
#

A few example scripts included:

A bit more complex tools insluded as well.

mpdwatcher

Calls provided shell command on every change of MPD state or options.

dmenu/dmenu_mpd_search

Shows user a prompt via dmenu. Searches user input in an MPD database and displays the result. If more than one track is found, asks user to pick a track among the results. If a track already exists in current playlist, jumps to it. Else adds the track to the end of the playlist and then jumps to it. User can narrow search results by typing another string.

awesome35/mpd-now-playing-widget + skmpd.lua

mpd-now-playing-widget feeds specified AwesomeWM (v3.5+) widget module with actual MPD data as soon as it changes. All text formatting is also done in this script since I don't like lua.

skmpd.lua is an example of such module widget.


Mail me.