I have experience with python, but I just got started learning how to develop addons for Kodi. Having a bit of trouble understanding the docs.
Is it possible to import or otherwise access python code from another plugin or script?
For example if my addon was: script.hello.world
and i wanted to use some_method
from plugin.video.someplugin
.
addon.xml imports the plugin i wish to access:
<requires>
<import addon="xbmc.python" version="2.14.0"/>
<import addon="plugin.video.plexbmc" version="3.4.5" optional="true"/>
</requires>
I was fairly sure this would not work, and i was correct:
from plugin.video.someplugin.default import some_method
The only thing in the docs that looked like it might work was this:
spi = xbmcaddon.Addon ('plugin.video.someplugin')
I can access the xbmc's built in methods of spi, but no way to get to the actual python objects.
Got it! Simply add the desired directory to the system's python path:
spi = xbmcaddon.Addon ('plugin.video.someplugin')
path = spi.getAddonInfo('path')
sys.path.append (xbmc.translatePath( os.path.join( path) ))
from default import some_method
some_method()