Script

This module is used for creating “Script” callback’s, which are also used as the base for all other types of callbacks.

codequick.run(process_errors=True, redirect=None)

The starting point of the add-on.

This function will handle the execution of the “callback” functions. The callback function that will be executed, will be auto selected.

The “root” callback, is the callback that will be the initial starting point for the add-on.

Parameters:process_errors (bool) – Enable/Disable internal error handler. (default => True)
Returns:Returns None if no errors were raised, or if errors were raised and process_errors is True (default) then the error Exception that was raised will be returned.

returns the error Exception if an error ocurred. :rtype: Exception or None

class codequick.script.Script[source]

This class is used to create “Script” callbacks. Script callbacks are callbacks that just execute code and return nothing.

This class is also used as the base for all other types of callbacks i.e. codequick.Route and codequick.Resolver.

handle = -1

The Kodi handle that this add-on was started with.

CRITICAL = 50

Critical logging level, maps to “xbmc.LOGFATAL”.

WARNING = 30

Critical logging level, maps to “xbmc.LOGWARNING”.

ERROR = 40

Critical logging level, maps to “xbmc.LOGERROR”.

DEBUG = 10

Critical logging level, maps to “xbmc.LOGDEBUG”.

INFO = 20

Critical logging level, maps to “xbmc.LOGINFO”.

NOTIFY_WARNING = 'warning'

Kodi notification warning image.

NOTIFY_ERROR = 'error'

Kodi notification error image.

NOTIFY_INFO = 'info'

Kodi notification info image.

setting = <codequick.script.Settings object>

Dictionary like interface of “add-on” settings. See script.Settings for more details.

logger = <Logger CodeQuick (DEBUG)>

Underlining logger object, for advanced use. See logging.Logger for more details.

params = {}

Dictionary of all callback parameters, for advanced use.

classmethod ref(path)[source]

When given a path to a callback function, will return a reference to that callback function.

This is used as a way to link to a callback without the need to import it first. With this only the required module containing the callback is imported when callback is executed. This can be used to improve performance when dealing with lots of different callback functions.

The path structure is ‘/<package>/<module>:function’ where ‘package’ is the full package path. ‘module’ is the name of the modules containing the callback. And ‘function’ is the name of the callback function.

Example:
>>> from codequick import Route, Resolver, Listitem
>>> item = Listitem()
>>>
>>> # Example of referencing a Route callback
>>> item.set_callback(Route.ref("/resources/lib/videos:video_list"))
>>>
>>> # Example of referencing a Resolver callback
>>> item.set_callback(Resolver.ref("/resources/lib/resolvers:play_video"))
Parameters:

path (str) – The path to a callback function.

Returns:

A callback reference object.

classmethod register(func=None, **kwargs)[source]

Decorator used to register callback functions.

Can be called with or without arguments. If arguments are given, they have to be “keyword only” arguments. The keyword arguments are parameters that are used by the plugin class instance. e.g. autosort=False to disable auto sorting for Route callbacks

Example:
>>> from codequick import Route, Listitem
>>>
>>> @Route.register
>>> def root(_):
>>>     yield Listitem.from_dict("Extra videos", subfolder)
>>>
>>> @Route.register(cache_ttl=240, autosort=False, content_type="videos")
>>> def subfolder(_):
>>>     yield Listitem.from_dict("Play video", "http://www.example.com/video1.mkv")
Parameters:
  • func (function) – The callback function to register.
  • kwargs – Keyword only arguments to pass to callback handler.
Returns:

A callback instance.

Return type:

Callback

static register_delayed(func, *args, **kwargs)[source]

Registers a function that will be executed after Kodi has finished listing all “listitems”. Since this function is called after the listitems has been shown, it will not slow down the listing of content. This is very useful for fetching extra metadata for later use.

Note

Functions will be called in reverse order to the order they are added (LIFO).

Parameters:
  • func – Function that will be called after “xbmcplugin.endOfDirectory” is called.
  • args – “Positional” arguments that will be passed to function.
  • kwargs – “Keyword” arguments that will be passed to function.

Note

There is one optional keyword only argument function_type. Values are as follows. * 0 Only run if no errors are raised. (Default) * 1 Only run if an error has occurred. * 2 Run regardless if an error was raised or not.

Note

If there is an argument called exception in the delayed function callback and an error was raised, then that exception argument will be set to the raised exception object. Otherwise it will be set to None.

static log(msg, args=None, lvl=10)[source]

Logs a message with logging level of “lvl”.

Logging Levels.
Parameters:
  • msg (str) – The message format string.
  • args (list or tuple) – List of arguments which are merged into msg using the string formatting operator.
  • lvl (int) – The logging level to use. default => 10 (Debug).

Note

When a log level of 50(CRITICAL) is given, all debug messages that were previously logged will now be logged as level 30(WARNING). This allows for debug messages to show in the normal Kodi log file when a CRITICAL error has occurred, without having to enable Kodi’s debug mode.

static notify(heading, message, icon=None, display_time=5000, sound=True)[source]

Send a notification to Kodi.

Options for icon are.
Parameters:
  • heading (str) – Dialog heading label.
  • message (str) – Dialog message label.
  • icon (str) – [opt] Icon image to use. (default => ‘add-on icon image’)
  • display_time (int) – [opt] Ttime in “milliseconds” to show dialog. (default => 5000)
  • sound (bool) – [opt] Whether or not to play notification sound. (default => True)
static localize(string_id)[source]

Returns a translated UI string from addon localization files.

Note

utils.string_map needs to be populated before you can pass in a string as the reference.

Parameters:

string_id (str or int) – The numeric ID or gettext string ID of the localized string

Returns:

Localized unicode string.

Return type:

str

Raises:

Keyword – if a gettext string ID was given but the string is not found in English strings.po.

Example:
>>> Script.localize(30001)
"Toutes les vidéos"
>>> Script.localize("All Videos")
"Toutes les vidéos"
static get_info(key, addon_id=None)[source]

Returns the value of an add-on property as a unicode string.

Properties.
  • author
  • changelog
  • description
  • disclaimer
  • fanart
  • icon
  • id
  • name
  • path
  • profile
  • stars
  • summary
  • type
  • version
Parameters:
  • key (str) – “Name” of the property to access.
  • addon_id (str) – [opt] ID of another add-on to extract properties from.
Returns:

Add-on property as a unicode string.

Return type:

str

Raises:

RuntimeError – If add-on ID is given and there is no add-on with given ID.

class codequick.script.Settings[source]

Settings class to handle the getting and setting of “add-on” settings.

__getitem__(key)[source]

Returns the value of a setting as a “unicode string”.

Parameters:key (str) – ID of the setting to access.
Returns:Setting as a “unicode string”.
Return type:str
__setitem__(key, value)[source]

Set add-on setting.

Parameters:
  • key (str) – ID of the setting.
  • value (str) – Value of the setting.
static get_string(key, addon_id=None)[source]

Returns the value of a setting as a “unicode string”.

Parameters:
  • key (str) – ID of the setting to access.
  • addon_id (str) – [opt] ID of another add-on to extract settings from.
Raises:

RuntimeError – If addon_id is given and there is no add-on with given ID.

Returns:

Setting as a “unicode string”.

Return type:

str

static get_boolean(key, addon_id=None)[source]

Returns the value of a setting as a “Boolean”.

Parameters:
  • key (str) – ID of the setting to access.
  • addon_id (str) – [opt] ID of another add-on to extract settings from.
Raises:

RuntimeError – If addon_id is given and there is no add-on with given ID.

Returns:

Setting as a “Boolean”.

Return type:

bool

static get_int(key, addon_id=None)[source]

Returns the value of a setting as a “Integer”.

Parameters:
  • key (str) – ID of the setting to access.
  • addon_id (str) – [opt] ID of another add-on to extract settings from.
Raises:

RuntimeError – If addon_id is given and there is no add-on with given ID.

Returns:

Setting as a “Integer”.

Return type:

int

static get_number(key, addon_id=None)[source]

Returns the value of a setting as a “Float”.

Parameters:
  • key (str) – ID of the setting to access.
  • addon_id (str) – [opt] ID of another addon to extract settings from.
Raises:

RuntimeError – If addon_id is given and there is no addon with given ID.

Returns:

Setting as a “Float”.

Return type:

float