plugin.video.torrserve
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
site-packages.torrserve.simpleplugin.Plugin Class Reference
Inheritance diagram for site-packages.torrserve.simpleplugin.Plugin:
site-packages.torrserve.simpleplugin.Addon site-packages.torrserve.simpleplugin.RoutedPlugin

Public Member Functions

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)
 
- Public Member Functions inherited from site-packages.torrserve.simpleplugin.Addon
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)
 

Static Public Member Functions

def get_params (paramstring)
 
def create_listing (listing, succeeded=True, update_listing=False, cache_to_disk=False, sort_methods=None, view_mode=None, content=None, category=None)
 
def resolve_url (path='', play_item=None, succeeded=True)
 
def create_list_item (item)
 

Public Attributes

 actions
 

Detailed Description

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``.

Constructor & Destructor Documentation

§ __init__()

def site-packages.torrserve.simpleplugin.Plugin.__init__ (   self,
  id_ = '' 
)
Class constructor

:type id_: str

Member Function Documentation

§ action()

def site-packages.torrserve.simpleplugin.Plugin.action (   self,
  name = None 
)
Action decorator

Defines plugin callback action. If action's name is not defined explicitly,
then the action is named after the decorated function.

.. warning:: Action's name must be unique.

A plugin must have at least one action named ``'root'`` implicitly or explicitly.

Example:

.. code-block:: python

    @plugin.action()  # The action is implicitly named 'root' after the decorated function
    def root(params):
pass

    @plugin.action('foo')  # The action name is set explicitly
    def foo_action(params):
pass

:param name: action's name (optional).
:type name: str
:raises SimplePluginError: if the action with such name is already defined.

§ create_list_item()

def site-packages.torrserve.simpleplugin.Plugin.create_list_item (   item)
static
Create an :class:`xbmcgui.ListItem` instance from an item dict

:param item: a dict of ListItem properties
:type item: dict
:return: ListItem instance
:rtype: xbmcgui.ListItem

§ create_listing()

def site-packages.torrserve.simpleplugin.Plugin.create_listing (   listing,
  succeeded = True,
  update_listing = False,
  cache_to_disk = False,
  sort_methods = None,
  view_mode = None,
  content = None,
  category = None 
)
static
Create and return a context dict for a virtual folder listing

:param listing: the list of the plugin virtual folder items
:type listing: list or GeneratorType
:param succeeded: if ``False`` Kodi won't open a new listing and stays on the current level.
:type succeeded: bool
:param update_listing: if ``True``, Kodi won't open a sub-listing but refresh the current one.
:type update_listing: bool
:param cache_to_disk: cache this view to disk.
:type cache_to_disk: bool
:param sort_methods: the list of integer constants representing virtual folder sort methods.
:type sort_methods: tuple
:param view_mode: a numeric code for a skin view mode.
    View mode codes are different in different skins except for ``50`` (basic listing).
:type view_mode: int
:param content: string - current plugin content, e.g. 'movies' or 'episodes'.
    See :func:`xbmcplugin.setContent` for more info.
:type content: str
:param category: str - plugin sub-category, e.g. 'Comedy'.
    See :func:`xbmcplugin.setPluginCategory` for more info.
:type category: str
:return: context object containing necessary parameters
    to create virtual folder listing in Kodi UI.
:rtype: ListContext

§ get_params()

def site-packages.torrserve.simpleplugin.Plugin.get_params (   paramstring)
static
Convert a URL-encoded paramstring to a Python dict

:param paramstring: URL-encoded paramstring
:type paramstring: str
:return: parsed paramstring
:rtype: Params

§ get_url()

def site-packages.torrserve.simpleplugin.Plugin.get_url (   self,
  plugin_url = '',
  kwargs 
)
Construct a callable URL for a virtual directory item

If plugin_url is empty, a current plugin URL is used.
kwargs are converted to a URL-encoded string of plugin call parameters
To call a plugin action, 'action' parameter must be used,
if 'action' parameter is missing, then the plugin root action is called
If the action is not added to :class:`Plugin` actions, :class:`PluginError` will be raised.

:param plugin_url: plugin URL with trailing / (optional)
:type plugin_url: str
:param kwargs: pairs of key=value items
:return: a full plugin callback URL
:rtype: str

§ handle()

def site-packages.torrserve.simpleplugin.Plugin.handle (   self)
Get plugin handle

:return: plugin handle
:rtype: int

§ params()

def site-packages.torrserve.simpleplugin.Plugin.params (   self)
Get plugin call parameters

:return: plugin call parameters
:rtype: Params

§ resolve_url()

def site-packages.torrserve.simpleplugin.Plugin.resolve_url (   path = '',
  play_item = None,
  succeeded = True 
)
static
Create and return a context dict to resolve a playable URL

:param path: the path to a playable media.
:type path: str or unicode
:param play_item: a dict of item properties as described in the class docstring.
    It allows to set additional properties for the item being played, like graphics, metadata etc.
    if ``play_item`` parameter is present, then ``path`` value is ignored, and the path must be set via
    ``'path'`` property of a ``play_item`` dict.
:type play_item: dict
:param succeeded: if ``False``, Kodi won't play anything
:type succeeded: bool
:return: context object containing necessary parameters
    for Kodi to play the selected media.
:rtype: PlayContext

§ run()

def site-packages.torrserve.simpleplugin.Plugin.run (   self)
Run plugin

:raises SimplePluginError: if unknown action string is provided.

The documentation for this class was generated from the following file: