Last active
August 29, 2015 14:04
-
-
Save kmullin/7ae53890a4e91e592bc5 to your computer and use it in GitHub Desktop.
Shairport Metadata JSON generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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