58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
"""从 PBZ-Editor 发行包里抽出 MIT 授权的 Oodle Kraken 解码器。
|
||
|
||
本仓库不直接分发 pbz_codec.dll 二进制,用这个脚本按需获取。
|
||
下载约 43MB,支持断点续传;只抽取那一个 DLL,其余丢弃。
|
||
"""
|
||
import sys
|
||
import urllib.request
|
||
import zipfile
|
||
from pathlib import Path
|
||
|
||
ROOT = Path(__file__).resolve().parent
|
||
URL = ("https://github.com/qry6868/PBZ-Editor/releases/download/"
|
||
"v0.3.1/PBZ-Editor-0.3.1-windows-x64.zip")
|
||
TOTAL = 43784872
|
||
TMP = ROOT / ".codec.zip"
|
||
|
||
|
||
def main():
|
||
for attempt in range(60):
|
||
have = TMP.stat().st_size if TMP.exists() else 0
|
||
if have >= TOTAL:
|
||
break
|
||
req = urllib.request.Request(URL, headers={
|
||
"User-Agent": "Mozilla/5.0", "Range": f"bytes={have}-"})
|
||
try:
|
||
with urllib.request.urlopen(req, timeout=60) as r:
|
||
mode = "ab" if have and r.status == 206 else "wb"
|
||
if mode == "wb":
|
||
have = 0
|
||
with TMP.open(mode) as f:
|
||
while True:
|
||
chunk = r.read(1 << 16)
|
||
if not chunk:
|
||
break
|
||
f.write(chunk)
|
||
print(f" {TMP.stat().st_size}/{TOTAL}", flush=True)
|
||
except Exception as e:
|
||
print(f" 重试 {attempt}: {type(e).__name__}", flush=True)
|
||
|
||
size = TMP.stat().st_size if TMP.exists() else 0
|
||
if size < TOTAL:
|
||
sys.exit(f"下载不完整({size}/{TOTAL}),请重试")
|
||
|
||
with zipfile.ZipFile(TMP) as z:
|
||
for n in z.namelist():
|
||
if n.endswith("pbz_codec.dll"):
|
||
dst = ROOT / "pbz_codec.dll"
|
||
dst.write_bytes(z.read(n))
|
||
print(f"已保存 {dst}({dst.stat().st_size} 字节)")
|
||
break
|
||
else:
|
||
sys.exit("压缩包里没找到 pbz_codec.dll")
|
||
TMP.unlink(missing_ok=True)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|