Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from bundle
Build or revise a reusable FFmpeg timeline for short-form video editing. Use when the user wants an agent-editable API for trimming clips, cropping, fitting to
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
scripts/video_timeline_editor/infrastructure/transcripts.py
1from __future__ import annotations23import json4from pathlib import Path56from video_timeline_editor.domain.model import CaptionTrack, WordToken789def resolve_path(value: str | Path, base_dir: Path) -> Path:10path = Path(value)11return path if path.is_absolute() else (base_dir / path).resolve()121314def load_transcript_words(track: CaptionTrack, timeline_dir: Path) -> tuple[WordToken, ...]:15transcript_path = resolve_path(track.transcript, timeline_dir)16if not transcript_path.exists():17raise FileNotFoundError(f"Missing transcript {transcript_path}")18payload = json.loads(transcript_path.read_text())19words: list[WordToken] = []20replacements = dict(track.replacements)21skipped = set(track.skip_tokens)22offset = float(track.source_offset)23for item in payload.get("words", []):24if item.get("type") != "word":25continue26text = str(item.get("text", "")).strip()27if not text or text in skipped:28continue29text = replacements.get(text, text)30words.append(31WordToken(32text=text,33start=float(item["start"]) + offset,34end=float(item["end"]) + offset,35)36)37return tuple(words)38