ndurner's picture
improve logging
bea5e12
"""Manual slide extraction helper.
Run slide extraction against a local video using the same pipeline the MCP
server uses. Useful for debugging model responses when no slides are returned.
"""
from __future__ import annotations
import argparse
import sys
from pathlib import Path
from .logging_utils import configure_logging
from .media_tools import _build_reference, _extract_slides_flow, _probe_duration, _slides_json_path
def main(argv: list[str] | None = None) -> int:
configure_logging()
parser = argparse.ArgumentParser(description="Extract slides from a video using the Gemini pipeline.")
parser.add_argument("video", type=Path, help="Path to the video file (mp4 recommended).")
parser.add_argument(
"--reference",
help="Reference id to use for cache/output. Defaults to one derived from the filename.",
)
parser.add_argument(
"--duration",
type=float,
help="Override duration in seconds (optional). If omitted, ffprobe is used.",
)
args = parser.parse_args(argv)
video_path: Path = args.video.expanduser().resolve()
if not video_path.exists():
parser.error(f"Video not found: {video_path}")
reference = args.reference or _build_reference(None, str(video_path))
duration = args.duration or _probe_duration(video_path)
metadata = {
"reference": reference,
"download_path": str(video_path),
"duration": duration,
"source": str(video_path),
}
try:
result = _extract_slides_flow(metadata)
except Exception as exc: # pragma: no cover - CLI convenience
print(f"[error] slide extraction failed: {exc}", file=sys.stderr)
return 1
slides = result.get("slides", [])
print(f"Extracted {len(slides)} slides for reference '{reference}'.")
if slides:
print("First few slides:")
for slide in slides[:5]:
start = slide.get("from")
end = slide.get("to")
label = slide.get("label") or ""
print(f" index={slide.get('index')} from={start:.2f}s to={end:.2f}s label={label}")
slides_json = _slides_json_path(reference)
print(f"Slides JSON saved to {slides_json}")
return 0
if __name__ == "__main__": # pragma: no cover - CLI execution
raise SystemExit(main())