|
def | __init__ (self, id_='') |
|
def | __str__ (self) |
|
def | __repr__ (self) |
|
def | params (self) |
|
def | handle (self) |
|
def | get_url (self, plugin_url='', kwargs) |
|
def | action (self, name=None) |
|
def | run (self) |
|
def | __init__ (self, id_='') |
|
def | __getattr__ (self, item) |
|
def | __str__ (self) |
|
def | __repr__ (self) |
|
def | addon (self) |
|
def | id (self) |
|
def | name (self) |
|
def | path (self) |
|
def | icon (self) |
|
def | fanart (self) |
|
def | config_dir (self) |
|
def | version (self) |
|
def | get_localized_string (self, id_) |
|
def | get_setting (self, id_, convert=True) |
|
def | set_setting (self, id_, value) |
|
def | log (self, message, level=xbmc.LOGDEBUG) |
|
def | log_notice (self, message) |
|
def | log_warning (self, message) |
|
def | log_info (self, message) |
|
def | log_error (self, message) |
|
def | log_debug (self, message) |
|
def | get_storage (self, filename='storage.pcl') |
|
def | get_mem_storage (self, storage_id='', window_id=10000) |
|
def | cached (self, duration=10) |
|
def | mem_cached (self, duration=10) |
|
def | gettext (self, ui_string) |
|
def | initialize_gettext (self) |
|
Plugin class
:param id_: plugin's id, e.g. 'plugin.video.foo' (optional)
:type id_: str
This class provides a simplified API to create virtual directories of playable items
for Kodi content plugins.
:class:`simpleplugin.Plugin` uses a concept of callable plugin actions (functions or methods)
that are defined using :meth:`Plugin.action` decorator.
A Plugin instance must have at least one action that is named ``'root'``.
Minimal example:
.. code-block:: python
from simpleplugin import Plugin
plugin = Plugin()
@plugin.action()
def root(): # Mandatory item!
return [{'label': 'Foo',
'url': plugin.get_url(action='some_action', label='Foo')},
{'label': 'Bar',
'url': plugin.get_url(action='some_action', label='Bar')}]
@plugin.action()
def some_action(params):
return [{'label': params.label]}]
plugin.run()
An action callable may receive 1 optional parameter which is
a dict-like object containing plugin call parameters (including action string)
The action callable can return
either a list/generator of dictionaries representing Kodi virtual directory items
or a resolved playable path (:class:`str` or :obj:`unicode`) for Kodi to play.
Example 1::
@plugin.action()
def list_action(params):
listing = get_listing(params) # Some external function to create listing
return listing
The ``listing`` variable is a Python list/generator of dict items.
Example 2::
@plugin.action()
def play_action(params):
path = get_path(params) # Some external function to get a playable path
return path
Each dict item can contain the following properties:
- label -- item's label (default: ``''``).
- label2 -- item's label2 (default: ``''``).
- thumb -- item's thumbnail (default: ``''``).
- icon -- item's icon (default: ``''``).
- path -- item's path (default: ``''``).
- fanart -- item's fanart (optional).
- art -- a dict containing all item's graphic (see :meth:`xbmcgui.ListItem.setArt` for more info) -- optional.
- stream_info -- a dictionary of ``{stream_type: {param: value}}`` items
(see :meth:`xbmcgui.ListItem.addStreamInfo`) -- optional.
- info -- a dictionary of ``{media: {param: value}}`` items
(see :meth:`xbmcgui.ListItem.setInfo`) -- optional
- context_menu - a list that contains 2-item tuples ``('Menu label', 'Action')``.
The items from the tuples are added to the item's context menu.
- url -- a callback URL for this list item.
- is_playable -- if ``True``, then this item is playable and must return a playable path or
be resolved via :meth:`Plugin.resolve_url` (default: ``False``).
- is_folder -- if ``True`` then the item will open a lower-level sub-listing. if ``False``,
the item either is a playable media or a general-purpose script
which neither creates a virtual folder nor points to a playable media (default: C{True}).
if ``'is_playable'`` is set to ``True``, then ``'is_folder'`` value automatically assumed to be ``False``.
- subtitles -- the list of paths to subtitle files (optional).
- mime -- item's mime type (optional).
- list_item -- an 'class:`xbmcgui.ListItem` instance (optional).
It is used when you want to set all list item properties by yourself.
If ``'list_item'`` property is present, all other properties,
except for ``'url'`` and ``'is_folder'``, are ignored.
- properties -- a dictionary of list item properties
(see :meth:`xbmcgui.ListItem.setProperty`) -- optional.
- cast -- a list of cast info (actors, roles, thumbnails) for the list item
(see :meth:`xbmcgui.ListItem.setCast`) -- optional.
- offscreen -- if ``True`` do not lock GUI (used for Python scrapers and subtitle plugins) --
optional.
- content_lookup -- if ``False``, do not HEAD requests to get mime type. Optional.
- online_db_ids -- a :class:`dict` of ``{'label': 'value'}`` pairs representing
the item's IDs in popular online databases. Possible labels: 'imdb', 'tvdb',
'tmdb', 'anidb', see :meth:`xbmcgui.ListItem.setUniqueIDs`. Optional.
- ratings -- a :class:`list` of :class:`dict`s with the following keys:
'type' (:class:`str`), 'rating' (:class:`float`),
'votes' (:class:`int`, optional), 'defaultt' (:class:`bool`, optional).
This list sets item's ratings in popular online databases.
Possible types: 'imdb', 'tvdb', tmdb', 'anidb'.
See :meth:`xbmcgui.ListItem.setRating`. Optional.
Example 3::
listing = [{ 'label': 'Label',
'label2': 'Label 2',
'thumb': 'thumb.png',
'icon': 'icon.png',
'fanart': 'fanart.jpg',
'art': {'clearart': 'clearart.png'},
'stream_info': {'video': {'codec': 'h264', 'duration': 1200},
'audio': {'codec': 'ac3', 'language': 'en'}},
'info': {'video': {'genre': 'Comedy', 'year': 2005}},
'context_menu': [('Menu Item', 'Action')],
'url': 'plugin:/plugin.video.test/?action=play',
'is_playable': True,
'is_folder': False,
'subtitles': ['/path/to/subtitles.en.srt', '/path/to/subtitles.uk.srt'],
'mime': 'video/mp4'
}]
Alternatively, an action callable can use :meth:`Plugin.create_listing` and :meth:`Plugin.resolve_url`
static methods to pass additional parameters to Kodi.
Example 4::
@plugin.action()
def list_action(params):
listing = get_listing(params) # Some external function to create listing
return Plugin.create_listing(listing, sort_methods=(2, 10, 17), view_mode=500)
Example 5::
@plugin.action()
def play_action(params):
path = get_path(params) # Some external function to get a playable path
return Plugin.resolve_url(path, succeeded=True)
If an action callable performs any actions other than creating a listing or
resolving a playable URL, it must return ``None``.