Hooks and webhooks
Every change to watch history, when a video starts, progresses or finishes, can run local scripts and call webhooks. Use it to sync progress to another app, scrobble, or keep a log.
Mount a directory of executables into the app container and point OwnTube at it:
services: app: environment: OWNTUBE_HOOKS_DIR: /app/apps/web/data/hooks volumes: - ./hooks:/app/apps/web/data/hooks:roEach executable runs once per event, in name order. It gets the event as environment variables and as JSON on standard input:
| Variable | Value |
|---|---|
OT_EVENT |
watched or progress |
OT_VIDEO_ID, OT_CHANNEL_ID |
YouTube IDs |
OT_POSITION_SECONDS |
Position in the video |
OT_DURATION_SECONDS |
Length; 0 if unknown |
OT_COMPLETED |
true or false |
OT_VIDEO_TITLE, OT_CHANNEL_NAME |
May be empty |
OT_SOURCE |
live, or replay for the periodic re-delivery |
OT_AT |
Unix time |
A minimal hook:
#!/bin/sh[ "$OT_COMPLETED" = true ] || exit 0echo "$OT_AT $OT_VIDEO_ID $OT_VIDEO_TITLE" >> /app/apps/web/data/watched.logA hook that fails or takes longer than OWNTUBE_HOOK_TIMEOUT_MS (30 seconds) is logged and never holds up playback or other hooks. Shorts are not reported.
Webhooks
Section titled “Webhooks”To receive the same events over HTTP, for example in n8n or Home Assistant, list one or more URLs:
OWNTUBE_WEBHOOK_URLS=https://n8n.example.org/webhook/owntubeOWNTUBE_WEBHOOK_TOKEN=<a random value>Each event is POSTed as JSON, with the token in the X-Webhook-Token header so the receiver can check the sender.