Initial commit
This commit is contained in:
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
# Python cache
|
||||
__pycache__/
|
||||
|
||||
# Python virtual environment
|
||||
venv/
|
||||
env/
|
||||
17
dhere/__main__.py
Normal file
17
dhere/__main__.py
Normal file
@ -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")
|
||||
28
dhere/http.py
Normal file
28
dhere/http.py
Normal file
@ -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)
|
||||
Reference in New Issue
Block a user