sky.fm を聞くのが好きで、curl を使用してメディア情報をクエリします
私が今使っているのは:
curl -s curl http://127.0.0.1:8080/requests/status.json | grep now_playing
これは以下を返します:
"now_playing":"Cody Simpson - On My Mind"
私がしたいのは:
Cody Simpson - On My Mind
さらに良いのは、アーティストとタイトルを別々の変数に入れることです。
artist: Cody Simpson
title: On My mind
解決
#!/bin/bash
a=`curl -s http://127.0.0.1:8080/requests/status.json | grep -Po '(?<=now_playing":")[^"]+'`
artist=$(echo $a | awk -F' - ' '{print $1}')
title=$(echo $a | awk -F' - ' '{print $2}')
echo $artist
echo $title