Files
aigc-home/docs/hel-892/seedvr2-video-document-evidence/fetch_sources.py
T

76 lines
2.4 KiB
Python

"""Fetch bounded exact 0.28.1 video/switch text only; never execute upstream."""
import hashlib
import json
import urllib.request
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path
REF = Path(__file__).resolve().parent.parent / "seedvr2-video-reference"
REPO = "Comfy-Org/ComfyUI"
FILES = [
"comfy_extras/nodes_video.py",
"comfy_extras/nodes_logic.py",
"comfy_api/input_impl/video_types.py",
"comfy_api/input/video_types.py",
"comfy_api/latest/_io.py",
"comfy_api/latest/_ui.py",
"nodes.py",
"LICENSE",
"comfy_api/latest/_input_impl/video_types.py",
"comfy_api/latest/_input/video_types.py",
"comfy_api/latest/_util/video_types.py",
]
def get(url):
with urllib.request.urlopen(url, timeout=45) as r:
b = r.read(3000001)
assert len(b) < 3000000
return b
def main():
raw = get(f"https://api.github.com/repos/{REPO}/git/ref/tags/v0.28.1")
(REF / "video-tag.json").write_bytes(raw)
tag = json.loads(raw)["object"]
assert tag["type"] == "commit"
commit = tag["sha"]
assert commit == "87a003e0c975b8f13e2d4067dd0710e56edd7ba5", "Tag binding changed"
print("exact core 0.28.1", commit, flush=True)
raw = get(f"https://api.github.com/repos/{REPO}/git/trees/{commit}?recursive=1")
(REF / "video-tree.json").write_bytes(raw)
tree = json.loads(raw)
assert not tree["truncated"] and tree["sha"] == commit
paths = {e["path"]: e for e in tree["tree"] if e["type"] == "blob"}
print(
"relevant paths",
[p for p in paths if any(s in p for s in ["video_types", "nodes_logic", "nodes_video"])],
flush=True,
)
def fetch(p):
url = f"https://raw.githubusercontent.com/{REPO}/{commit}/{p}"
b = get(url)
blob = hashlib.sha1(b"blob " + str(len(b)).encode() + b"\0" + b).hexdigest()
assert blob == paths[p]["sha"]
name = "video__" + p.replace("/", "__")
(REF / name).write_bytes(b)
return dict(
id="video",
file=p,
local_file=name,
url=url,
commit=commit,
sha256=hashlib.sha256(b).hexdigest(),
git_blob_sha1=blob,
)
with ThreadPoolExecutor(max_workers=4) as pool:
entries = list(pool.map(fetch, [p for p in FILES if p in paths]))
(REF / "sources.json").write_text(json.dumps(dict(sources=entries), indent=2) + "\n")
if __name__ == "__main__":
main()