Switch programmatically to a pvr channel
#1
Hi,

is there any way to switch to a dedicated channel (with available channel id) from an addon via python? I've searched but did not find a way to do this instantly.

My current workaround uses xmbc.executebuiltin( Action(Number<x>) ) for every digit of the channel number to simulate the appropriate remote number keys. This works when i close my window and wait till the WindowClose animation is done before i trigger the actions. But this is not my favorite solution...

So is there any way to do this directly? Via a dedicated player URL may be?

Any help apprechiated...cheers Louis
Reply
#2
If you know the channel uid and the pvr plugin name then you cause play the url of the pvr TV channel directly from python

'pvr://channels/tv/All channels/' + addon + '_ ' + uid + '.pvr'

There is similar logic for radio pvr url's

Martin
Reply
#3
Hi Martin,

thanks a lot for your reply. I already thought about this approach, but it seemed not "generic" enough for me...

I can use the channel UID (when querying PVR.GetChannelDetails in broadcastnow and broadcastnext the channel UID is included), so i'll give that a try, but may be you can answer my open questions in preface:

- the "All Channels" part is translated (in my german setup, it is "Alle Kanäle"). Is that necessary or is "All channels" fine for every language?
- for pvr addon name could i use the PVR.BackendName Infolabel? Is it possible to use more than one PVR backend? Then this approach could fail...

Cheers Louis
Reply
#4
Ok, checked it now....this code (inside the appropriate class) works fine for me:

Code:

    def switchChannel(self, channel_uid):
        all_channels_loc = xbmc.getLocalizedString(19287).encode('utf-8')
        pvr_backend = self.pvrBackendAddonId()
        if not pvr_backend: return
        pvr_url = 'pvr://channels/tv/' + all_channels_loc + '/' + pvr_backend + '_' + str(channel_uid) + '.pvr'
        action = 'PlayMedia(' + pvr_url + ')'
        xbmc.executebuiltin(action)

    def pvrBackendAddonId(self):
        query_addons = xbmc.executeJSONRPC( { "jsonrpc": "2.0", "id": 1, "method": "Addons.GetAddons", "params": {"type": "xbmc.pvrclient"} } )
        try:
            addons = query_addons['result']['addons']
            return addons[0]['addonid'].encode('utf-8')
        except Exception:
            log('error querying pvr addon: %s' % Exception )
            return None

I always take the first available pvr client. If there are more than one...hm. Any way to get the pvr backend for a channel uid more reliable? Huh Any other remarks?

Cheers Louis
Reply
#5
The uid is only unique within the addon so not sure you can can do any reliable lookups solely on it if you  must support multiple addons.  Also as noted earler this URL will fail for pvr radio.

Martin
Reply

Logout Mark Read Team Forum Stats Members Help
Switch programmatically to a pvr channel0