From f29851f71ab23170182a84c06b04ee49fa59caf1 Mon Sep 17 00:00:00 2001 From: Mat Mrosko Date: Wed, 4 Nov 2015 00:06:04 -0500 Subject: [PATCH] Use jq instead of sed voodoo to parse our data so it's more maintainable. --- .gitmodules | 3 +++ callbacks.sh | 6 +++--- fpp_install.sh | 8 ++++++++ jq | 1 + 4 files changed, 15 insertions(+), 3 deletions(-) create mode 160000 jq diff --git a/.gitmodules b/.gitmodules index fb51d2b..cc10030 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "vastfmt"] path = vastfmt url = https://github.com/Materdaddy/vastfmt.git +[submodule "jq"] + path = jq + url = https://github.com/stedolan/jq.git diff --git a/callbacks.sh b/callbacks.sh index 28dcc31..a7d04e0 100755 --- a/callbacks.sh +++ b/callbacks.sh @@ -106,9 +106,9 @@ case $operation in vast_args="$vast_args --rds" fi - # This voodoo turns our json into environment variables we - # can simply parse - eval $(echo $DATA | sed 's/^{//;s/}$//;s/,\s*/\n/g;s/"\([^"]*\)"\:\s*"\([^"]*\)"/\1="\2"/g') + # Use jq to parse our JSON data + artist=$(echo $DATA | ./jq/jq -r ".artist") + title=$(echo $DATA | ./jq/jq -r ".title") # Try to grab artist if Media exists. This assumes the filename # is "Artist - Title.extension" diff --git a/fpp_install.sh b/fpp_install.sh index 841711f..0bdc1c4 100755 --- a/fpp_install.sh +++ b/fpp_install.sh @@ -27,4 +27,12 @@ make -C vastfmt CXX=$CXX mkdir -p bin cp vastfmt/radio bin/rds +# Get jq going for parsing our json data +pushd jq +autoreconf -i +./configure --disable-maintainer-mode +make src/builtin.inc +make +popd + popd diff --git a/jq b/jq new file mode 160000 index 0000000..8f115e9 --- /dev/null +++ b/jq @@ -0,0 +1 @@ +Subproject commit 8f115e9eed8e71816b9f3a86e0d3aabd47a750d9