Add-on:Kodi Callbacks: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 21: Line 21:
== Features ==
== Features ==


* Run a user configured task when events occur in Kodi
* Runs as a service when Kodi starts
 
* Runs user configured tasks when events occur in Kodi
* Currently can create tasks for:
* Currently can create tasks for:
# Running an external script with or without the shell
# Running an external script with or without the shell
Line 42: Line 44:


To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at 'Users/Username/AppData/Roaming/Kodi/addons/'. If you have a previous installation, consider backing it up to a safe place before installing.
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at 'Users/Username/AppData/Roaming/Kodi/addons/'. If you have a previous installation, consider backing it up to a safe place before installing.
Remove the '-master' from the end of the folder name!!!


If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2
Line 60: Line 64:
=== Details ===
=== Details ===


There are three pages of settings - Tasks, Events and General
==== Settings - Tasks ====
[[File:Kodi-callbacks-settings1.PNG|800px|frameless|right]]
[[File:Kodi-callbacks-settings1.PNG|800px|frameless|right]]


==== Settings - Tasks ====
You can configure up to 10 tasks.
For each task, select a type - builtin, http, python or script.
For all you can configure:
# The maximum number of this task that can be running simultaneously
# The maximum number of times this task can be run for a given Kodi session
# A refractory period after a task is run where it won't be re-run
 
For different types, there are additional things to configure:
 
For scripts, whether the script requires the shell to run
For python:
# Execute the python file directly
# Import the file as a module and call whatever is designated within as 'run' - arguments will be passed as run(args)
 
Note the task number as that is how it will be referred to on the next settings page.




Line 68: Line 89:
==== Settings - Events ====
==== Settings - Events ====
[[File:Kodi-callbacks-settings2.PNG|800px|frameless|right]]
[[File:Kodi-callbacks-settings2.PNG|800px|frameless|right]]
You can configure up to 10 events and have each use a different task or reuse the same task.
For each event, select an event type. There are currently 23 different events.
For some events, additional information is required:
# For JSON notification events, the sender, method and data are required.
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]
# For Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require 'matchIf' strings.
# A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.
# Log strings can also be rejected if a different portion matches 'rejectIf'.
A variable substituted argument string can then optionally be provided to pass additional information to your task.
The variables that can be passed are dependent on the event and are shown on the settings page.
Only the variables shown will be searched for and substituted.
To ensure that literal percent signs are passed correctly, use '%%'.
Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.
If you need to ensure that a space is not split, use %_.
Again, spaces can cause issues sometimes. Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.
A fully configured event can be tested from the Event Settings Page.
First click OK to cause any changes made to be written to the user settings file.
Then re-enter Settings and navigate back to the event to be tested and click "Test command'.
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).
NOTE: The test will in most circumstances wait for the task to 'return'. So if the task launches a program, no further information will be provided until that program ends.
Exceptions or any returned text will then be displayed.


<br clear=all>
<br clear=all>
==== Settings - General ====
==== Settings - General ====
[[File:Kodi-callbacks-settings3.PNG|800px|frameless|right]]
[[File:Kodi-callbacks-settings3.PNG|800px|frameless|right]]
These are the settings that are used when using the '''Auto switch based on AR''' mode. Here, the profiles that have been previously configured in AmbiBox to be used with full screen video of various aspect ratios are configured. The default is None. If no profile is configured for a given aspect ratio, the next closest one will be chosen.
 
The addon can optionally show a brief notification each time a task is run.
 
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.
 
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.
 
The Log frequency is for the log checker.
 
The Task frequency is for the main task dispatcher.
 
 
An option is provided to elevate all routine messages to the normal log, instead of the debug log.
 
A request has been made by the Kodi developers that addons avoid writing to the normal log.
 
This allows you to selectively elevate messages to that log for troubleshooting and then turn it back off once fixed.
 
This avoids having the user turn on the full debug mode with its OSD.
 
Lastly, you can click to regenerate the addon's settings.xml file. This is only needed if you have created your own task and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.


<br clear=all>
<br clear=all>
Line 78: Line 160:
== Notes ==
== Notes ==


The log checking events consume the most resources and regex checks utilize more than simple checks.


* Using the option to switch profiles based upon a file's display aspect ratio depends on the file being properly formatted. In some circumstances XBMC is able to provide that information to the script. If not, that information can sometimes be retrieved using a dll called mediainfo, which may be optionally downloaded and installed from the settings page. Not all files comply with formatting standards or have the correct information available. Furthermore, if the letterboxing is hardcoded into the file (i.e. there is actually black boxes in the video frame itself), this will not be detected.
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle).
* Switching profiles for 3D content is solely based on the file name.
 
* XBMCDirect capture has to be enabled as a capture mode BOTH in the Ambibox program itself and in the XBMC settings. This works by mapping the memory for video frames directly in XBMC and then passing that information on to AmbiBox. Whether this is better or worse that other capture modes is highly dependent on your system. The best way to figure this out is trial and error. This method CANNOT be used if you are using an external video player such as MPC-HC.
These are only started if there is a task configured that utilizes them.


== Limitations ==
* For modes other than PlayClaw or XBMCDirect, XBMC must be run in fullscreen windowed mode.
* If using an external player and not using mediainfo, the DAR may not be detected by the system.
* XBMCDirect does not work with external players.
* XBMCDirect will only activate the lights while playing audio or video content. The lights will remain off in the XBMC GUI.
* XBMCDirect will not work with most streaming video as opposed to playing from a file.
* For LiveTV content that is in a DAR other than your display's DAR, there may be black bars embedded in the content. If the video is not zoomed to fill the display window, the capture areas may not be capturing areas with active video content. This is true for all capture modes.
* XBMCDirect may not work with LiveTV SD content due to the black bar areas.
* XBMCDirect does NOT work with DSPlayer builds of XBMC Gotham.
* The automatic sensing of using a 3D mode in the GUI is not directly supported.
* Currently only hSBS and hTAB 3D video modes are supported and in a limited fashion.


== FAQs ==
== FAQs ==


'''Why would I want to go through the trouble of setting up all of these different profiles, my display is 16:9, why would I use other profiles?'''
'''I need to a respond to an event that isn't listed as an event. Can you make it so that I can?'''


When video files are played that have display aspect ratios that differ from your display, some people may either zoom or stretch the video so that it fills the screen. Under those circumstances, only one profile is needed because the video content reaches to the edge of the screen and can be correctly captured in order to drive the LED’s.
Most likely, no. Pretty much everything that can be detected is already there.
The other, often preferred, method of display is using letterboxing or pillaring. Black or gray bars are placed either above and below or on either side of the video in order to display the content without distortion. In this case, there is no active video content in these areas and the AmbiBox application would be capturing whatever color is in those bars if it is using a standard setup to capture around the periphery of the display. By setting up different capture profiles for content with different aspect ratios, one can capture from the edge of the active content and have the LED’s display correctly.


'''Why don’t my LED’s light while music is playing?'''
'''I am having an issues, how can I get help?'''


I have set up a profile using ColorMusic and AmbiBox switches to it but the lights remain dark.
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/
AmbiBox cannot hook into the audio stream if you are using WASAPI for audio output. Please go to System -> System -> Audio Output and go to the very bottom (often times this setting isn’t seen if you do not scroll) to Audio Output Device and choose something other than WASAPI.


'''I am having an issues, how can I get help?'''
If you believe that things are not working as expected, please also UPLOAD A COPY OF 'kodi.log' TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin] AND INCLUDE A LINK TO THE LOG IN YOUR POST!


The two best places to get script help are: via the XBMC forum thread here: http://forum.kodi.tv/showthread.php?tid=198173 or via the Adafruit forums in this thread: http://forums.adafruit.com/viewtopic.php?f=47&t=36032
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.


If you believe that things are not working as expected, please also include the ''version number'' of the script and any ''relevant entries in the XBMC logs'' in your post.
The forum moderators frown upon posting your log directly in the forum.


[[Category:Add-ons not in the Kodi.tv repo]]
[[Category:Add-ons not in the Kodi.tv repo]]

Revision as of 23:17, 11 January 2016

Kodi Callbacks
http://kodi.wiki/images/0/08/Callbacks-icon.png

See this add-on on the kodi.tv showcase

Author: KenV99

Type: Services
Repo:

License: GPL v2.0
Source: Source code
Summary: Callbacks for Kodi Events to launch user tasks
Home icon grey.png   ▶ Add-ons ▶ Kodi Callbacks
Attention talk.png Need help with this add-on? See here.

Perform custom user-defined tasks for multiple events in Kodi

Installing

This add-on is installed from the Add-on browser located in Kodi as follows:

  1. Settings
  2. Add-ons
  3. Install from repository
  4. Services
  5. Kodi Callbacks
  6. Install

Features

  • Runs as a service when Kodi starts
  • Runs user configured tasks when events occur in Kodi
  • Currently can create tasks for:
  1. Running an external script with or without the shell
  2. Running an external python script either directly or via dynamic import
  3. Running a Kodi builtin
  4. Sending an http string (response)
  • Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments
  • 23 different Kodi events are supported
  • Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting
  • New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the resources/lib/tasks folder

Installation

Overview

The script is not currently available via the official repo (it's a localized string issue that prevents submission). You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip

Details

To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at 'Users/Username/AppData/Roaming/Kodi/addons/'. If you have a previous installation, consider backing it up to a safe place before installing.

Remove the '-master' from the end of the folder name!!!

If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2

Configuration

Overview

In Kodi go to System > Add-Ons > Enabled Add-Ons > Services > Kodi Callbacks > Configure

In general:

  1. Configure your task.
  2. On the next page, associate your task with one or more events.
  3. Click OK to save.
  4. Re-enter settings by clicking configure.
  5. Test your setup

Details

There are three pages of settings - Tasks, Events and General

Settings - Tasks

Kodi-callbacks-settings1.PNG

You can configure up to 10 tasks. For each task, select a type - builtin, http, python or script. For all you can configure:

  1. The maximum number of this task that can be running simultaneously
  2. The maximum number of times this task can be run for a given Kodi session
  3. A refractory period after a task is run where it won't be re-run

For different types, there are additional things to configure:

For scripts, whether the script requires the shell to run For python:

  1. Execute the python file directly
  2. Import the file as a module and call whatever is designated within as 'run' - arguments will be passed as run(args)

Note the task number as that is how it will be referred to on the next settings page.



Settings - Events

Kodi-callbacks-settings2.PNG

You can configure up to 10 events and have each use a different task or reuse the same task. For each event, select an event type. There are currently 23 different events. For some events, additional information is required:

  1. For JSON notification events, the sender, method and data are required.
  2. For Window Open and Close events, the window id is needed (see: Kodi Window Ids
  3. For Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).
  4. For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require 'matchIf' strings.
  5. A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.
  6. Log strings can also be rejected if a different portion matches 'rejectIf'.

A variable substituted argument string can then optionally be provided to pass additional information to your task.

The variables that can be passed are dependent on the event and are shown on the settings page.

Only the variables shown will be searched for and substituted.

To ensure that literal percent signs are passed correctly, use '%%'.

Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.

If you need to ensure that a space is not split, use %_.

Again, spaces can cause issues sometimes. Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.


A fully configured event can be tested from the Event Settings Page.

First click OK to cause any changes made to be written to the user settings file.

Then re-enter Settings and navigate back to the event to be tested and click "Test command'.

First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.

Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).

NOTE: The test will in most circumstances wait for the task to 'return'. So if the task launches a program, no further information will be provided until that program ends.

Exceptions or any returned text will then be displayed.



Settings - General

Kodi-callbacks-settings3.PNG

The addon can optionally show a brief notification each time a task is run.

Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.

The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.

The Log frequency is for the log checker.

The Task frequency is for the main task dispatcher.


An option is provided to elevate all routine messages to the normal log, instead of the debug log.

A request has been made by the Kodi developers that addons avoid writing to the normal log.

This allows you to selectively elevate messages to that log for troubleshooting and then turn it back off once fixed.

This avoids having the user turn on the full debug mode with its OSD.

Lastly, you can click to regenerate the addon's settings.xml file. This is only needed if you have created your own task and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.


Notes

The log checking events consume the most resources and regex checks utilize more than simple checks.

The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle).

These are only started if there is a task configured that utilizes them.


FAQs

I need to a respond to an event that isn't listed as an event. Can you make it so that I can?

Most likely, no. Pretty much everything that can be detected is already there.

I am having an issues, how can I get help?

The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/

If you believe that things are not working as expected, please also UPLOAD A COPY OF 'kodi.log' TO: XBMCLogs or pastebin AND INCLUDE A LINK TO THE LOG IN YOUR POST!

I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.

The forum moderators frown upon posting your log directly in the forum.