# betaflix-catalog Flask service that receives Sonarr/Radarr **OnImport** webhooks and commits catalog updates to `git.s8n.ru/s8n/beta-flix`. ## What it does For each `Import` event: 1. Pulls latest `main` of `beta-flix` (rebase). 2. Inserts a row into `playbooks/import-media/MEDIA-LIST.md`, alphabetic by title. Dedupes — if the key (`Title (Year)`) already exists, it skips. 3. Writes a per-import run log to `playbooks/import-media/runs/.md` using the Jinja template at `templates/run.md.j2`. 4. Commits as `obsidian-ai `. 5. Pushes to Forgejo using `FORGEJO_PUSH_TOKEN` embedded in the URL. Idempotency: payload-hash cache at `/state/seen-imports.json`. Sonarr/Radarr retry transient failures; duplicates are no-ops. ## Endpoints - `POST /sonarr` — Sonarr Connect webhook target. Set Sonarr → Settings → Connect → Webhook → URL `http://host.docker.internal:5055/sonarr`, method POST, triggers: **On Import** only. - `POST /radarr` — same shape for Radarr at `/radarr`. - `GET /healthz` — liveness probe. ## Build ```bash cd catalog/ docker build -t betaflix-catalog:local . ``` Or use compose: the parent `compose/docker-compose.yml` defines the `betaflix-catalog` service with `build:` set to this directory. ## Env vars | Variable | Required | Default | What | |----------------------|----------|--------------------------------------------|---------------------------------------| | `FORGEJO_REMOTE` | yes | `https://git.s8n.ru/s8n/beta-flix.git` | Push target. | | `FORGEJO_PUSH_TOKEN` | yes | (empty) | Forgejo PAT — scopes: repository RW. | | `GIT_AUTHOR_NAME` | no | `obsidian-ai` | Commit author. | | `GIT_AUTHOR_EMAIL` | no | `obsidian-ai@s8n.ru` | Commit author email. | | `REPO_PATH` | no | `/repo` | Where beta-flix gets cloned. | | `STATE_DIR` | no | `/state` | seen-imports.json lives here. | | `LISTEN_PORT` | no | `5055` | Flask bind port. | ## Volumes - `/repo` — beta-flix checkout. Bind-mounted persistent volume. - `/state` — `seen-imports.json` cache. - `/root/.ssh` (optional, read-only) — for SSH deploy key (currently uses HTTPS+PAT; SSH path reserved for future). ## Development Run locally without Docker: ```bash cd catalog/ python -m venv .venv && . .venv/bin/activate pip install -r requirements.txt REPO_PATH=/tmp/beta-flix-test STATE_DIR=/tmp/catalog-state \ FORGEJO_PUSH_TOKEN=xxx python catalog.py # In another shell: curl -X POST http://localhost:5055/sonarr \ -H 'Content-Type: application/json' \ -d '{"eventType":"Test"}' ```