Kodi
Kodi is a free, open source media center: it plays videos, music and pictures on a TV, from local files, network shares and add-ons. It runs on almost anything; a Raspberry Pi behind the TV is the classic setup.
Kodi has its own remote apps, but they are built to browse Kodi's library, not to send it what is on your computer. I wrote three small tools for that, each for a different place the thing you want on the TV comes from:
| Project | You send | From | Language |
|---|---|---|---|
| send2kodi | Links, and the videos, music and pictures on your computer | The command line | Python |
| browser2kodi | The picture, video, song, link or page you are looking at | The browser's right-click menu and toolbar | JavaScript |
| wl2kodi | The whole screen, live | A wlroots Wayland desktop | Shell |
None of them needs anything installed on the Kodi box beyond what this page describes.
Setting up Kodi
All three talk to Kodi over its web server, which is off by default. Turn it on in Settings → Services → Control:
- Allow remote control via HTTP: on.
- Port:
8080by default; all three tools assume it. - Username and Password:
kodiand empty by default. Set a password if anyone else shares your network, and give it to the tools.
Add-ons
Kodi plays links to media files and streams (.mp4,
.mp3, .m3u8...) by itself. A web page like a
YouTube video is not a media file, so it needs an add-on that turns it
into one. Both are optional; install them from Kodi's add-on browser or
their repositories.
| Add-on | For |
|---|---|
YouTube (plugin.video.youtube) |
YouTube videos; the fastest way to play them |
SendToKodi
(plugin.video.sendtokodi) |
Any other page yt-dlp understands: Vimeo, Twitch, YouTube playlists... It runs yt-dlp on the Kodi box |
send2kodi and browser2kodi send YouTube through the YouTube add-on by
default, and through SendToKodi if you ask them to
(--ytdlp, or the YouTube option).
How the tools talk to Kodi
Kodi's web server speaks JSON-RPC: a POST to
http://KODI:8080/jsonrpc with a method and its parameters.
This is enough to play a link:
$ curl -s -u kodi: -H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","id":1,"method":"Player.Open","params":{"item":{"file":"https://example.com/video.mp4"}}}' \
http://192.168.1.50:8080/jsonrpc
Everything else is deciding what to put in file:
| What | file |
|---|---|
| A media file or stream | its URL, as it is |
| A YouTube video | plugin://plugin.video.youtube/play/?video_id=ID |
| Any other page | plugin://plugin.video.sendtokodi/?URL |
| A file on your computer | an HTTP URL to it, served by send2kodi |
| Your screen | udp://@:PORT, where wl2kodi streams to |
The rest of the work is in the details: Playlist.Add to
queue instead of play, Player.Seek to start at the time in
a YouTube link, Player.AddSubtitle for subtitles, and
Player.GetActivePlayers to check that Kodi really started
playing.
OK to any Player.Open, even for a
link that will never play. send2kodi and browser2kodi wait until a
player is actually running, and otherwise tell you why, so a failure
does not look like a success.Kodi decides how to play something by the extension of its path: a
picture without one, like the thumbnails of an image search, goes to the
video player, which flashes it and stops. send2kodi serves such pictures
under a .jpg name; browser2kodi, which cannot serve
anything, sends them through the wsrv.nl image proxy.
Which one to use
- A file on your computer (a film, a folder of episodes, an album, holiday pictures): send2kodi. It is the only one that can, by serving the files to Kodi itself. Subtitles next to a video go along with it.
- A link you have in the terminal or the clipboard:
send2kodi (
send2kodi URL, orsend2kodi -C). - Something on the web page you are looking at: browser2kodi. Right-click it, or click the toolbar button to send the page.
- Anything that is not a file or a link (slides, a demo, a video call): wl2kodi, which mirrors the screen.
send2kodi and browser2kodi make Kodi fetch the media itself, at its full quality, and leave your computer free: you can close the laptop once it plays (send2kodi has to keep serving local files until Kodi has played them). wl2kodi streams what your screen shows instead, with 200–500 ms of latency and, for now, no audio.
Installation
send2kodi and wl2kodi are also in the pm user repository; browser2kodi installs like any other browser extension.
| Project | Install |
|---|---|
| send2kodi | ./install.sh, which asks for Kodi's address and checks
which add-ons it has; or pm |
| browser2kodi | addons.mozilla.org for Firefox, the release zip for Chrome |
| wl2kodi | Copy the script to ~/.local/bin; or pm |
send2kodi and browser2kodi have the same settings: address, port,
user, password and how to play YouTube. wl2kodi takes the address with
--tv, and --user and --pass if
Kodi has a login.
Troubleshooting
- Can't reach Kodi: check that Kodi is on, the address and port are right, and Allow remote control via HTTP is enabled.
- Links play but local files don't: Kodi cannot reach
your computer. Check that a firewall lets send2kodi's port
(
8765) through. - A web page does not play: install SendToKodi, or try the other YouTube option. Pages behind a login do not play: Kodi fetches them without your browser's cookies.
- wl2kodi shows nothing: look for
failed to configure rendererin Kodi's log, and wait ~30 s after restarting Kodi before streaming.
See also
- Guides