Execute addon in background
#1
Hey all

I am making a small addon that will defines a couple of functions. All of these functions run in the background (most of them having to do with different library maintenance actions).

I would like to be able to run the functions in three different ways:
1: run the functions at startup
2: Browse the addon in Kodi, and execute different functions manually (as in, using xbmcgui.ListItem etc.)
3: Trigger specific functions externally using the JSON RPC method "Addons.ExecuteAddon" and certain parameters

I have been able to do 1 and 2 done this by identifying the addon as "xbmc.python.pluginsource" and "xbmc.service" in my addon.xml:
PHP Code:
<extension point="xbmc.python.pluginsource" library="default.py">
    <
provides>video</provides>
</
extension>
 <
extension point="xbmc.service" library="default.py" start="[login|startup]"> </extension

The problem I have run into, is that when I now trigger the addon using JSON RPC, it opens the window to choose between different functions, instead of just running the script in the background.

I am, honestly, a little confused about the different types of Kodi addons - script vs. service vs plugin source etc

I would be most grateful for any assistance in making an addon that does the three things I listed above,
Reply
#2
I may not be the most qualified person to answer this, but I've used multiple extension points to overcome a similar situation. I have the service call one python file, while the python script extension calls another (which opens a graphical interface).

I've not tried call via JSON to see what happens.

My addon.xml file is here: https://github.com/elParaguayo/service.b.../addon.xml
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#3
This is super helpful, thanks! Okay, so to see if I am understanding this correctly, line number 1 here allows you to draw a GUI, while line number 2 makes the script autostart on login?
PHP Code:
<extension point="xbmc.python.script" library="helper.py" />
<
extension point="xbmc.service" library="default.py" start="login"/> 
Reply
#4
Correct. The service extension (default.py) is a silent script that runs in the background. helper.py gives me a graphical interface and is called when I use "RunScript(service.bbclivefootballscores)".
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#5
Is this truly solved? Or is there something I'm missing?

pluginsource -> GUI
script -> Required for RunAddon
service -> Run at start

If I convert the pluginsource to script, then the script doesn't get passed sys.argv values and it fails. And if I add all 3 extension points, when I call RunAddon it prioritizes the plugin and draws the list items in the GUI. Though if I manually run the script from the Program Addons directory it works.

I guess my question is, how do I use RunAddon() but explicitly point to a source? RunScript() doesn't work because the Addon() info is not passed.

Here is my addon.xml:

Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.mycam"
       name="MyCam"
       version="1.0.0"
       provider-name="Maikito26">
  <requires>
    <import addon="xbmc.python" version="2.20.0"/>
    <import addon="script.module.requests" version="2.3.0" optional="false"/>
  </requires>
  <extension point="xbmc.python.script" library="allcameraplayer.py">
    <provides>executable</provides>
  </extension>
  <extension point="xbmc.python.pluginsource" library="navigation.py">
    <provides>video executable</provides>
  </extension>
  <extension point="xbmc.service" library="service.py" start="startup"/>


For clarity:
1. Both allcameraplayer and navigation show up as options in the Program Addons list
2. Both work as expected from Program Addons. Here is the debug logs for running allcameraplayer:

Code:
22:05:36 T:5360   DEBUG: CPythonInvoker(6, C:\Users\mjordan\AppData\Roaming\Kodi\addons\plugin.video.mycam\navigation.py): start processing
22:05:36 T:5360   DEBUG: CPythonInvoker(6, C:\Users\mjordan\AppData\Roaming\Kodi\addons\plugin.video.mycam\navigation.py): the source file to load is "C:\Users\mjordan\AppData\Roaming\Kodi\addons\plugin.video.mycam\navigation.py"
22:05:36 T:5360   DEBUG: CPythonInvoker(6, C:\Users\mjordan\AppData\Roaming\Kodi\addons\plugin.video.mycam\navigation.py): setting the Python path to C:\Users\mjordan\AppData\Roaming\Kodi\addons\plugin.video.mycam;C:\Users\mjordan\AppData\Roaming\Kodi\addons\script.module.requests\lib;C:\Program Files (x86)\Kodi\system\python\DLLs;C:\Program Files (x86)\Kodi\system\python\Lib;C:\Program Files (x86)\Kodi\python27.zip;C:\Program Files (x86)\Kodi\system\python\lib\plat-win;C:\Program Files (x86)\Kodi\system\python\lib\lib-tk;C:\Program Files (x86)\Kodi;C:\Program Files (x86)\Kodi\system\python;C:\Program Files (x86)\Kodi\system\python\lib\site-packages
22:05:36 T:5360   DEBUG: CPythonInvoker(6, C:\Users\mjordan\AppData\Roaming\Kodi\addons\plugin.video.mycam\navigation.py): entering source directory C:\Users\mjordan\AppData\Roaming\Kodi\addons\plugin.video.mycam

3. RunAddon('plugin.video.mycam') results in navigation.py being called
4. RunScript('path\allcameraplayer.py') results in the addon not being passed: xbmcaddon.Addon() throws an error.

Thanks in advanced!
Reply
#6
I had a look at the trakt plugin to see what it was doing (just looking through notable addons). It was setting the Addon() value as xbmcaddon.Addon('script.trakt'). This solved my RunScript() issue and I can use this going forward.
Reply

Logout Mark Read Team Forum Stats Members Help
Execute addon in background0