Add multithreading downloads

Shoud fix some bugs???
This commit is contained in:
Kentai Radiquum 2023-12-09 02:25:57 +05:00
parent b9d958c6c1
commit 848c2697f4
Signed by: Radiquum
GPG key ID: 858E8EE696525EED
5 changed files with 48 additions and 20 deletions

View file

@ -177,6 +177,9 @@ if username is not None:
data = open(username[0]).read()
username = filter(None, data.split("\n"))
if len(username) == 1 and args.folder is not None:
username = username[0]
# Custom input
cookies = args.cookies
output_folder = args.output_folder

View file

@ -56,7 +56,7 @@ def download(path, max_retries=5):
if config.category != "gallery":
output = f"{config.output_folder}/{author}/{config.category}"
if config.folder is not None:
output = f"{config.output_folder}/{author}/{config.folder}"
output = f"{config.output_folder}/{author}/folders/{config.folder.split('/')[1]}"
os.makedirs(output, exist_ok=True)
output_path = f"{output}/{title} ({view_id}) - {filename}"

View file

@ -125,19 +125,14 @@ def next_button(page_url):
if config.submissions is True:
# unlike galleries that are sequentially numbered, submissions use a different scheme.
# the "page_num" is instead: new~[set of numbers]@(12 or 48 or 72) if sorting by new
try:
parse_next_button = s.find("a", class_="button standard more").attrs.get(
"href"
)
except AttributeError:
try:
parse_next_button = s.find(
"a", class_="button standard more-half"
).attrs.get("href")
except AttributeError as e:
print(f"{config.WARN_COLOR}Unable to find next button{config.END}")
raise DownloadComplete from e
page_num = parse_next_button.split("/")[-2]
parse_next_button = s.find("a", class_="button standard more")
if parse_next_button is None:
parse_next_button = s.find("a", class_="button standard more-half")
if parse_next_button is not None:
page_num = parse_next_button.attrs['href'].split("/")[-2]
else:
print(f"{config.WARN_COLOR}Unable to find next button{config.END}")
raise DownloadComplete
elif config.category != "favorites":
parse_next_button = s.find("button", class_="button standard", text="Next")
if parse_next_button is None or parse_next_button.parent is None:
@ -147,10 +142,9 @@ def next_button(page_url):
else:
parse_next_button = s.find("a", class_="button standard right", text="Next")
page_num = fav_next_button(parse_next_button)
next_page_url = (parse_next_button.parent.attrs['action'] if 'action'
in parse_next_button.parent.attrs else parse_next_button.attrs['href'])
print(
f"Downloading page {page_num} - {config.BASE_URL}{next_page_url}"
f"Downloading page {page_num}"
)
return page_num