-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
json output? #17
Comments
I would. Could you elaborate on what output you'd like to generate with a |
i'm thinking it would be beneficial to hook into my shell's prompt and i can mix and match with |
you can do |
hi @kirtan-shah I ran into this issue myself.
For my needs, JSON would be better so I can parse individual fields and build a string using I'd like to get JSON output from the tool so I can pull all of the necessary information from I'm using #!/bin/bash
raw=$(nowplaying-cli get-raw)
key_prefix="kMRMediaRemoteNowPlayingInfo"
json=$(
sed 's/ =/:/' <(echo "${raw}") | # replace all ` =` with `:`
sed 's/;/,/' | # replace all `;` with `,`
sed -r 's/\\[A-Za-z0-9]+ //' | # replace any UNICODE escape sequences (`\U25ba`) with ``
sed -r "s/(${key_prefix}[A-Za-z]+)/\"\1\"/" | # wrap all keys in quotes
sed -r "s/(\"${key_prefix}UniqueIdentifier\": .+),/\1/" # guess the last key and replace the `,` with ``
)
echo "${json}" | jq . It's not perfect and there are some keys that I need to remove completely in order to properly encode this into JSON. Also this solution messes up whenever there are UNICODE escape characters. |
I also have another way to pull sections of the See the updated gist here: https://gist.github.com/rogeruiz/817a92a4919db531baf1c184f842516b declare -A info=(
[artist]=''
[title]=''
[album]=''
[isMusicApp]=''
)
count=0
nowplaying-cli get artist title album isMusicApp | {
while read -r line; do
case ${count} in
0) info[artist]+=" $line" ;;
1) info[title]+=" $line" ;;
2) info[album]+=" $line" ;;
3) info[isMusicApp]+=" $line" ;;
*) ;;
esac
count=$((count + 1))
done
# declare -n info
echo "artist: ${info[artist]}"
echo "title: ${info[title]}"
echo "album: ${info[album]}"
echo "isMusicApp: ${info[isMusicApp]}"
} |
Would you consider adding a JSON output to allow tools like
jq
to parse this?The text was updated successfully, but these errors were encountered: