Repository navigation
Plugins
A plugin is a small Python add-on. It can listen to what happens in the room, add colour themes, add songs to search results and show short messages on the TV.
"""Says the song title when a song starts."""
NAME = "Hello"
VERSION = "1.0.0"
PERMISSIONS = ["events", "toast"]
API_VERSION = 1
def setup(api):
def on_state(_payload):
song = api.now_playing()
if song:
api.toast(f"Now singing: {song['title']}")
api.on("state", on_state)Examples to copy and change:
- hello_plugin.py: reacts to songs and shows a message.
- theme_plugin.py: a colour theme.
- song_source_plugin.py: adds songs from a CSV file to search results.
-
A single file: copy the
.pyfile into thepluginsfolder of the YTKTV data folder. Settings → Plugins shows the exact path. -
A package: publish it on PyPI with an entry point in the
ytktv.pluginsgroup:[project.entry-points."ytktv.plugins"] hello = "ytktv_hello"
A plugin stays off until the venue turns it on in Settings → Plugins. Before it is turned on, YTKTV shows what it asks for. Changes take effect the next time YTKTV starts. If a new version asks for more than the venue agreed to, it is turned off again until the venue agrees.
| Permission | Lets the plugin |
|---|---|
events |
use api.on(topic, callback) and api.now_playing()
|
themes |
use api.add_theme(name, colours)
|
songs |
use api.add_song_source(search)
|
toast |
use api.toast(text)
|
Calling something you did not ask for raises PermissionDenied, and the plugin is turned
off for the session.
Permissions say what a plugin means to do. They are not a sandbox: a plugin is Python code running with this computer's access. Venues should only turn on plugins they trust.
-
api.on(topic, callback):callback(payload)runs whenever the app emitstopic. Topics includestate,score,lyrics,game,reactionandtoast. Use"*"to get every topic ascallback(topic, payload). Callbacks run on the app's own threads, so return quickly. -
api.now_playing(): the song on screen (video_id,title,channel,singer), orNone. -
api.add_theme(name, colours): a theme based on Neon.coloursreplaces any ofBG,PANEL,PANEL_2,LINE,TEXT,MUTED,PINK,CYAN,PURPLE,GOLD,GREENandDANGERwith#rrggbbcolours. -
api.add_song_source(search):search(query)returnsytktv.core.models.Songobjects with YouTube video ids. They are added after the normal results (at most 20 per plugin). It runs off the GUI thread. -
api.toast(text): a short message on the TV. -
api.data_dir: a folder of the plugin's own for files it keeps. -
api.log: alogging.Loggerfor the plugin. -
api.api_version: the plugin API version,1today. A plugin that sets a higherAPI_VERSIONthan YTKTV supports is not loaded.
If setup, a callback or a song source raises an error, the error is logged, the plugin
is turned off for the session and the error is shown in Settings → Plugins. YTKTV keeps
running.
This page is copied from docs/guide in the repository. To change it, edit the file there (a pull request is welcome); edits made only here would be overwritten by the next copy.