Showing posts with label Kodi. Show all posts
Showing posts with label Kodi. Show all posts

Sunday, May 25, 2025

How to Configure an Nginx Reverse Proxy with WebSockets for Kodi Chorus2

This tutorial details how to configure Nginx as a secure reverse proxy for Kodi's Chorus2 web interface, enabling full remote media playback control over HTTPS under a subpath (e.g., https://domain.com/kodi/).

Before configuring Nginx, enable the Kodi Web Server in Settings → Services → Control and set a secure username and password, as documented in the Kodi Web Interface Wiki.

The Nginx URI Normalization Challenge

Kodi Chorus2 requires two distinct routing configurations:

  1. WebSocket JSON-RPC (port 9090): Real-time playback status and control events route through /jsonrpc without path prefixing.
  2. Web Assets & Album Art (port 10080 / 8080): Chorus2 fetches album artwork and movie posters using dynamic queries. Under Nginx's proxy_pass specification, naive subpath proxying will corrupt the image query string unless the normalized request URI is explicitly matched and forwarded.

Nginx Configuration (/etc/nginx/sites-available/kodi.conf)

Add the following location blocks to your Nginx HTTPS server block:

## Kodi Reverse Proxy Configuration

# 1) WebSocket channel for JSON-RPC
location ^~ /jsonrpc {
    proxy_http_version 1.1;
    proxy_set_header   Upgrade    $http_upgrade;
    proxy_set_header   Connection "Upgrade";
    proxy_set_header   Host       $host;
    proxy_set_header   X-Real-IP  $remote_addr;
    proxy_read_timeout 360s;
    proxy_pass         http://10.10.1.5:9090;
}

# 2) Redirect bare /kodi to canonical /kodi/
location = /kodi {
    return 301 /kodi/;
}

# 3) Proxy Chorus2 web interface and strip /kodi prefix
location /kodi/ {
    if ($request_uri ~ "^/kodi(?/[^?]*)") {
        set $new_path $after;
    }

    proxy_cache        off;
    proxy_set_header   Host      $host;
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_read_timeout 300s;

    proxy_pass         http://10.10.1.5:10080$new_path$is_args$args;
}

Test your configuration and reload Nginx:

sudo nginx -t
sudo systemctl reload nginx

In Chorus2 settings (in your browser), enable reverse proxy mode and set the port to 443. Album art, audio streaming, and WebSocket playback controls will now operate flawlessly.

Friday, February 21, 2025

How to Set Up Kodi 21 with YouTube Add-on and HDMI-CEC on Raspberry Pi 5

This guide covers how to set up Kodi 21 (Omega) with the unofficial YouTube Add-on, Chorus2 web interface, and intelligent HDMI-CEC control on a Raspberry Pi 5 running Raspberry Pi OS (Debian 12/13).

1. Installing Kodi 21

Raspberry Pi repositories provide both kodi (v20) and kodi21 (v21 Omega). Install Kodi 21 along with the adaptive streaming library to prevent playback stuttering:

sudo apt-get update
sudo apt-get install kodi21 kodi21-inputstream-adaptive -y

2. Installing the Unofficial YouTube Plugin

cd ~/Downloads
wget https://ftp.fau.de/osmc/osmc/download/dev/anxdpanic/repositories/repository.yt.testing_unofficial-2.0.7.zip
  1. In Kodi: Settings → Add-ons → Install from zip file → Home folder → Downloads → repository.yt.testing_unofficial-2.0.7.zip.
  2. Under Add-ons, open the context menu / options at bottom left and select Check for updates.
  3. Select Install from repository → YouTube Test Repo (Unofficial) → Video add-ons → YouTube → Install.

3. YouTube Personal API v3 Keys

To avoid hitting shared API quota limits, generate personal Google Cloud credentials (Setup Guide):

  • Create a project in Google Cloud Console with YouTube Data API v3 enabled.
  • Create an OAuth 2.0 Client ID (Application type: TV and Limited Input devices) and an API Key. Ensure the Publishing Status in OAuth Consent Screen is set to Production.
  • In Kodi: YouTube → Settings → API and enter your API Key, Client ID, and Client Secret.

4. Installing the Chorus2 Web Interface

Install the latest Chorus2 web control interface:

tmp="$(mktemp -d)"
curl -L -o "$tmp/chorus2.zip" https://github.com/xbmc/chorus2/archive/refs/heads/master.zip
unzip -q "$tmp/chorus2.zip" -d "$tmp"

mkdir -p ~/.kodi/addons
rm -rf ~/.kodi/addons/webinterface.default.new
cp -a "$tmp"/chorus2-master/dist ~/.kodi/addons/webinterface.default.new

if [ -d ~/.kodi/addons/webinterface.default ]; then
  mv ~/.kodi/addons/webinterface.default ~/.kodi/addons/webinterface.default.bak.$(date +%Y%m%d-%H%M%S)
fi

mv ~/.kodi/addons/webinterface.default.new ~/.kodi/addons/webinterface.default
rm -rf "$tmp"

5. Fine-Tuning HDMI-CEC Power Behavior

To prevent your Raspberry Pi from turning on your TV every time it reboots, add this parameter to /boot/firmware/config.txt:

hdmi_ignore_cec_init=1

Configure automatic playback pausing in Kodi when you switch TV inputs or turn off the screen:

  • Navigate to: Kodi → Settings → System → Input → Peripherals → CEC Adapter
  • Set Action when switching to another source → Stop playback
  • Set When the TV is switched off → Stop playback

6. Wayland Autostart / Remote Launch Script (/scripts/youtube.py)

To launch Kodi remotely over SSH, DBus, or a Telegram bot under Wayland without display collisions:

#!/usr/bin/env python3
import os

os.chdir('/home/pi')
os.environ["DISPLAY"] = ":0"
os.environ["WAYLAND_DISPLAY"] = "wayland-0"
os.environ["XDG_RUNTIME_DIR"] = "/run/user/1000"
os.environ["DBUS_SESSION_BUS_ADDRESS"] = "unix:path=/run/user/1000/bus"

# Terminate competing browser windows before launching media center
os.system("pkill -9 -f 'chrome|chromium|google-chrome|kodi|kodi21.bin'")
os.system('/usr/bin/kodi &')

How Google Antigravity Solved the Mysterious NVIDIA Sleep Reboot on My Dell Inspiron 7567 (Ubuntu Linux)

If you run modern Ubuntu or Linux on a Dell Inspiron 15 Gaming (7567) or a similar 7th-gen Intel laptop paired with an NVIDIA GeForce GTX ...