"""Session data loading — reads frame/transcript indexes, returns plain data.""" import json import logging from pathlib import Path log = logging.getLogger(__name__) def load_frame_index(frames_dir: Path) -> list[dict]: """Read frames/index.json and return list of {id, path, timestamp}. Returns only entries where the image file exists on disk. Paths are resolved relative to *frames_dir* if needed. """ index_path = frames_dir / "index.json" if not index_path.exists(): return [] try: index = json.loads(index_path.read_text()) except (json.JSONDecodeError, IOError): return [] result = [] for entry in index: fpath = Path(entry["path"]) if not fpath.exists(): fpath = frames_dir / fpath.name if not fpath.exists(): continue result.append({ "id": entry["id"], "path": fpath, "timestamp": entry.get("timestamp", 0), }) return result