#!/usr/bin/env python3 """Read scene metadata ONLY from Friction v34, little-endian, 64-bit-qreal files. Does not parse layers, validate the whole project, render, or execute expressions. Unsupported/malformed input is an inspection error, not an agent score. """ import argparse import hashlib import json import math from pathlib import Path import struct class InspectionError(ValueError): pass def inspect(data: bytes) -> dict: if len(data) < 61: raise InspectionError('File too short for the supported header and footer') footer = len(data) - 49 version = struct.unpack_from(' footer: raise InspectionError('Truncated scene metadata') if fmt == '?' and data[offset] not in (0, 1): raise InspectionError('Unsupported boolean representation') value = struct.unpack_from('<' + fmt, data, offset)[0] offset += size return value if read('q') != 0: raise InspectionError('Unexpected initial checkpoint / byte order') count = read('i') if not 0 <= count <= 10000: raise InspectionError('Invalid or unsupported scene count') scenes = [] for index in range(count): current = read('i') clip = read('?') width, height = read('i'), read('i') fps = read('d') start, end = read('i'), read('i') in_enabled, in_frame = read('?'), read('i') out_enabled, out_frame = read('?'), read('i') markers_size = read('i') if markers_size == -1: # Qt null QByteArray markers_size = 0 if markers_size < 0 or offset + markers_size > footer: raise InspectionError('Truncated or invalid marker array') markers = data[offset:offset + markers_size] offset += markers_size if width <= 0 or height <= 0 or not math.isfinite(fps) or fps <= 0 or end < start: raise InspectionError('Invalid scene settings / unsupported binary layout') try: markers_text = markers.decode('utf-8') except UnicodeDecodeError as exc: raise InspectionError('Invalid UTF-8 scene markers') from exc scenes.append({ 'scene_index': index, 'current_frame': current, 'clip_to_canvas': clip, 'width': width, 'height': height, 'fps': fps, 'frame_range_inclusive': [start, end], 'frame_count': end - start + 1, 'duration_seconds': (end - start + 1) / fps, 'in_marker': {'enabled': in_enabled, 'frame': in_frame}, 'out_marker': {'enabled': out_enabled, 'frame': out_frame}, 'markers_raw': markers_text, }) return { 'inspector': 'friction-scene-header-v1', 'scope': 'scene_metadata_only', 'full_project_validity': 'not_checked', 'format_version': version, 'binary_layout': 'little_endian_qreal64', 'artifact_sha256': hashlib.sha256(data).hexdigest(), 'scene_count': count, 'scenes': scenes, 'capabilities': {'scene_settings': True, 'layers': False, 'keyframes': False, 'expressions': False, 'effects': False, 'rendering': False, 'action_history': False}, } def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('project', type=Path) parser.add_argument('--out', type=Path) args = parser.parse_args() try: result = inspect(args.project.read_bytes()) except (OSError, InspectionError) as exc: parser.exit(2, f'Inspection error: {exc}\n') output = json.dumps(result, indent=2) + '\n' if args.out: args.out.write_text(output) else: print(output, end='') if __name__ == '__main__': main()