HEL-892: add source-bound reverse-video Chinese reference document
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
"""Fetch fixed source text and registry archive; never import upstream code."""
|
||||
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
import subprocess
|
||||
import urllib.request
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
|
||||
OUT = Path(__file__).resolve().parent.parent / "reverse-reference"
|
||||
FILES = {
|
||||
"kj": (
|
||||
"kijai/ComfyUI-KJNodes",
|
||||
"c661baadd9683c0033cd2a6ad90157c6d099a6c2",
|
||||
["LICENSE", "__init__.py", "nodes/image_nodes.py", "pyproject.toml"],
|
||||
),
|
||||
"core": ("Comfy-Org/ComfyUI", "v0.3.75", ["LICENSE", "nodes.py"]),
|
||||
}
|
||||
|
||||
VHS = [
|
||||
"LICENSE",
|
||||
"__init__.py",
|
||||
"pyproject.toml",
|
||||
"videohelpersuite/nodes.py",
|
||||
"videohelpersuite/load_video_nodes.py",
|
||||
"videohelpersuite/utils.py",
|
||||
"video_formats/h264-mp4.json",
|
||||
"web/js/VHS.core.js",
|
||||
"web/js/videoinfo.js",
|
||||
]
|
||||
|
||||
|
||||
def get(url):
|
||||
return urllib.request.urlopen(
|
||||
urllib.request.Request(url, headers={"User-Agent": "static-reference"}), timeout=30
|
||||
).read()
|
||||
|
||||
|
||||
def main():
|
||||
OUT.mkdir(exist_ok=True)
|
||||
sources, identities = [], []
|
||||
for key, (repo, revision, files) in FILES.items():
|
||||
if revision.startswith("v"):
|
||||
raw = subprocess.check_output(
|
||||
[
|
||||
"git",
|
||||
"ls-remote",
|
||||
"https://github.com/" + repo + ".git",
|
||||
"refs/tags/" + revision,
|
||||
],
|
||||
timeout=45,
|
||||
)
|
||||
commit = raw.decode().split()[0]
|
||||
(OUT / (key + "-tag.txt")).write_bytes(raw)
|
||||
else:
|
||||
commit = revision
|
||||
url = f"https://github.com/{repo}/commit/{commit}.patch"
|
||||
raw = get(url)
|
||||
assert b"diff --git" in raw
|
||||
(OUT / (key + "-commit.patch")).write_bytes(raw)
|
||||
identities.append(
|
||||
dict(repo=repo, id=key, revision=revision, commit=commit, installed=False)
|
||||
)
|
||||
for file in files:
|
||||
url = f"https://raw.githubusercontent.com/{repo}/{commit}/{file}"
|
||||
raw = get(url)
|
||||
local = key + "__" + file.replace("/", "__")
|
||||
(OUT / local).write_bytes(raw)
|
||||
sources.append(
|
||||
dict(
|
||||
id=key,
|
||||
file=file,
|
||||
local_file=local,
|
||||
url=url,
|
||||
commit=commit,
|
||||
sha256=hashlib.sha256(raw).hexdigest(),
|
||||
)
|
||||
)
|
||||
url = "https://api.comfy.org/nodes/comfyui-videohelpersuite/versions/1.7.7"
|
||||
raw = get(url)
|
||||
(OUT / "vhs-registry.json").write_bytes(raw)
|
||||
release = json.loads(raw)
|
||||
raw = get(release["downloadUrl"])
|
||||
(OUT / "vhs-1.7.7.zip").write_bytes(raw)
|
||||
sha = hashlib.sha256(raw).hexdigest()
|
||||
with zipfile.ZipFile(io.BytesIO(raw)) as z:
|
||||
members = [
|
||||
dict(file=n, sha256=hashlib.sha256(z.read(n)).hexdigest())
|
||||
for n in z.namelist()
|
||||
if not n.endswith("/")
|
||||
]
|
||||
for file in VHS:
|
||||
raw = z.read(file)
|
||||
local = "vhs__" + file.replace("/", "__")
|
||||
(OUT / local).write_bytes(raw)
|
||||
sources.append(
|
||||
dict(
|
||||
id="vhs",
|
||||
file=file,
|
||||
local_file=local,
|
||||
url=release["downloadUrl"],
|
||||
commit="发布包SHA256:" + sha,
|
||||
sha256=hashlib.sha256(raw).hexdigest(),
|
||||
git_commit_binding="unknown",
|
||||
)
|
||||
)
|
||||
(OUT / "vhs-package-index.json").write_text(
|
||||
json.dumps(
|
||||
dict(
|
||||
url=release["downloadUrl"],
|
||||
sha256=sha,
|
||||
members=members,
|
||||
git_commit_binding="unknown",
|
||||
note="发布包同字节不等于提交绑定",
|
||||
),
|
||||
ensure_ascii=False,
|
||||
indent=2,
|
||||
)
|
||||
+ "\n"
|
||||
)
|
||||
identities.append(
|
||||
dict(
|
||||
id="vhs",
|
||||
version="1.7.7",
|
||||
package_sha256=sha,
|
||||
git_commit_binding="unknown",
|
||||
installed=False,
|
||||
)
|
||||
)
|
||||
(OUT / "sources.json").write_text(
|
||||
json.dumps(dict(sources=sources), ensure_ascii=False, indent=2) + "\n"
|
||||
)
|
||||
(OUT / "identity.json").write_text(json.dumps(identities, ensure_ascii=False, indent=2) + "\n")
|
||||
print("Fixed KJ, core0.3.75 and VHS1.7.7 package source text only")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user