Skip to content

Commit a4a8030

Browse files
authored
Merge pull request #86 from Aidenir/add-headless-cli
Add headless CLI for autonomous subtitle sync pipelines
2 parents 2cb24bf + cdc4ac9 commit a4a8030

11 files changed

Lines changed: 1773 additions & 571 deletions

File tree

Dockerfile.cli

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Slim, headless image for autonomous pipeline use of AutoSubSync.
2+
# Contains only what the CLI needs - no X11, VNC, or Qt display deps.
3+
# main/cli.py is engineered to not load PyQt6 QtWidgets/QtGui at runtime,
4+
# so the slim image works even though PyQt6 is still a transitive install dep.
5+
6+
# --- Builder stage: compile native deps (webrtcvad etc.) ---
7+
FROM python:3.11-slim-bookworm AS builder
8+
9+
ENV PYTHONUNBUFFERED=1 \
10+
PIP_NO_CACHE_DIR=1 \
11+
PIP_DISABLE_PIP_VERSION_CHECK=1
12+
13+
RUN apt-get update && apt-get install -y --no-install-recommends \
14+
build-essential \
15+
&& rm -rf /var/lib/apt/lists/*
16+
17+
WORKDIR /app
18+
COPY pyproject.toml README.md ./
19+
COPY main ./main
20+
RUN python -m pip install --prefix=/install .
21+
22+
# --- Runtime stage: just glibc + libstdc++ + the installed wheels ---
23+
FROM python:3.11-slim-bookworm
24+
25+
ENV PYTHONUNBUFFERED=1
26+
27+
RUN apt-get update && apt-get install -y --no-install-recommends \
28+
ca-certificates \
29+
libstdc++6 \
30+
libglib2.0-0 \
31+
&& rm -rf /var/lib/apt/lists/*
32+
33+
COPY --from=builder /install /usr/local
34+
35+
WORKDIR /data
36+
VOLUME ["/data"]
37+
38+
ENTRYPOINT ["assy-cli"]
39+
CMD ["--help"]

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,59 @@ To access the GUI, open your web browser and go to: [http://localhost:6080](http
157157
4. Select output location
158158
5. Click `Start`
159159

160+
### Command-line interface (`assy-cli`)
161+
162+
For autonomous pipelines, CI/CD, scheduled jobs, and Docker, AutoSubSync ships a
163+
fully-featured CLI that never starts a Qt event loop or requires a display.
164+
165+
```bash
166+
# Auto-sync one subtitle (machine-readable output)
167+
assy-cli sync video.mkv subs.srt -o synced.srt --json
168+
# {"ok": true, "input": "subs.srt", "output": "synced.srt", "tool": "ffsubsync", ...}
169+
170+
# Shift a subtitle by 1.5 seconds
171+
assy-cli shift subs.srt 1500 -o shifted.srt
172+
173+
# Batch sync a folder of pairs and continue past failures
174+
assy-cli batch --folder ./episodes --continue-on-error --json
175+
176+
# Two-folder pairing with explicit output dir
177+
assy-cli batch --video-dir ./videos --subtitle-dir ./subs -o ./out --json
178+
179+
# Pick a sync engine per call
180+
assy-cli sync video.mkv subs.srt -t alass
181+
182+
# Inspect or persist user config
183+
assy-cli config path
184+
assy-cli config get sync_tool
185+
assy-cli config set sync_tool alass
186+
```
187+
188+
| Subcommand | Purpose |
189+
|---|---|
190+
| `sync` | Auto-sync one subtitle to a video or reference subtitle |
191+
| `shift` | Shift subtitle timing by milliseconds |
192+
| `batch` | Process many pairs from `--folder`, `--video-dir`+`--subtitle-dir`, or repeated `--pair` |
193+
| `config` | `get` / `set` / `unset` / `list` / `path` for the user config JSON |
194+
| `version` | Print version |
195+
196+
**Exit codes:** `0` success · `1` at least one sync failed · `2` usage or config error · `130` SIGINT.
197+
198+
**JSON mode** (`--json`) writes structured results to stdout (one object per sync; for `batch`, NDJSON plus a final `{"summary": ...}` line) while human-readable logs go to stderr. Pipe straight into `jq`:
199+
200+
```bash
201+
assy-cli sync video.mkv subs.srt --json | jq -r '.output'
202+
```
203+
204+
**Run from Docker** with no display:
205+
206+
```bash
207+
docker build -f Dockerfile.cli -t autosubsync-cli .
208+
docker run --rm -v "$PWD:/data" autosubsync-cli sync /data/video.mkv /data/subs.srt -o /data/out.srt
209+
```
210+
211+
Or via compose: `docker compose --profile cli run --rm assy-cli sync /data/video.mkv /data/subs.srt`.
212+
160213
## `Features`
161214

162215
### Automatic Synchronization

docker-compose.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,15 @@ services:
1515
- DISPLAY=:0
1616
- QT_QPA_PLATFORM=xcb
1717
restart: unless-stopped
18+
19+
# Headless CLI image for autonomous pipelines.
20+
# Build: docker compose build assy-cli
21+
# Usage: docker compose run --rm assy-cli sync /data/video.mkv /data/sub.srt
22+
assy-cli:
23+
build:
24+
context: .
25+
dockerfile: Dockerfile.cli
26+
image: autosubsync-cli
27+
volumes:
28+
- $PWD:/data
29+
profiles: ["cli"] # only spun up when explicitly invoked

0 commit comments

Comments
 (0)