Kodi Community Forum

Full Version: TVH & Kodi internal channel index numbers
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All,

I have a problem with Kodi and TVH I hope someone can help out with. I have a TV Headend instance running on a Linux (Debian) PC, which has Kodi running on as a front end. The channels come from a DVB-S2 dual tuner card and a USB DVB-T2 stick. 

I have been playing with Alexa to add voice control to Kodi, and can switch channels with "Alexa, ask Kodi to play channel Sky News" (for example). Alexa looks up 'Sky News' in it's internal script, and calls a web server in my house with "sky news" and a code of "284". 
The number 284 relates to the unique internal index number Kodi has given the channel. My web server then sends a JSON request to Kodi to change the channel, based on the index number provided. This works perfectly. Please note, the number used here is Kodi (or the TVH plugin's) internal index number, not the channel number which I would use on a remote or in the EPG (Sky news is actually on channel 501 as far as users see). 284 is the internal index number Kodi or the TVH plugin seem to use, and Alexa works fine with it.

My issue came up when I added a second front end in the bedroom connected to the same TVH backend on the PC. I added Alexa control to that one, and Alexa requests Sky News on index 284 with my web server sending the JSON request to the bedroom PI frontend. 

It seems that although the secondary frontend is using the same backend as the original Kodi, the internal index numbers have changed. So calling channel 284 on the secondary frontend gives me BBC1, not Sky News! 

I can of course code around this, but I was hoping someone could give me a way to make the internal channel index numbers match on both Kodi/TVH plugin instances? I assume there is a database somewhere in Kodi or TVH that keeps the PVR channel index, so can I copy the master frontend version of that database onto the secondary frontend to match everything up? Kodi certainly doesn't seem to use the channel index numbers from the backend TVH, or both would already match. It's something generated in Kodi or the TVH plugin. 

Any advise would be greatly appreciated,
With Kindest Regards,
Ian
Wild stab in the dark: check on each Kodi frontend at Settings > PVR & Live TV > General (referenced here on Kodi's wiki) and ensure both Kodi installations have same settings for using frontend/backend channel numbers and channel order.  Perhaps one is set to use backend channel numbers and the other is not?

I guess I'm trying to understand where the number 284 is even coming from.  Perhaps also check/edit (in same settings screen) the Channel Manager so that channel numbers and order are consistent between the two Kodi installations.
I'm not sure that I know how/where those numbers come from, however I do know that I have a shell script that pulls them off each of my kodi instances and therefore starts the correct channel on any box.  It's a similar thing to what you are doing, only I'm typing it, not saying it.
Code:
result=$( curl -s --data-binary '{"jsonrpc": "2.0", "method": "PVR.GetChannelGroups", "params": {"channeltype" : "tv"}, "id": 1 }' -H 'content-type: application/json;' http://$xbmcAddress:$xbmcPort/jsonrpc)
groupid=$(echo $result | jq '.result.channelgroups | select(.label=="All channels") | .channelgroupid')

The above calls a kodi instance on $xbmcAddress with $xbmcPort and gets the group id for "all channels".
 
Code:
result=$( curl -s --data-binary '{"jsonrpc": "2.0", "method": "PVR.GetChannels", "params": {"channelgroupid" : '$groupid',"properties":["channel"]}, "id": 1 }' -H 'content-type: application/json;' http://$xbmcAddress:$xbmcPort/jsonrpc)

Use that group ID to get all the channels.
Code:
echo echo $result | jq '.result.channels.channel' | sed 's/"//g' > ~/scripts/channels.txt
channels=( `cat "~/scripts/channels.txt" `)

That gives you all the channel names (at this point I put them into a temporary file) and read it back into an array.
Code:
echo $result | jq '.result.channels.channelid' > ~/scripts/channelid.txt
    channelid=( `cat "~/scripts/channelid.txt" `)

Do the same thing with the channel ID's.  Then simply loop through the 'channels' array to find your channel and the corresponding channel ID is at the same index in the other array.

My script uses those arrays in dialog to produce a menu and it works consistently across four different kodi instances running on different hardware, so although I've never investigated whether or not the internal ID's are different across machines, it doesn't matter because they are matched against channel name.