This class provides a lot of code that is used across many XBMC addons in the hope that it will simplify some of the common tasks an addon needs to perform.
Mostly this is achieved by providing a wrapper around commonly used parts of xbmc, xbmcaddon, xbmcgui and xbmcplugin.
You probably want to have exactly one instance of this class in your addon which you can call from anywhere in your code.
Example:
import sys
from t0mm0.common.addon import Addon
addon = Addon('my.plugin.id', argv=sys.argv)
Convenience method to add a directory to the display list or a playlist.
See add_item() for full infomation
Adds an item to the list of entries to be displayed in XBMC or to a playlist.
Use this method when you want users to be able to select this item to start playback of a media file. queries is a dict that will be sent back to the addon when this item is selected:
add_item({'host': 'youtube.com', 'media_id': 'ABC123XYZ'},
{'title': 'A youtube vid'})
will add a link to:
plugin://your.plugin.id/?host=youtube.com&media_id=ABC123XYZ
See also
queries (dict): A set of keys/values to be sent to the addon when the user selects this item.
infolabels (dict): A dictionary of information about this media (see the XBMC Wiki InfoLabels entry).
img (str): A URL to an image file to be used as an icon for this entry.
fanart (str): A URL to a fanart image for this entry.
resolved (str): If not empty, queries will be ignored and instead the added item will be the exact contentes of resolved.
total_items (int): Total number of items to be added in this list. If supplied it enables XBMC to show a progress bar as the list of items is being built.
playlist (playlist object): If False (default), the item will be added to the list of entries to be displayed in this directory. If a playlist object is passed (see get_playlist()) then the item will be added to the playlist instead
item_type (str): The type of item to add (eg. ‘music’, ‘video’ or ‘pictures’)
Convenience method to add a music item to the directory list or a playlist.
See add_item() for full infomation
Convenience method to add a video item to the directory list or a playlist.
See add_item() for full infomation
Returns a plugin:// URL which can be used to call the addon with the specified queries.
Example:
>>> addon.build_plugin_url({'name': 'test', 'type': 'basic'})
'plugin://your.plugin.id/?name=test&type=basic'
Regular expression to convert entities such as , to the correct characters. It is called by unescape() and so it is not required to call it directly.
This method was found on the web
Returns the addon author as defined in addon.xml.
Convenience method to return a music xbmc.Playlist object.
See also
Return a xbmc.Playlist object of the specified type.
The available playlist types are defined in the xbmc module and are currently as follows:
xbmc.PLAYLIST_MUSIC = 0
xbmc.PLAYLIST_VIDEO = 1
See also
pl_type (int): The type of playlist to get.
new (bool): If False (default), get the current xbmc.Playlist object of the type specified. If True then return a new blank xbmc.Playlist.
Returns the full path to the addon profile directory (useful for storing files needed by the addon such as cookies).
Returns an addon setting. Settings must be defined in your addon’s resources/settings.xml file.
Returns a localized string. Strings must be defined in your addon’s resources/language/[lang_name]/strings.xml file.
Returns the addon summary as defined in addon.xml (eg. xbmc.python.pluginsource).
Convenience method to return a video xbmc.Playlist object.
See also
Load the data that was saved with save_data() and returns the data structure.
Writes a string to the XBMC log file. The addon name is inserted into the beginning of the message automatically to help you find relevent messages in the log file.
The available log levels are defined in the xbmc module and are currently as follows:
xbmc.LOGDEBUG = 0
xbmc.LOGERROR = 4
xbmc.LOGFATAL = 6
xbmc.LOGINFO = 1
xbmc.LOGNONE = 7
xbmc.LOGNOTICE = 2
xbmc.LOGSEVERE = 5
xbmc.LOGWARNING = 3
Convenience method to write to the XBMC log file at the xbmc.LOGDEBUG error level. Use this when you want to print out lots of detailed information that is only usefull for debugging. This will show up in the log only when debugging is enabled in the XBMC settings, and will be prefixed with ‘DEBUG:’.
Convenience method to write to the XBMC log file at the xbmc.LOGERROR error level. Use when something has gone wrong in your addon code. This will show up in the log prefixed with ‘ERROR:’ whether you have debugging switched on or not.
Convenience method to write to the XBMC log file at the xbmc.LOGNOTICE error level. Use for general log messages. This will show up in the log prefixed with ‘NOTICE:’ whether you have debugging switched on or not.
Parse a query string as used in a URL or passed to your addon by XBMC.
Example:
>>> addon.parse_query('name=test&type=basic')
{'mode': 'main', 'name': 'test', 'type': 'basic'}
Tell XBMC that you have resolved a URL (or not!).
This method should be called as follows:
Saves the data structure using pickle. If the addon data path does not exist it will be automatically created. This save function has the same restrictions as the pickle module.
filename (string): name of the file you want to save data to. This file will be saved in your addon’s profile directory.
data (data object/string): you want to save.
Convenience method to show an XBMC dialog box with a single OK button and also write the message to the log file at the ERROR log level.
The title of the dialog will be the addon’s name with the prefix ‘Error: ‘.
Warning
Don’t forget that msg must be a list of strings and not just a string even if you only want to display a single line!
Display an XBMC dialog with a message and a single ‘OK’ button. The message is also written to the XBMC log file at the appropriate log level.
Warning
Don’t forget that msg must be a list of strings and not just a string even if you only want to display a single line!
Example:
addon.show_ok_dialog(['My message'], 'My Addon')
title (str): String to be displayed as the title of the dialog box. Defaults to the addon name.
is_error (bool): If True, the log message will be written at the ERROR log level, otherwise NOTICE will be used.
Displays a small popup box in the lower right corner. The default delay is 5 seconds.
Code inspired by anarchintosh and daledude’s Icefilms addon.
Example:
import os
logo = os.path.join(addon.get_path(), 'art','logo.jpg')
addon.show_small_popup('MyAddonName','Is now loaded enjoy', 5000, logo)
title (str): title to be displayed at the top of the box
msg (str): Main message body
delay (int): delay in milliseconds until it disapears
image (str): Path to the image you want to display
Decodes HTML entities in a string.
You can add more entities to the rep dictionary.
Calls unescape() on all values in a dictionary.