Skip to content

Bulk asynchronous downloader for multiple file hosts

fix minor bugs and change to simultaneous per domain downloads

Jules-WinnfieldX16738a8605b5
diff --git a/cyberdrop_dl/base_functions/config_schema.py b/cyberdrop_dl/base_functions/config_schema.py
index 90c138968..db5ba7988 100644
--- a/cyberdrop_dl/base_functions/config_schema.py
+++ b/cyberdrop_dl/base_functions/config_schema.py
@@ -56,7 +56,7 @@ config_default = [
"proxy": "",
"remove_bunkr_identifier": False,
"required_free_space": 5,
- "simultaneous_downloads": 0,
+ "simultaneous_downloads_per_domain": 4,
},
"Sorting": {
"sort_downloads": False,
@@ -87,7 +87,7 @@ jdownloader_args = ["apply_jdownloader", "jdownloader_username", "jdownloader_pa
ratelimiting_args = ["connection_timeout", "ratelimit", "throttle"]
-runtime_args = ["simultaneous_downloads", "allow_insecure_connections", "attempts", "disable_attempt_limit",
+runtime_args = ["simultaneous_downloads_per_domain", "allow_insecure_connections", "attempts", "disable_attempt_limit",
"include_id", "mark_downloaded", "proxy", "required_free_space", "output_errored_urls",
"output_unsupported_urls", "block_sub_folders"]
diff --git a/cyberdrop_dl/downloader/downloaders.py b/cyberdrop_dl/downloader/downloaders.py
index 3ddebef2e..6b89c034a 100644
--- a/cyberdrop_dl/downloader/downloaders.py
+++ b/cyberdrop_dl/downloader/downloaders.py
@@ -66,8 +66,7 @@ class Downloader:
"""Downloader class, directs downloading for domain objects"""
def __init__(self, args: dict, client: Client, SQL_Helper: SQLHelper, scraper: ScrapeMapper, max_workers: int,
- domain: str, domain_obj: DomainItem, semaphore: asyncio.Semaphore, bunkr_semaphore: asyncio.Semaphore,
- pixeldrain_semaphore: asyncio.Semaphore, anonfiles_semaphore: asyncio.Semaphore, files: Files):
+ domain: str, domain_obj: DomainItem, semaphore: asyncio.Semaphore, files: Files):
self.backup_scraper = scraper
self.client = client
self.download_session = DownloadSession(client, args["Ratelimiting"]["connection_timeout"])
@@ -85,9 +84,6 @@ class Downloader:
self.current_attempt = {}
self.max_workers = max_workers
self._semaphore = semaphore
- self._bunkr_semaphore = bunkr_semaphore
- self._pixeldrain_semaphore = pixeldrain_semaphore
- self._anonfiles_semaphore = anonfiles_semaphore
self.delay = {'cyberfile': 1, 'anonfiles': 1, "coomer": 0.2, "kemono": 0.2}
self.pixeldrain_api_key = args["Authentication"]["pixeldrain_api_key"]
@@ -144,19 +140,8 @@ class Downloader:
self.files.skipped_files += 1
album_progress.advance(album_task, 1)
return
-
- if 'bunkr' in self.domain:
- async with self._bunkr_semaphore:
- await self.download_file(album_task, album, media)
- elif 'pixeldrain' in self.domain:
- async with self._pixeldrain_semaphore:
- await self.download_file(album_task, album, media)
- elif 'anonfiles' in self.domain:
- async with self._anonfiles_semaphore:
- await self.download_file(album_task, album, media)
- else:
- async with self._semaphore:
- await self.download_file(album_task, album, media)
+ async with self._semaphore:
+ await self.download_file(album_task, album, media)
async def check_file_exists(self, complete_file, partial_file, media, album, url_path, original_filename,
current_throttle):
@@ -331,7 +316,7 @@ class Downloader:
async def download_cascade(args: dict, Cascade: CascadeItem, SQL_Helper: SQLHelper, client: Client,
scraper: ScrapeMapper) -> None:
"""Handler for cascades and the progress bars for it"""
- user_threads = args["Runtime"]["simultaneous_downloads"]
+ user_threads = args["Runtime"]["simultaneous_downloads_per_domain"]
files = Files()
progress_table = await get_cascade_table()
@@ -342,16 +327,14 @@ async def download_cascade(args: dict, Cascade: CascadeItem, SQL_Helper: SQLHelp
downloaders = []
tasks = []
- threads = user_threads if user_threads != 0 else multiprocessing.cpu_count()
- download_semaphore = asyncio.Semaphore(threads)
- bunkr_semaphore = asyncio.Semaphore(2 if threads > 2 else threads)
- pixeldrain_semaphore = asyncio.Semaphore(2 if threads > 2 else threads)
- anonfiles_semaphore = asyncio.Semaphore(2 if threads > 2 else threads)
for domain, domain_obj in Cascade.domains.items():
+ threads = user_threads if user_threads != 0 else multiprocessing.cpu_count()
+ if 'bunkr' in domain or 'pixeldrain' in domain or 'anonfiles' in domain:
+ threads = 2 if (threads > 2) else threads
+ download_semaphore = asyncio.Semaphore(threads)
downloaders.append(Downloader(args, client, SQL_Helper, scraper, threads, domain, domain_obj,
- download_semaphore, bunkr_semaphore, pixeldrain_semaphore,
- anonfiles_semaphore, files))
+ download_semaphore, files))
for downloader in downloaders:
tasks.append(downloader.start_domain(cascade_task))
await asyncio.gather(*tasks)
@@ -364,7 +347,7 @@ async def download_cascade(args: dict, Cascade: CascadeItem, SQL_Helper: SQLHelp
async def download_forums(args: dict, Forums: ForumItem, SQL_Helper: SQLHelper, client: Client,
scraper: ScrapeMapper) -> None:
"""Handler for forum threads and the progress bars for it"""
- user_threads = args["Runtime"]["simultaneous_downloads"]
+ user_threads = args["Runtime"]["simultaneous_downloads_per_domain"]
files = Files()
progress_table = await get_forum_table()
@@ -377,16 +360,14 @@ async def download_forums(args: dict, Forums: ForumItem, SQL_Helper: SQLHelper,
downloaders = []
tasks = []
- threads = user_threads if user_threads != 0 else multiprocessing.cpu_count()
- download_semaphore = asyncio.Semaphore(threads)
- bunkr_semaphore = asyncio.Semaphore(2 if threads > 2 else threads)
- pixeldrain_semaphore = asyncio.Semaphore(2 if threads > 2 else threads)
- anonfiles_semaphore = asyncio.Semaphore(2 if threads > 2 else threads)
for domain, domain_obj in Cascade.domains.items():
+ threads = user_threads if user_threads != 0 else multiprocessing.cpu_count()
+ if 'bunkr' in domain or 'pixeldrain' in domain or 'anonfiles' in domain:
+ threads = 2 if (threads > 2) else threads
+ download_semaphore = asyncio.Semaphore(threads)
downloaders.append(Downloader(args, client, SQL_Helper, scraper, threads, domain, domain_obj,
- download_semaphore, bunkr_semaphore, pixeldrain_semaphore,
- anonfiles_semaphore, files))
+ download_semaphore, files))
for downloader in downloaders:
tasks.append(downloader.start_domain(cascade_task))
await asyncio.gather(*tasks)
diff --git a/cyberdrop_dl/main.py b/cyberdrop_dl/main.py
index cbb72780f..2fdbc85d4 100644
--- a/cyberdrop_dl/main.py
+++ b/cyberdrop_dl/main.py
@@ -54,7 +54,7 @@ def parse_args() -> argparse.Namespace:
parser.add_argument("--proxy", help="HTTP/HTTPS proxy used for downloading, format [protocal]://[ip]:[port]", default=None)
parser.add_argument("--remove-bunker-identifier", help="Removes the bunkr added identifier from output filenames", action="store_true")
parser.add_argument("--required-free-space", type=int, help="required free space (in gigabytes) for the program to run", default=5)
- parser.add_argument("--simultaneous-downloads", type=int, help="number of threads to use (0 = max)", default=0)
+ parser.add_argument("--simultaneous-downloads-per-domain", type=int, help="Number of simultaneous downloads to use per domain", default=4)
# Sorting
parser.add_argument("--sort-downloads", help="sorts downloaded files after downloads have finished", action="store_true")
@@ -109,7 +109,7 @@ async def file_management(args: dict, links: list) -> None:
output_url_file.touch()
if args['Runtime']['output_unsupported_urls']:
- unsupported_urls = args['Forum_Options']['unsupported_urls_file']
+ unsupported_urls = args['Files']['unsupported_urls_file']
if unsupported_urls.exists():
unsupported_urls.unlink()
unsupported_urls.touch()
@@ -117,7 +117,7 @@ async def file_management(args: dict, links: list) -> None:
await f.write("URL,REFERER,TITLE")
if args['Runtime']['output_errored_urls']:
- errored_urls = args['Forum_Options']['errored_urls_file']
+ errored_urls = args['Files']['errored_urls_file']
if errored_urls.exists():
errored_urls.unlink()
errored_urls.touch()