All Projects → tamland → kodi-plugin-routing

tamland / kodi-plugin-routing

Licence: GPL-3.0 license
A routing module for kodi plugins

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to kodi-plugin-routing

KodiSharp
Use Kodi python APIs in C#, and write rich addons using the .NET framework/Mono
Stars: ✭ 22 (-35.29%)
Mutual labels:  kodi, kodi-plugin, kodi-module
plugin.video.covenant
Covenant Kodi Addon Development - Kodi is a registered trademark of the XBMC Foundation. We are not connected to or in any other way affiliated with Kodi - DMCA: [email protected]
Stars: ✭ 24 (-29.41%)
Mutual labels:  kodi, kodi-plugin
kodi.plugin.yandex-music
Yandex Music plugin for Kodi
Stars: ✭ 33 (-2.94%)
Mutual labels:  kodi, kodi-plugin
repository.colossus
Colossus Repository for Kodi Addons - Kodi is a registered trademark of the XBMC Foundation. We are not connected to or in any other way affiliated with Kodi - DMCA: [email protected]
Stars: ✭ 13 (-61.76%)
Mutual labels:  kodi, kodi-plugin
plugin.video.vrt.nu
Kodi add-on to watch content from the VRT NU website
Stars: ✭ 88 (+158.82%)
Mutual labels:  kodi, kodi-plugin
script.library.integration.tool
Kodi addon that allows video plugin content to be integrated into your library
Stars: ✭ 14 (-58.82%)
Mutual labels:  kodi, kodi-plugin
Tvlist Awesome M3u M3u8
直播源相关资源汇总 📺 💯 IPTV、M3U —— 勤洗手、戴口罩,祝愿所有人百毒不侵
Stars: ✭ 5,304 (+15500%)
Mutual labels:  kodi, kodi-plugin
DeezerKodi
Deezer client for Kodi
Stars: ✭ 15 (-55.88%)
Mutual labels:  kodi, kodi-plugin
ElementumService
A service that executes binaries for Kodi's addon Elementum on Android without a W^X violation.
Stars: ✭ 51 (+50%)
Mutual labels:  kodi
plugin.video.giraffe.seasonvar
plugin for Kodi to watch seasonvar.ru
Stars: ✭ 23 (-32.35%)
Mutual labels:  kodi-plugin
kodi-viaplay
Viaplay for Kodi
Stars: ✭ 26 (-23.53%)
Mutual labels:  kodi
skin.grid
Grid, a UI for Kodi. By using this code you agree with the license terms as included.
Stars: ✭ 39 (+14.71%)
Mutual labels:  kodi
youtube-to-XBMC
[WebExtension] Kassi Share - Send YouTube videos to XBMC
Stars: ✭ 21 (-38.24%)
Mutual labels:  kodi
service.subloader
Kodi automatic subtitles
Stars: ✭ 26 (-23.53%)
Mutual labels:  kodi
kodi
KODI Addons Project
Stars: ✭ 48 (+41.18%)
Mutual labels:  kodi
repository.membrane
Repository for my Kodi add-ons
Stars: ✭ 56 (+64.71%)
Mutual labels:  kodi
plugin.video.sendtokodi
📺 plays various stream sites on kodi using youtube-dl
Stars: ✭ 86 (+152.94%)
Mutual labels:  kodi
PlexKodiConnect
Plex integration in Kodi done right
Stars: ✭ 917 (+2597.06%)
Mutual labels:  kodi
repository.dobbelina
repository.dobbelina- Kodi is a registered trademark of the XBMC Foundation.We are not connected to or in any other way affiliated with Kodi
Stars: ✭ 161 (+373.53%)
Mutual labels:  kodi
pvr.freebox
Kodi + Freebox TV
Stars: ✭ 51 (+50%)
Mutual labels:  kodi

GitHub release Build Status License: GPLv3 Contributors

Plugin routing

Library for building and parsing URLs in Kodi plugins.

Example

import routing
from xbmcgui import ListItem
from xbmcplugin import addDirectoryItem, endOfDirectory

plugin = routing.Plugin()

@plugin.route('/')
def index():
    addDirectoryItem(plugin.handle, plugin.url_for(show_category, "one"), ListItem("Category One"), True)
    addDirectoryItem(plugin.handle, plugin.url_for(show_category, "two"), ListItem("Category Two"), True)
    addDirectoryItem(plugin.handle, plugin.url_for(show_directory, "/dir/one"), ListItem("Directory One"), True)
    addDirectoryItem(plugin.handle, plugin.url_for(show_directory, "/dir/two"), ListItem("Directory Two"), True)
    endOfDirectory(plugin.handle)

@plugin.route('/category/<category_id>')
def show_category(category_id):
    addDirectoryItem(plugin.handle, "", ListItem("Hello category %s!" % category_id))
    endOfDirectory(plugin.handle)

@plugin.route('/directory/<path:dir>')
def show_directory(dir):
    addDirectoryItem(plugin.handle, "", ListItem("List directory %s!" % dir))
    endOfDirectory(plugin.handle)

if __name__ == '__main__':
    plugin.run()

Creating rules

The route() decorator binds a function to an URL pattern. The pattern is a path expression consisting of static parts and variable parts of an URL. Variables are enclosed in angle brackets as <variable_name> and will be passed to the function as keyword arguments.

For example:

@plugin.route('/hello/<what>')
def hello(what):
    # will be called for all incoming URLs like "/hello/world", "/hello/123" etc.
    # 'what' will contain "world", "123" etc. depending on the URL.
    pass

In case your variable contains slashes (i.e. is a path or URL) and you want to match this, you can use the path identifier in the patern.

@plugin.route('/url/<path:url>')
def parse_url(url):
    # will be called for all incoming URLs like "/url/https://foo.bar/baz" etc.
    # 'url' can be any string with slashes.
    pass

Routes can also be registered manually with the add_route method.

Building URLs

url_for() can be used to build URLs for registered functions. It takes a reference to a function and a number of arguments that corresponds to variables in the URL rule.

For example:

plugin.url_for(hello, what="world")

will read the rule for hello, fill in the variable parts and return a final URL:

plugin://my.addon.id/hello/world

which can be passed to xbmcplugin.addDirectoryItem(). All variable parts must be passed to url_for either as ordered arguments or keyword arguments.

Keywords that does not occur in the function/pattern will be added as query string in the returned URL.

Alternatively, URLs can be created directly from a path with url_for_path. For example url_for_path('/foo/bar') will return plugin://my.addon.id/foo/bar. Unlike url_for this method will not check that the path is valid.

Query string

The query string part of the URL is parsed with urlparse.parse_qs and is accessible via the plugin.args attribute. The dictionary keys corresponds to query variables and values to lists of query values.

Example:

@plugin.route('/')
def index():
    url = plugin.url_for(search, query="hello world")
    addDirectoryItem(plugin.handle, url, ListItem("Search"))
    # ...


@plugin.route('/search')
def search():
    query = plugin.args['query'][0]
    addDirectoryItem(plugin.handle, "", ListItem("You searched for '%s'" % query))
    # ...

Creating a dependency in your addon

To get kodi to install this dependency you will have to add a command to your addons.xml.

    <requires>
        <import addon="xbmc.python" version="2.25.0" />
        <import addon="script.module.routing" version="0.2.0"/>
    </requires>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].