Wake.py - play TV channel

Hi,

Is it possible to insert into wake.py script any commands that after wake up vero close the standby menu, switch to TV and starts play TV channel number XY? I am using tvheadend and I would be grateful for any example where this or similar topic is solved.

Thx
L.

Hi,

This should be possible. Please see Switch programmatically to a pvr channel.

Sam

Maybe you are right, but for me it is hard. I tried to copy this source into my file and define class on first line like

Class Startme:

and call it this way with channel ID (even in quotes)

Startme.switchChannel(4e6ca943f08e86168d9c8ee3c17e0b9f)

it ends with an error (with quotes it ends with different error)

SyntaxError: invalid syntax

I tried it like

m = Startme()
m.switchChannel(4e6ca943f08e86168d9c8ee3c17e0b9f)

and no luck (even channel is in quotes). I do not even know if the channe UID is right but first I would like to solve errors about calling and defining and after that a channel.

But thx anyway

Without seeing the script, it’s impossible to even guess why it’s not working. The only thing I can tell you, the UUID must be in quotes.

Class Startme:
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
m = Startme()
m.switchChannel(4e6ca943f08e86168d9c8ee3c17e0b9f)

And Channel uid in quotes. So completelly ctrl+c and Ctrl+v from previous post with first line class definiton and at the end my try with calling it.

I fixed your formatting for you. If the way it looks now matches the actual file, then you have not properly indented the code. It should look like this:

Class Startme:
    def switchChannel(self, channel_uid):
        all_channels_loc = xbmc.getLocalizedString(19287).encode('utf-8')

OK, I am posting screenshots: 01 and 02 are almost the same (double qoutes vs single ones), but 03 error is the same (string, not dict).

If I save my file without quotes error is invalid syntax. thx

Did you read the error that you it gave you when you used quotes? The error clearly points to the line and what the issue is. You are supplying a dict to executeJSONRPC when it’s expecting a string.

Here is some reading for you on how to properly call executeJSONRPC: https://www.programcreek.com/python/example/79076/xbmc.executeJSONRPC

BTW: how do you format code? I can not find it out :frowning: On my wake.py all is ok formated. So bellow is some kind of “someting”.

Hi, thx, now I am little bit further :wink:

class Startme:
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:
#logging(‘error querying pvr addon: %s’ % Exception )
return None

m = Startme()
m.switchChannel(‘4e6ca943f08e86168d9c8ee3c17e0b9f’)

I must comment out log row (even here https://forum.kodi.tv/showthread.php?tid=343640 there is only log (not logging), but anyway it was not functional.

But now kodi find my file, no error at kodi.log but nothing happen like:

NOTICE: CApplication::ToggleStandby – checking for existence of /home/osmc/.kodi/userdata/wake.py
NOTICE: CApplication::ToggleStandby – script /home/osmc/.kodi/userdata/wake.py found
WARNING: CPythonInvoker(31): Script invoked without an addon. Adding all addon modules installed to python path as fallback. This behaviour will be removed in future version.

I think that it gets to that part of code with logging and return None so nothing happen