From 043a0301f1f38e02d88f820d46a67dc4cd601fee Mon Sep 17 00:00:00 2001 From: Tomuxs Date: Mon, 19 May 2025 03:42:31 +0200 Subject: [PATCH] Initial commit --- .gitignore | 6 ++++++ dhere/__main__.py | 17 +++++++++++++++++ dhere/http.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 .gitignore create mode 100644 dhere/__main__.py create mode 100644 dhere/http.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fb78577 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +# Python cache +__pycache__/ + +# Python virtual environment +venv/ +env/ \ No newline at end of file diff --git a/dhere/__main__.py b/dhere/__main__.py new file mode 100644 index 0000000..cf8d996 --- /dev/null +++ b/dhere/__main__.py @@ -0,0 +1,17 @@ +from .http import download, failed +from concurrent.futures import ThreadPoolExecutor +import pyperclip + + +if __name__ == "__main__": + with ThreadPoolExecutor(max_workers=5) as exe: + for line in pyperclip.paste().splitlines(): + line = line.strip() + if line == "": + continue + exe.submit(download, line) + + if len(failed) != 0: + with open("failed.log", "w") as file: + for url in failed: + file.write(url+"\n") \ No newline at end of file diff --git a/dhere/http.py b/dhere/http.py new file mode 100644 index 0000000..35e4b30 --- /dev/null +++ b/dhere/http.py @@ -0,0 +1,28 @@ +import threading +import cloudscraper +from tqdm import tqdm +from time import sleep + + +scraper = cloudscraper.CloudScraper() +failed = [] + + +def download(url: str): + try: + filename = url.split("/")[-1].split("?")[0] + + res = scraper.get(url, stream=True) + if res.status_code != 200: + raise Exception(url + " : " + res.reason) + total_size = int(res.headers.get("content-length", 0)) + + with tqdm(desc=filename, total=total_size, unit="B", unit_scale=True) as progress_bar: + with open(filename, "wb") as file: + for data in res.iter_content(1024): + progress_bar.update(len(data)) + file.write(data) + sleep(0.01) + + except Exception as ex: + failed.append(url) \ No newline at end of file