Skip to content

Instantly share code, notes, and snippets.

@kmullin
Last active August 29, 2015 14:04
Show Gist options
  • Save kmullin/7ae53890a4e91e592bc5 to your computer and use it in GitHub Desktop.
Save kmullin/7ae53890a4e91e592bc5 to your computer and use it in GitHub Desktop.
Shairport Metadata JSON generator
#!/bin/bash
pipe=/home/shairport/metadata/now_playing
datafile=$pipe.json
stringify() {
a=${1%%=*}
b=${1##*=}
echo "\"$a\": \"$b\""
}
exec 4< $pipe
while read -ru 4 line ; do
if [[ $line == artist* ]]; then
echo '{' > $datafile
elif [ -z "$line" ]; then
echo '}' >> $datafile
continue
fi
# jsonify the string
data=$(stringify "$line")
# for logging
echo $line
# pretty print the JSON
# comment is the last line of the output
if [[ $line == comment* ]]; then
echo " $data" >> $datafile
else
echo " $data," >> $datafile
fi
done
exec 4<&-
echo Exiting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment