addon: wire play action + remote-control via Kodi JSON-RPC

main.py now handles the standard Kodi plugin-URL routing:

  plugin://plugin.video.torttube/?action=play&id=<yt-id>
  plugin://plugin.video.torttube/?action=play&url=<full-url>

Either form calls the sidecar resolve op, picks a stream URL from the
response (rustypipe video_stream preferred, yt-dlp combined fallback),
and hands it to Kodi via xbmcplugin.setResolvedUrl.

URL parser accepts watch?v=, youtu.be/, /shorts/, /embed/, /live/, and
bare 11-char IDs. setResolvedUrl flags inputstream.adaptive for .mpd
and .m3u8 manifests so DASH/HLS streams play with the right demuxer.

This makes 'share to TV' work over Kodi's existing JSON-RPC API on
:8080 — Player.Open with a plugin URL is all the remote client needs.
No new server, no app — Kore / Yatse / curl / HA all already work.

docs/remote-control.md captures the curl recipe + Android share-target
plan for the eventual companion app.
This commit is contained in:
Kayos 2026-05-23 08:37:57 -07:00
parent 7add3cb469
commit 9b2a47c909
3 changed files with 261 additions and 7 deletions

74
docs/remote-control.md Normal file
View file

@ -0,0 +1,74 @@
# Remote control — sending a YouTube URL to Kodi
Kodi exposes a JSON-RPC HTTP endpoint that any client on the LAN can hit
to start playback. torttube wires up the `play` action so this works
out of the box once the addon is installed.
## Endpoint
```
POST http://<rpi-host>:8080/jsonrpc
Authorization: Basic base64(kodi:<password>)
Content-Type: application/json
```
Sulkta defaults (per REFERENCE.md): `http://192.168.0.158:8080`, user
`kodi`, password `pineapple`.
## Play by YouTube ID
```bash
curl -u kodi:pineapple -H "Content-Type: application/json" \
-X POST http://192.168.0.158:8080/jsonrpc -d '{
"jsonrpc": "2.0",
"id": 1,
"method": "Player.Open",
"params": {
"item": {
"file": "plugin://plugin.video.torttube/?action=play&id=dQw4w9WgXcQ"
}
}
}'
```
## Play by full URL
```bash
curl -u kodi:pineapple -H "Content-Type: application/json" \
-X POST http://192.168.0.158:8080/jsonrpc -d '{
"jsonrpc": "2.0",
"id": 1,
"method": "Player.Open",
"params": {
"item": {
"file": "plugin://plugin.video.torttube/?action=play&url=https%3A//www.youtube.com/watch%3Fv%3DdQw4w9WgXcQ"
}
}
}'
```
The addon's `_extract_id()` accepts any of:
- bare 11-char ID
- `https://youtu.be/<id>`
- `https://www.youtube.com/watch?v=<id>`
- `https://www.youtube.com/shorts/<id>`
- `https://www.youtube.com/embed/<id>`
- `https://www.youtube.com/live/<id>`
## Android share-target wiring (later)
Future companion app (or HA automation) takes a YouTube URL from the
Android share sheet and posts it to whichever TV is selected. Until
that lands, any HTTP-capable client works (Kore, Yatse, curl, an HA
script, a phone shortcut, etc.).
## Common Kodi JSON-RPC ops you'll want
- `Player.Open` — start playback
- `Player.Stop` — stop
- `Player.PlayPause` — toggle
- `Player.Seek` — jump to position
- `Input.ShowOSD` — bring up the OSD
- `GUI.ShowNotification` — toast a message
Full docs: https://kodi.wiki/view/JSON-RPC_API