8000 GitHub - yertto/kodi_event: Bash script to control a Kodi instance running EventServer.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

yertto/kodi_event

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kodi_event

Conventional Commits

Bash script to compose packets and send them to a Kodi instance running an Event Server.

Its only dependency is the xxd command.

(which is usually packaged with vim-common so should be widely available)

Background

It is a re-write in bash of the xbmcclient.py python library included in Kodi.

Implementation of XBMC's UDP based input system.

A set of classes that abstract the various packets that the event server currently supports. In addition, there's also a class, XBMCClient, that provides functions that sends the various packets

NB. Kodi also allows control via it's JSON-RPC API.

JSON-RPC is a HTTP- and/or raw TCP socket-based interface for communicating with Kodi. It replaces the deprecated HTTP API.

However this tool is using a third way to control Kodi - the EventServer

The EventServer in Kodi was created to satisfy a need to support many input devices across multiple hardware platforms. Adding direct support for a multitude of devices generally decreases performance and stability, and becomes difficult to maintain. The EventServer was created to provide a simple, reliable way to communicate with and control Kodi.

A quick and easy way to tell clients apart is to look for the port number they use to connect to Kodi.

  • JSON-RPC API clients communicate with Kodi using TCP on port 9090
  • EventServer clients communicate with Kodi using UDP on port 9777

Getting Started

This (and any other Event Client) requires Kodi to be configured to allow remote control from applications on other systems.

Installation:

git clone git@github.com:yertto/event_client.git ~/Code/event_client
export PATH="$HOME/Code/event_client/bin:$PATH"

Alternatives

repo JSON-RPC API Event Server CLI language description
kodi-remotecontrol 🚫 🚫 python This is a Python remote control for Kodi with minimal but sufficient basic controls. This remote control acts as a WebSocket Gateway of the UDP Event Server API for more reactivity.
kodi-control 🚫 python Kodi Control can be used to control a running instance of Kodi from a terminal. You can use it to interactively control the app and the players by opening a terminal and typing individual characters to perform various actions
kodi-cli 🚫 python used from the command line to execute commands against a target Kodi host via the RPC interface defined at JSON-RPC API This provides a Kodi JSON-RPC client. All Kodi JSON methods can be called as methods to the KodiJSONClient instance.
python-kodijson 🚫 🚫 python Simple python module that allow kodi control over JSON-RPC API
xbmc-client 🚫 python is a Kodi command line client, written in Python to control your Kodi instance through the JSON-RPC API (
kodijsonrpc 🚫 🚫 python This provides a Kodi JSON-RPC client. All Kodi JSON methods can be called as methods to the KodiJSONClient instance.
kodicontroller 🚫 🚫 python This package provides an array of functions which can be used to control a Kodi instance.
PyKodi 🚫 🚫 python An async python interface for Kodi over JSON-RPC. This is mostly designed to integrate with HomeAssistant. If you have other needs, there might be better packages available.

Motivation

Home Assistant - Kodi (View Source) is a Home Assistant integration to control a Kodi multimedia system.

However I wanted to use Kodi's Event Server so I could use button events to drive the UI and Home Assistant integration didn't appear to do that.

In particular I want to send Left and Right button events so I can use the Skip Steps to incrementally skip.

I only found one alternative that would connect to the Event Server.

However to run as a script in my Home Assistant it needs to be able to run with the very minimal resources used by BusyBox

BusyBox combines tiny versions of many common UNIX utilities into a single small executable. It provides replacements for most of the utilities you usually find in GNU fileutils, shellutils, etc. The utilities in BusyBox generally have fewer options than their full-featured GNU cousins; however, the options that are included provide the expected functionality and behave very much like their GNU counterparts. BusyBox provides a fairly complete environment for any small or embedded system.

So I made this tool to work just using bash & BusyBox's version of xxd.

(And remarkably enough, it appears to achieve everything the python library does.)

Testing

The tests can be run with:

  • make test

These tests make "golden test" assertions against pre-created binary packets.

The packets have been manually tested and confirmed to work against Kodi v20.1-Nexus

ie. by running:

  • cat shpecs/support/NOTIFICATION/10chars_with_title.bin | EVENT_SERVER_HOST=$kodi_host kodi_event_send
  • cat shpecs/support/BUTTON/R1-info.bin | EVENT_SERVER_HOST=$kodi_host kodi_event_send

Or run interactively using:

  • kodi_event-test_menu
Screen Shot 2023-11-28 at 1 11 51 am

Where the "golden" pre-created binary packets can be re-created using uid=1700610725 and checked to have stayed unchanged with di 6CE3 ff & xxd

eg. when a diff of their xxd hexdumps produces no difference...

  • diff -u <(xxd < shpecs/support/LOG/10chars.bin) <(uid=1700610725 pt=LOG kodi_event_packet "$(printf "X%.0s" {1..10})" | xxd)

Or sent to Kodi using the generic kodi_event command setting a different packet type (pt) for each event type:

Or there's also convenience scripts that pass in the pt type to kodi_event:

  • kodi-helo # equavilent to pt=HELO kodi_event
  • kodi-button escape # equavilent to pt=BUTTON kodi_event escape
  • kodi-action CreateBookmark # equavilent to pt=ACTION kodi_event CreateBookmark
  • kodi-notification hello world # equavilent to pt=NOTIFICATION kodi_event hello world
  • kodi-log hello logs # equavilent to pt=LOG kodi_event hello logs
  • kodi-ping # equavilent to pt=PING kodi_event
  • kodi-bye # equavilent to pt=BYE kodi_event

Nb. all these commands require an EVENT_SERVER_HOST env var pointing at the Kodi instance.

(Or BROADCAST=255.255.255.255 to broadcast to all running Kodi instances.)

eg.

  • BROADCAST=255.255.255.255 kodi-notification hello all kodi instances

Or if your router doesn't like that, then something like:

  • BROADCAST=192.168.1.255 kodi-notification hello all kodi instances
    • (ie. if your kodi instances ar on the 192.168.1.x network.)

About

Bash script to control a Kodi instance running EventServer.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0