Skip to content

Instantly share code, notes, and snippets.

@dataolle
Created December 4, 2012 18:50
Show Gist options
  • Save dataolle/4207390 to your computer and use it in GitHub Desktop.
Save dataolle/4207390 to your computer and use it in GitHub Desktop.
send url to xbmc's json-rpc service for playback on the big screen
#!/bin/bash
#set url and port to the xbmc box webservice
XBMC_HOST="http://127.0.0.1:8080"
if [ "$1" = "" ]; then
echo -n "Insert URL: "
read url
else
url="$1"
fi
if [[ "$url" == *youtube.com* ]]
then
vid=$( echo "$url" | tr '?&#' '\n\n' | grep -e '^v=' | cut -d'=' -f2 )
payload='{"jsonrpc": "2.0", "method": "Player.Open", "params":{"item": {"file" : "plugin://plugin.video.youtube/?action=play_video&videoid='$vid'" }}, "id" : "1"}'
elif [[ "$url" == *vimeo.com* ]]
then
vid=$( echo "$url" | awk -F"/" '{print ($(NF))}' )
payload='{"jsonrpc": "2.0", "method": "Player.Open", "params":{"item": {"file" : "plugin://plugin.video.vimeo/?action=play_video&videoid='$vid'" }}, "id": "1" }'
else
payload='{ "jsonrpc": "2.0", "method": "Player.Open", "params": { "item": { "file": "'${url}'" }}, "id": 1 }'
fi
curl -v -u xbmc:password -d "$payload" -H "Content-type:application/json" -X POST "${XBMC_HOST}/jsonrpc"
@aviwad
Copy link

aviwad commented Dec 10, 2017

Is there any way, we can, say, in one command, search for a youtube video and automatically play the first result? I wanna incorporate this in my Raspberry Pi with voice commands, that's why! thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment