97 lines
3.6 KiB
Python
97 lines
3.6 KiB
Python
"Independent original bytes and every physical boundary; no layout mapping."
|
|
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[3]
|
|
OUT = Path(__file__).resolve().parent
|
|
PATH = (
|
|
"example_ComfyUI_workflows/5-数字人/"
|
|
"Wan2.1_infinitetalk_音频驱动视频配音-单人for循环长视频(官流).json"
|
|
)
|
|
|
|
|
|
def inventory():
|
|
raw = (ROOT / PATH).read_bytes()
|
|
g = json.loads(raw)
|
|
(fields, empty, notes, scopes) = ([], [], [], [])
|
|
graphs = [("", g)] + [
|
|
(f"/definitions/subgraphs/{i}", s)
|
|
for (i, s) in enumerate(g.get("definitions", {}).get("subgraphs", []))
|
|
]
|
|
for prefix, graph in graphs:
|
|
scopes.append(
|
|
dict(
|
|
pointer=prefix or "/",
|
|
nodes=len(graph["nodes"]),
|
|
edges=len(graph["links"]),
|
|
modes=[n["mode"] for n in graph["nodes"]],
|
|
named_nodes=sum(("widgets_values_named" in n for n in graph["nodes"])),
|
|
)
|
|
)
|
|
for i, n in enumerate(graph["nodes"]):
|
|
p = f"{prefix}/nodes/{i}"
|
|
if "widgets_values" not in n or n["widgets_values"] in [None, []]:
|
|
empty.append(
|
|
dict(
|
|
node=n["id"],
|
|
pointer=p,
|
|
state="missing"
|
|
if "widgets_values" not in n
|
|
else "null"
|
|
if n["widgets_values"] is None
|
|
else "empty_list",
|
|
)
|
|
)
|
|
if n["type"] in ["Note", "MarkdownNote"]:
|
|
notes.append(
|
|
dict(
|
|
node=n["id"],
|
|
pointer=p + "/widgets_values/0",
|
|
text=n["widgets_values"][0],
|
|
characters=len(n["widgets_values"][0]),
|
|
lf_count=n["widgets_values"][0].count("\n"),
|
|
literal_backslash_n=n["widgets_values"][0].count("\\n"),
|
|
ends_with_lf=n["widgets_values"][0].endswith("\n"),
|
|
named=n.get("widgets_values_named"),
|
|
)
|
|
)
|
|
continue
|
|
saved = n.get("widgets_values") or []
|
|
entries = saved.items() if isinstance(saved, dict) else enumerate(saved)
|
|
for j, v in entries:
|
|
fields.append(
|
|
dict(
|
|
node=n["id"],
|
|
pointer=f"{p}/widgets_values/{j}",
|
|
value=v,
|
|
json_type=type(v).__name__,
|
|
scope="root" if not prefix else prefix,
|
|
named=n.get("widgets_values_named"),
|
|
)
|
|
)
|
|
return dict(
|
|
path=PATH,
|
|
sha256=hashlib.sha256(raw).hexdigest(),
|
|
git_blob_sha1=hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\x00" + raw).hexdigest(),
|
|
fields=fields,
|
|
empty=empty,
|
|
notes=notes,
|
|
scopes=scopes,
|
|
extra=g["extra"],
|
|
hosts=[n for n in g["nodes"] if n["type"] not in ["Note", "MarkdownNote"]],
|
|
definition_boundary=[
|
|
{k: s[k] for k in ["id", "inputNode", "outputNode", "inputs", "outputs", "widgets"]}
|
|
for s in g.get("definitions", {}).get("subgraphs", [])
|
|
],
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
x = inventory()
|
|
(OUT / "independent-inventory.json").write_text(
|
|
json.dumps(x, ensure_ascii=False, indent=2) + "\n"
|
|
)
|
|
print("Saved", len(x["fields"]), "notes", len(x["notes"]), "scopes", x["scopes"])
|