Change channel PVR from the terminal?

Hi,
How to start, stop, or change a channel PVR from the terminal ?

# play
curl -s -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":1,"method":"Player.Open","params":{"item":{"channelid":14}}}' http://127.0.0.1:8080/jsonrpc 

# stop
curl -s -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":1,"method":"Player.Stop", "params":{"playerid": 1}}' http://127.0.0.1:8080/jsonrpc 

# get all channelid
curl -s -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":1,"method":"PVR.GetChannels","params":{"channelgroupid":1}}' http://127.0.0.1:8080/jsonrpc

You need to allow Kodi for remote control in Settings/Services/Control.

1 Like

Thank you vpeter for the help.
My ugly script works.

#!/bin/bash

# JSON-RPC API of XBMC / Kodi
# Font 1: https://forum.kodi.tv/showthread.php?tid=183807
# Font 2: https://forum.kodi.tv/showthread.php?tid=183965
# Font 3: https://discourse.coreelec.org/t/change-channel-pvr-from-the-terminal/

# change this URL, acording to the box IP
boxUrl="http://boxip:8080"

# note: associative arrays are only avaible in bash version 4 (dont work in coreelec)
#boxtv_getChannelid_Test(){
#	declare -A channels
#	channels[rtp1]="305"
#
#	echo ${channels[$1]}
#	channelid=${channels[$1]}
#}

# we use a switch case for compatibility
boxtv_getChannelid(){
case $1 in
	'rtp1')
		channelid="305"
		;;
	'rtp2')
		channelid="465"
		;;
	'sic')
		channelid="467"
		;;
	'tvi')
		channelid="466"
		;;
	'btv')
		channelid="52"
		;;
	'sporting')
		channelid="59"
		;;
	'sporttv1')
		channelid="44"
		;;
	'sporttv2')
		channelid="148"
		;;
	'sporttv3')
		channelid="167"
		;;
	'sporttv4')
		channelid="231"
		;;
	'sporttv5')
		channelid="192"
		;;
	'eleven1')
		channelid="199"
		;;
	'eleven2')
		channelid="177"
		;;
	'eleven3')
		channelid="227"
		;;
	'eleven4')
		channelid="121"
		;;
	'eleven5')
		channelid="175"
		;;
	'eleven6')
		channelid="187"
		;;
	'eurosport1')
		channelid="109"
		;;
	'eurosport2')
		channelid="117"
		;;
	'pesca')
		channelid="301"
		;;
	'toros')
		channelid="530"
		;;
	'tvcine1')
		channelid="292"
		;;
	'tvcine2')
		channelid="80"
		;;
	'tvcine3')
		channelid="293"
		;;
	'bbc')
		channelid="427"
		;;
		*)
		channelid="466"
		;;
esac
}

boxtv(){
README="
# boxtv.play <channel_name>
#
# boxtv.play rtp1
# boxtv.play rtp2
# boxtv.play sic
# boxtv.play tvi
# boxtv.play btv
# boxtv.play sporting
# boxtv.play sporttv1
# boxtv.play sporttv2
# boxtv.play sporttv3
# boxtv.play sporttv4
# boxtv.play sporttv5
# boxtv.play eleven1
# boxtv.play eleven2
# boxtv.play eleven3
# boxtv.play eleven4
# boxtv.play eleven5
# boxtv.play eleven6
# boxtv.play eurosport1
# boxtv.play eurosport2
# boxtv.play pesca
# boxtv.play toros
# boxtv.play tvcine1
# boxtv.play tvcine2
# boxtv.play tvcine3
# boxtv.play bbc
"
echo "$README"
}

boxtv_play(){
if [ "$#" -eq 0 ]
then
	boxtv
else
	boxtv_getChannelid $1
	data='[{"jsonrpc":"2.0","method":"Player.Open","params":{"item":{"channelid":'$channelid'},"options":{}},"id":1}]'
	boxtv_httpPost
fi
}

boxtv_stop(){
	data='{"jsonrpc":"2.0","id":1,"method":"Player.Stop","params":{"playerid":1}}'
	boxtv_httpPost
}

boxtv_getAllChannelid(){
	data='{"jsonrpc":"2.0","id":1,"method":"PVR.GetChannels","params":{"channelgroupid":1}}'
	boxtv_httpPost
}

boxtv_httpPost(){
	echo $data
	curl -v -s \
	-H "Accept: application/json" -H "Content-type: application/json" \
	-X POST -d $data \
	$boxUrl'/jsonrpc'
}


# boxtv_play $1
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.