Files
aigc-home/docs/hel-892/simple-vfi-document-evidence/fetch_packages.py
T

90 lines
3.4 KiB
Python

"""Bounded exact release text retrieval; no import, installation or execution."""
import hashlib
import io
import json
import urllib.request
import zipfile
from pathlib import Path
REF = Path(__file__).resolve().parent.parent / "simple-vfi-reference"
def main():
entries = json.loads((REF / "sources.json").read_bytes())["sources"]
entries = [e for e in entries if e["id"] not in ["rife", "essentials", "impact", "vhs"]]
for key, wanted in {
"rife": [
"__init__.py",
"vfi_models/rife/__init__.py",
"vfi_models/rife/rife_arch.py",
"vfi_utils.py",
"LICENSE",
"pyproject.toml",
],
"essentials": ["__init__.py", "image.py", "LICENSE", "pyproject.toml"],
"impact": ["__init__.py", "modules/impact/util_nodes.py", "LICENSE.txt", "pyproject.toml"],
"vhs": [
"__init__.py",
"videohelpersuite/nodes.py",
"videohelpersuite/load_video_nodes.py",
"videohelpersuite/utils.py",
"web/js/VHS.core.js",
"video_formats/h264-mp4.json",
"LICENSE",
"pyproject.toml",
],
}.items():
if key == "impact":
raw = (REF.parent / "resize-compare-reference/impact-source.zip").read_bytes()
meta = json.loads(
(REF.parent / "resize-compare-reference/impact-registry.json").read_bytes()
)
elif key == "vhs":
raw = (REF.parent / "reverse-reference/vhs-1.7.7.zip").read_bytes()
meta = json.loads((REF.parent / "reverse-reference/vhs-registry.json").read_bytes())
else:
meta = json.loads((REF / (key + "-registry.json")).read_bytes())
archive = REF / (key + ("-source.tar.gz" if key == "essentials" else "-source.zip"))
if archive.exists():
raw = archive.read_bytes()
else:
with urllib.request.urlopen(meta["downloadUrl"], timeout=40) as r:
raw = r.read(20000001)
assert len(raw) < 20000000
(REF / (key + ("-source.tar.gz" if key == "essentials" else "-source.zip"))).write_bytes(
raw
)
(REF / (key + "-registry.json")).write_text(json.dumps(meta, indent=2) + "\n")
sha = hashlib.sha256(raw).hexdigest()
with zipfile.ZipFile(io.BytesIO(raw)) as z:
names = z.namelist()
(REF / (key + "-members.json")).write_text(json.dumps(names, indent=2) + "\n")
for file in wanted:
if file not in names:
print("MISSING", key, file)
continue
b = z.read(file)
name = key + "__" + file.replace("/", "__")
(REF / name).write_bytes(b)
entries.append(
dict(
id=key,
file=file,
local_file=name,
url=meta["downloadUrl"],
commit="发布包SHA256:" + sha,
git_commit_binding="unknown",
package_sha256=sha,
sha256=hashlib.sha256(b).hexdigest(),
)
)
print(key, sha)
(REF / "sources.json").write_text(
json.dumps(dict(sources=entries), ensure_ascii=False, indent=2) + "\n"
)
if __name__ == "__main__":
main()