import json import hashlib import pathlib import sys import bpy def strip_state(strip): return { "name": strip.name, "type": strip.type, "channel": strip.channel, "start": strip.frame_final_start, "end": strip.frame_final_end, "sourceStart": strip.frame_offset_start, "sourceEnd": strip.frame_offset_end, "muted": strip.mute, "locked": strip.lock, "inputs": [getattr(strip, key).name for key in ("input_1", "input_2") if getattr(strip, key, None)], "children": sorted((strip_state(child) for child in strip.strips), key=lambda child: child["name"]) if strip.type == "META" else [], "source": { "sound": strip.sound.filepath if strip.type == "SOUND" and strip.sound else None, "movie": strip.filepath if strip.type == "MOVIE" else None, "scene": strip.scene.name if strip.type == "SCENE" and strip.scene else None, "directory": strip.directory if strip.type == "IMAGE" else None, "images": [element.filename for element in strip.elements] if strip.type == "IMAGE" else [], }, } directory = pathlib.Path(sys.argv[sys.argv.index("--") + 1]) snapshots = {} for blend in sorted(directory.glob("*.blend")): bpy.ops.wm.open_mainfile(filepath=str(blend)) snapshots[blend.stem] = { scene.name: sorted((strip_state(strip) for strip in scene.sequence_editor.strips), key=lambda strip: strip["name"]) if scene.sequence_editor else [] for scene in bpy.data.scenes } snapshots[blend.stem]["__soundData"] = sorted(({ "name": sound.name, "path": sound.filepath, "users": sound.users, "packedSha256": hashlib.sha256(sound.packed_file.data).hexdigest() if sound.packed_file else None, } for sound in bpy.data.sounds), key=lambda sound: sound["name"]) (directory / "native-sequencer-snapshots.json").write_text( json.dumps(snapshots, indent=2, sort_keys=True) + "\n")