Skip to content

Instantly share code, notes, and snippets.

@kingosticks
Last active November 9, 2020 14:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kingosticks/e15fe8f62d145d8187bf3b3abb486b31 to your computer and use it in GitHub Desktop.
Save kingosticks/e15fe8f62d145d8187bf3b3abb486b31 to your computer and use it in GitHub Desktop.
Mopidy cover artwork displayer
#!/bin/bash
# sudo apt-get install mpc jq fbi 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
function display_artwork() {
[ -f "$1" ] && fbi --vt 1 --noverbose --autozoom $1
}
do
display_artwork $DEFAULT_ARTWORK
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 $TRACK_ARTWORK $IMAGE_URI
display_artwork $TRACK_ARTWORK
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