import json import os import glob session_file = '/Users/logchen/Documents/github/VideoClaw/video-claw/video-claw/backend/code/data/sessions/1782135655622.json' with open(session_file, 'r', encoding='utf-8') as f: data = json.load(f) changed = False # Fix reference_generation if "reference_generation" in data.get("artifacts", {}): scenes = data["artifacts"]["reference_generation"].get("scenes", []) for scene in scenes: if scene.get("status") == "running": # Check if there are files shot_id = scene["id"] scenes_dir = os.path.join('/Users/logchen/Documents/github/VideoClaw/video-claw/video-claw/backend/code/result/image/1782135655622/Scenes') pattern = os.path.join(scenes_dir, f"{shot_id}*.*") files = [] for ext in ("jpg", "jpeg", "png", "webp", "bmp"): pattern = os.path.join(scenes_dir, f"{shot_id}*.{ext}") files.extend(glob.glob(pattern)) if files: files = sorted(set(files), key=os.path.getmtime) # Map paths to relative or absolute as they are normally stored # reference_agent stores absolute paths? No, it uses os.path.join which might be relative # Let's see what is stored in selected: # 'code/result/image/1782135655622/Scenes/seg_02_01.jpg' # We need to construct relative path rel_files = [] for f in files: rel_files.append(f.replace('/Users/logchen/Documents/github/VideoClaw/video-claw/video-claw/backend/', '')) scene["versions"] = rel_files scene["selected"] = rel_files[-1] scene["status"] = "done" else: scene["status"] = "failed" changed = True if changed: with open(session_file, 'w', encoding='utf-8') as f: json.dump(data, f, ensure_ascii=False, indent=2) print("Fixed!") else: print("No changes needed.")