Access pictures in root of addon folder
#1
How does a python add-on get its root directory to access pictures and the like?

I have an add on folder: script.test.addon

In the root of that folder I want to access .png files from python files but I can't get the root directory.

P.S. I'm on a Mac inside of the XBMC .app folder.
Reply
#2
Never mind figured it out!

root = os.path.dirname(__file__)


I hope this works on windows too but it seems like it would.
Reply
#3
You can use the special protocol.

Code:
PLUGIN_ID = 'plugin.video.sample'
MEDIA_URL = 'special://home/addons/{0}/resources/media/'.format(PLUGIN_ID)
image = MEDIA_URL + "image.png" # image.png file is in ~/.xbmc/addons/plugin.video.sample/resources/media/image.png on Linux in this example.  Path will translate properly for other OSes

See http://wiki.xbmc.org/?title=Special_protocol for more information
Reply
#4
This thread is from 2013, pardon the resurrection.
-----


It comes up a lot on a Google search.
Instead of using the 'special://' protocol to get the path of the root folder of your plugin (it works anyway), there's a more direct way which is using xbmcaddon.Addon().getAddonInfo with 'path' as the property:
https://codedocs.xyz/xbmc/xbmc/group__py...3a8a4222fb

The folder it returns is already resolved (doesn't use the 'special://' protocol) and does not include the trailing slash, you need to add it, like:
python:
import os
import xbmcaddon

myFilePath = os.path.join(xbmcaddon.Addon().getAddonInfo('path'), 'myFile.xyz')
Or...
python:
from os import sep as osSeparator
import xbmcaddon

myFilePath = xbmcaddon.Addon().getAddonInfo('path') + osSeparator + 'myFile.xyz'

Note that getAddonInfo('profile') returns 'special://profile/addon_data/plugin.video.yourpluginname/' -- that is, it does include the trailing slash and uses 'special://'.
To resolve paths with the special protocol you need to use xbmc.translatePath(xbmcaddon.Addon().getAddonInfo('profile')).decode('utf-8').
Reply

Logout Mark Read Team Forum Stats Members Help
Access pictures in root of addon folder0