Aege-041-engsub Convert03-08-26 Min -
#
# 2️⃣ Trim (if requested) if trim_start is not None or trim_end is not None: start = trim_start or timedelta(0) end = trim_end or subs[-1].end subs = [s for s in subs if s.start >= start and s.end <= end] AEGE-041-engsub convert03-08-26 Min
# 2b Adjust timestamps so they start at 0 or at the original start offset = start for s in subs: s.start -= offset s.end -= offset # # 2️⃣ Trim (if requested) if trim_start
| Code | Body | Meaning | |------|------|---------| | 400 | "error":"Unsupported file type", "file":"foo.xyz" | Invalid format. | | 422 | "error":"Trim window out of bounds", "detail":"End time exceeds file duration" | Validation. | | 500 | "error":"Conversion failed", "detail":"Parser threw at line 842" | Server side. | 8. Backend Implementation Details | Component | Tech Stack | Key Libraries | |-----------|------------|---------------| | API Gateway | Node.js (Express) or Go (Gin) | multer (multipart), jsonwebtoken | | Conversion Service | Python 3.11 (FastAPI) – stateless | pysrt , ass , webvtt-py , ttml , python‑srt , ffmpeg‑python (only for timestamp arithmetic) | | Storage | AWS S3 (temporary bucket) with lifecycle rule 30 min. | | Queue (optional for large files) | Amazon SQS / RabbitMQ | Workers pull jobs, update progress via WebSocket. | | WebSocket (progress) | Socket.io (if using Node) or FastAPI‑WebSocket | Broadcast requestId updates. | | Auth | Centralised JWT (OAuth2) | Middleware validates sub claim. | | Testing | PyTest (backend), Jest (frontend) | Coverage ≥ 90 %. | Conversion Algorithm (pseudo‑Python) def convert_subtitle(source_bytes, src_fmt, tgt_fmt, trim_start: Optional[timedelta] = None, trim_end: Optional[timedelta] = None) -> bytes: # 1️⃣ Parse source parser = PARSERS[src_fmt] subs = parser.from_bytes(source_bytes) | | WebSocket (progress) | Socket
