the rest of the refactor

This commit is contained in:
2026-04-03 05:16:45 -03:00
parent 130fc5dac2
commit 9dfa252727
5 changed files with 527 additions and 325 deletions

35
cht/session.py Normal file
View File

@@ -0,0 +1,35 @@
"""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