Skip to content

Instantly share code, notes, and snippets.

@vsefer
Last active August 16, 2020 04:11
Show Gist options
  • Save vsefer/091633c89d75441559579148b701d3f7 to your computer and use it in GitHub Desktop.
Save vsefer/091633c89d75441559579148b701d3f7 to your computer and use it in GitHub Desktop.
#!/bin/bash
# sudo apt-get install mpc jq curl wget
MPD_PORT=6600
HTTP_PORT=6680
RPC_HOST=http://localhost:$HTTP_PORT/mopidy/rpc
TRACK_ARTWORK=/tmp/cover-art-img
DEFAULT_ARTWORK=some-default-picture
while true
do
mpc -p $MPD_PORT -q || (echo "Connection Failed on port $MPD_PORT" && sleep 30 && continue)
if [ -n "$(mpc -p $MPD_PORT current)" ]
then
TRACK=$(curl -s -X POST -H Content-Type:application/json -d '{ "method": "core.playback.get_current_track", "jsonrpc": "2.0", "params": {}, "id": 1 }' $RPC_HOST)
TRACK_URI=$(echo $TRACK | jq -r '.result.uri')
IMAGES=$(curl -s -X POST -H Content-Type:application/json -d '{ "method": "core.library.get_images", "jsonrpc": "2.0", "params": { "uris": ["'"$TRACK_URI"'"] }, "id": 1}' $RPC_HOST)
IMAGE_URI=$(echo $IMAGES | jq -r 'first(.result[] | sort_by(.width) | reverse | .[].uri)')
if [ -n "$IMAGE_URI" ]
then
wget -O /home/pi/pidi/tmp-current.jpg $IMAGE_URI
mv /home/pi/pidi/tmp-current.jpg /home/pi/pidi/current.jpg
fi
fi
echo "Waiting for next player event"
mpc -p $MPD_PORT -q idle player
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment