喜欢听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