Commit a1948630 authored by Ronald van Engelen's avatar Ronald van Engelen

replaced funky netcat with bash builtin sockets as per https://superuser.com/a/1122119/955505

parent a7bdd9ca
......@@ -160,7 +160,6 @@ function check_commands() {
cmd_mpc=$(type -p mpc) || err+=("mpc")
cmd_soxi=$(type -p soxi) || err+=("soxi")
cmd_exiftool=$(type -p exiftool) || err+=("exiftool")
cmd_netcat=$(type -p nc) || err+=("netcat (nc)")
cmd_bc=$(type -p bc) || err+=("bc")
cmd_numfmt=$(type -p numfmt)
if [[ ${#err[@]} -gt 0 ]]; then
......@@ -516,43 +515,27 @@ function ret_formatted_time() {
"${hours}" "${minutes}" "${seconds}"
}
function get_nc_args() {
## echo status command to mpd host on mpd port using netcat, to
## fill mpc_vals array with rt_ fields
declare -a netcat_args
netcat_args=(--help)
debug "$(declare -p cmd_netcat mpd_host mpd_port)"
res=$(${cmd_netcat} "${netcat_args[@]}" 2>&1 >/dev/null)
# shellcheck disable=SC2181
if [[ $? -ne 0 ]]; then
netcat_args=(-N)
debug "using netcat \`${cmd_netcat} with short args (${netcat_args[*]})."
else
netcat_args=(--close)
debug "using netcat \`${cmd_netcat} with long args (${netcat_args[*]})."
fi
## return command
printf '%s' "${netcat_args[@]}"
}
function ret_mpd_now() {
## echo status command to mpd host on mpd port using netcat, to
## fill mpc_vals array with rt_ fields
## echo status command to mpd host on mpd port using bash builtin
## socket, to fill mpc_vals array with rt_ fields
prefix="rt_raw"
key_val_re="^([^\:]+):[[:space:]]+(.*)"
## store each line in an associative array, by splitting the mpc
## output lines (paramater:value)
# shellcheck disable=SC2207
netcat_args=($(get_nc_args))
debug "$(declare -p netcat_args)"
while read -r line; do
if [[ "${line}" =~ ${key_val_re} ]]; then
field="${BASH_REMATCH[1]}"
value="${BASH_REMATCH[2]}"
mpd_vals["${prefix}_${field}"]="${value}"
fi
done< <(${cmd_netcat} "${netcat_args[@]}" ${mpd_host} ${mpd_port} <<< 'status')
done< <(
exec 3<>/dev/tcp/${mpd_host}/${mpd_port}
printf "command_list_begin\nstatus\nclose\ncommand_list_end\n" >&3
cat <&3
exec 3<&-
exec 3<&-
)
debug "$(declare -p mpd_vals)"
## store the double colon separated values
## (samplerate:bitdepth:channelcount, eg. 48000:24:2) of the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment