diff --git a/main.py b/main.py index 9b147ef..1cf940c 100644 --- a/main.py +++ b/main.py @@ -75,11 +75,19 @@ def run(cmd: List[str], hide_output=True): def download(url: str, dest: Path): console.print(f"[cyan]Скачивание {url} → {dest.name}") - with httpx.stream("GET", url, timeout=30) as r: - r.raise_for_status() - with open(dest, "wb") as f: - for chunk in r.iter_bytes(): - f.write(chunk) + + with httpx.Client(follow_redirects=True, timeout=60.0) as client: + with client.stream("GET", url) as response: + response.raise_for_status() + total = int(response.headers.get("Content-Length", 0)) + + dest.parent.mkdir(parents=True, exist_ok=True) + + with open(dest, "wb") as f, Progress(console=console) as progress: + task = progress.add_task("Загрузка", total=total if total else None) + for chunk in response.iter_bytes(chunk_size=8192): + f.write(chunk) + progress.update(task, advance=len(chunk)) # ======================= INIT ========================= @@ -91,10 +99,9 @@ def init(): if not (TOOLS / "apktool.jar").exists(): download(conf.base.tools.apktool_jar_url, TOOLS / "apktool.jar") - wrapper = httpx.get( - conf.base.tools.apktool_wrapper_url, timeout=30, follow_redirects=True - ).text - (TOOLS / "apktool").write_text(wrapper, encoding="utf-8") + + if not (TOOLS / "apktool").exists(): + download(conf.base.tools.apktool_wrapper_url, TOOLS / "apktool") (TOOLS / "apktool").chmod(0o755) try: