autostart tv

  • Hi folks,

    I'd like to autostart a specific tv program automatically when libreelec starts. By chance I stumbled over the autoexec.py scripting facility, which seems to be well suited for doing this.

    But as I'm not a real programmer I'm not able to write such a script. Maybe one of you folks already has such a script or can help me to write it ?

    Or is there another way to autostart a specific tv program ?

    Thanks in advance :)

  • You can retrieve the channel list with command

    Code
    curl -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0", "method": "PVR.GetChannels", "params": {"channelgroupid": "alltv", "properties" :["uniqueid"]},"id": 1}' http://127.0.0.1:8080/jsonrpc

    look for channel id and then use autoexec.py something like

    Code
    import xbmc
    import xbmcgui
    import xbmcaddon
    import json
    import time
    # sleep few seconds
    time.sleep(5)
    # play a channel 149
    jsonCmd = '{"jsonrpc":"2.0","id":1,"method":"Player.Open","params":{"item":{"channelid":149}}}'
    jsonRv = xbmc.executeJSONRPC(jsonCmd)


    I think last channel can be played automatically (set somewhere in pvr settings).

  • thanks a lot

    The first one works when I change the port to 80, there is nothing listening on port 8080:

    Code
    tcp        0      0 0.0.0.0:1524            0.0.0.0:*               LISTEN
    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
    tcp        0      0 0.0.0.0:9981            0.0.0.0:*               LISTEN
    tcp        0      0 0.0.0.0:9982            0.0.0.0:*               LISTEN
    tcp        0      0 0.0.0.0:4713            0.0.0.0:*               LISTEN
    tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN

    I have seen that the channelid I want to use is 1088.

    The python script throws an error:

    Code
    11:31:58.090 T:1612706720   ERROR: EXCEPTION Thrown (PythonToCppException) : -->
    Python callback/script returned the following error<--
    - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
    Error Type: <type 'exceptions.Syntax Error'>
    Error Contents: ('invalid syntax', ('/storage/.kodi/userdata/autoexec.py', 12, 132, 'jsonCmd = \'Content-Type: application/json\' -d \'{"jsonrpc":"2.0","id":1,"method":"Player.Open","params":{"item":{"channelid":1088}}}\'\n'))
    SyntaxError: ('invalid syntax', ('/storage/.kodi/userdata/autoexec.py', 12, 132, 'jsonCmd = \'Content-Type: application/json\' -d \'{"jsonrpc":"2.0","id":1,"method":"Player.Open","params":{"item":{"channelid":1088}}}\'\n'))
    -->End of Python script error report<--


    I see that it is a syntax error, but I can't identify it :(

    Or can it be caused that tvheadend is not running at the time the autoexec.py is executed ?

    Code
    11:31:55.445 T:1553986464   ERROR: AddOnLog: Tvheadend HTSP Client: pvr.hts - unable to connect to localhost:9982
  • ok, understand regarding the fixed code. My bad.

    Now nothing at all happens. It does not switch to the channel I like it to switch, and there are no messages in the kodi.log, at least no messages that seem to be related to the autoexec.py.

    How can I make a debug NOTICE in the autoexec.py ? Can this be done with printf ?

  • yeah, I've got the channelid, it was the first step I did.

    Code
    40818},{"channelid":1265,"label":"arte HD","uniqueid":1963091052},{"channelid":1088,"label":"3sat HD","uniqueid":1026189214},{"channelid":1004,"label":"tagesschau24 HD","uniqueid":640869133},{"channelid":1141,"label":"ZDFinfo HD","uniqueid"

    It is the {"channelid":1088,"label":"3sat HD","uniqueid":1026189214}, so channelid -> 1088

    Have activated the kodi debug log, a lot of info is generated. The last occurence of 'autoexec' in the log is as follows:

    Code
    19:24:36.149 T:139715384309504    INFO: CPythonInvoker(3, /home/gb/.kodi/userdata/autoexec.py): script successfully run
    19:24:36.149 T:139715384309504    INFO: Python script stopped
    19:24:36.149 T:139715384309504   DEBUG: Thread LanguageInvoker 139715384309504 terminating

    The other occurences of 'autoexec' also do not indicate errors, but it does not work.

    Edited once, last by gbi (December 22, 2017 at 6:57 PM).

  • well, I also have noticed/suspected this, that tvheadend starts later than autoexec.py is exec'd. I have even increased the time.sleep() to 30 or even 90 seconds, but no success, nothing happens

  • ok, I have injected an error at the end of the autoexec.py script, with a time.sleep(xx). Simply to get an error popup onscreen when the error occurs. Guess what, this popup comes immidiately, before the startup of tvheadend has happend, it does not matter if the time.sleep is 30 or 90 or whatsoever.

    Sigh :(

  • Hi all,

    just for the records: this solution does not work ! I'm sorry.

    The time.sleep() at line 7 has no effect, it does not delay further execution of autoexec.py.

    I'm too less a python specialist to track down why it does not work.

    Suggestions for doing an 'autostart tv' or to get the above script to work are welcome :)

    Thanks in advance.

  • Well, I'm not sure what you are doing but works perfectly fine for me. It is probably wrong approach but it works. Also sleep works as you can see:

  • Hi,

    now it works.

    I had 2 problems:

    1. the sleep time had to be at least around 30 seconds. Libreelec and tvheadend are running on a raspiv2

    2. strange enough it does not work with channelid 1088 (I have rechecked the output of curl, 1088 is listed), but it does work with another channelid I found in the list :

    Code
    {"channelid":1265,"label":"arte HD","uniqueid":1963091052}

    It also does not work when I run tvheadend on the raspi and stream it's output to my PC which also runs kodi.

    So this solution is may be the wrong approch (as you said) but at least it works

    Thanks a lot for your kind support :)

  • Script could be smarter to check if pvr is ready and nit hardcoded time.

    Maybe it is something wrong with required channel id? Does it switch to it with curl command?