Skip to content
Ivan Kokan edited this page Feb 2, 2020 · 11 revisions

Integrating in your add-on

Below is an example of how to integrate InputStream Helper in your add-on.

import sys
import xbmcgui
import xbmcplugin

PROTOCOL = 'mpd'
DRM = 'com.widevine.alpha'
STREAM_URL = 'https://demo.unified-streaming.com/video/tears-of-steel/tears-of-steel-dash-widevine.ism/.mpd'
LICENSE_URL = 'https://cwip-shaka-proxy.appspot.com/no_auth'


def play():
    from inputstreamhelper import Helper  # pylint: disable=import-outside-toplevel

    is_helper = Helper(PROTOCOL, drm=DRM)
    if is_helper.check_inputstream():
        play_item = xbmcgui.ListItem(path=STREAM_URL)
        play_item.setProperty('inputstreamaddon', is_helper.inputstream_addon)
        play_item.setProperty('inputstream.adaptive.manifest_type', PROTOCOL)
        play_item.setProperty('inputstream.adaptive.license_type', DRM)
        play_item.setProperty('inputstream.adaptive.license_key', LICENSE_URL + '||R{SSM}|')
        xbmcplugin.setResolvedUrl(handle=int(sys.argv[1]), succeeded=True, listitem=play_item)

if __name__ == '__main__':
    play()

The Helper class takes two arguments: protocol (the media streaming protocol) and the optional argument 'drm'.

Accepted protocol arguments:

  • mpd -- MPEG-DASH
  • ism -- Microsoft Smooth Streaming
  • hls -- HTTP Live Streaming from Apple
  • rtmp -- Real-Time Messaging Protocol

Accepted drm arguments:

  • widevine
  • com.widevine.alpha

NOTE: Also notice that we recommend to import inputstreamhelper in the block where it will be used (contrary to general Python practices). This avoids adding to the start-up time of your add-on (especially on Raspberry Pi). This is an advice you can also use within your add-on to speed up load times.

Integrating in your addon.xml

It is recommended to not add your InputStream add-on (e.g. inputstream.adaptive) as a dependency in addon.xml. It can cause confusion with users not being able to install your add-on because the InputStream add-on is disabled. InputStream Helper addresses issues such as these and helps the user to install/enable required InputStream components.

So we expect to have this add:

<addon ...>
    ...
    <requires>
        ...
        <import addon="script.module.inputstreamhelper" version="0.4.2"/>
        ...
    </requires>
    ...
</addon>

Integrating in your add-on settings

In order to help in troubleshooting playback issues in your add-on, it could be useful to give your users direct access to the information and controls of InputStream Helper.

Typically an add-on has a special section in its settings named Troubleshooting or Expert, you could add any of the below there.

Access to Kodi/Add-on/Widevine version information

If you like you can add something like this in your resources/settings.xml.

<setting label="InputStream Helper information" type="action" action="RunScript(script.module.inputstreamhelper,info)"/>

Access to InputStream Helper settings

If you wish to give users the ability to open the InputStream Helper directly from your settings, you can add this to your resources/settings.xml.

<setting label="InputStream Helper settings..." type="action" action="Addon.OpenSettings(script.module.inputstreamhelper)" option="close"/>

In this case you may want to add in gray/italic "(for protected content)" or "(for Widevine DRM content)".

Access to (re)install Widevine

If you consider it useful that the user can install or reinstall Widevine, you could add the following to your resources/settings.xml.

<setting label="(Re)install Widevine CDM..." type="action" action="RunScript(script.module.inputstreamhelper,widevine_install)" visible="!system.platform.android"/>

or to remove Widevine:

<setting label="Remove Widevine CDM..." type="action" action="RunScript(script.module.inputstreamhelper, widevine_remove)" visible="!system.platform.android"/>