Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
Add extra concurrency limiting options for downloads.
Jules-WinnfieldX875d642a927c
diff --git a/README.md b/README.mdindex aab12b2ff..bad148fae 100644--- a/README.md+++ b/README.md@@ -137,13 +137,16 @@ optional arguments:--block-sub-folders block sub folders from being created--disable-attempt-limit disables the attempt limitation--include-id include the ID in the download folder name+--max-concurrent-threads number of threads to download simultaneously+--max-concurrent-domains number of domains to download simultaneously+--max-concurrent-albums number of albums to download simultaneously+--max-concurrent-downloads-per-domain number of simultaneous downloads per domain--skip-download-mark-completed sets the scraped files as downloaded without downloading--output-errored-urls sets the failed urls to be output to the errored urls file--output-unsupported-urls sets the unsupported urls to be output to the unsupported urls file--proxy HTTP/HTTPS proxy used for downloading, format [protocal]://[ip]:[port]--remove-bunkr-identifier removes the bunkr added identifier from output filenames--required-free-space required free space (in gigabytes) for the program to run---simultaneous-downloads-per-domain number of simultaneous downloads to use per domain--sort-downloads sorts downloaded files after downloads have finished--sort-directory folder to download files todiff --git a/cyberdrop_dl/__init__.py b/cyberdrop_dl/__init__.pyindex aaf096ae3..672a8773e 100644--- a/cyberdrop_dl/__init__.py+++ b/cyberdrop_dl/__init__.py@@ -1 +1 @@-__version__ = "4.2.29"+__version__ = "4.2.31"diff --git a/cyberdrop_dl/base_functions/config_schema.py b/cyberdrop_dl/base_functions/config_schema.pyindex 4af417cce..19ddda736 100644--- a/cyberdrop_dl/base_functions/config_schema.py+++ b/cyberdrop_dl/base_functions/config_schema.py@@ -72,12 +72,15 @@ config_default: Dict = {"block_sub_folders": False,"disable_attempt_limit": False,"include_id": False,+ "max_concurrent_threads": 0,+ "max_concurrent_domains": 0,+ "max_concurrent_albums": 0,+ "max_concurrent_downloads_per_domain": 4,"output_errored_urls": False,"output_unsupported_urls": False,"proxy": "","remove_bunkr_identifier": False,"required_free_space": 5,- "simultaneous_downloads_per_domain": 4,"skip_download_mark_completed": False,"user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/112.0",},diff --git a/cyberdrop_dl/downloader/downloader_utils.py b/cyberdrop_dl/downloader/downloader_utils.pyindex 52e878d26..78341565a 100644--- a/cyberdrop_dl/downloader/downloader_utils.py+++ b/cyberdrop_dl/downloader/downloader_utils.py@@ -50,7 +50,7 @@ async def check_free_space(required_space_gb: int, download_directory: Path) ->def get_threads_number(args: Dict, domain: str) -> int:- threads = args["Runtime"]["simultaneous_downloads_per_domain"] or multiprocessing.cpu_count()+ threads = args["Runtime"]["max_concurrent_downloads_per_domain"] or multiprocessing.cpu_count()if any(s in domain for s in ('anonfiles', 'bunkr', 'pixeldrain')):return min(threads, 2)return threadsdiff --git a/cyberdrop_dl/downloader/downloaders.py b/cyberdrop_dl/downloader/downloaders.pyindex 5350c1fbc..4b8a36a48 100644--- a/cyberdrop_dl/downloader/downloaders.py+++ b/cyberdrop_dl/downloader/downloaders.py@@ -6,7 +6,7 @@ import itertoolsimport loggingfrom http import HTTPStatusfrom random import gauss-from typing import TYPE_CHECKING, Any, Dict, Tuple+from typing import TYPE_CHECKING, Any, Dict, Tuple, Coroutine, List, Optionalimport aiofilesimport aiohttp.client_exceptions@@ -49,6 +49,17 @@ if TYPE_CHECKING:from rich.progress import TaskID+def _limit_concurrency(coroutines: List[Coroutine], semaphore: Optional[asyncio.Semaphore]) -> List[Coroutine]:+ if not semaphore:+ return coroutines++ async def limit_concurrency(coroutine: Coroutine) -> Coroutine:+ async with semaphore:+ return await coroutine++ return [limit_concurrency(coroutine) for coroutine in coroutines]++class CDLHelper:def __init__(self, args: Dict, client: Client, files: OverallFileProgress, SQL_Helper: SQLHelper):self.args = args@@ -77,6 +88,11 @@ class CDLHelper:self.proxy = args["Runtime"]["proxy"]self.required_free_space = args["Runtime"]["required_free_space"]+ # Concurrency Limits+ self.threads_limit = asyncio.Semaphore(args["Runtime"]["max_concurrent_threads"]) if args["Runtime"]["max_concurrent_threads"] else None+ self.domains_limit = asyncio.Semaphore(args["Runtime"]["max_concurrent_domains"]) if args["Runtime"]["max_concurrent_domains"] else None+ self.albums_limit = asyncio.Semaphore(args["Runtime"]["max_concurrent_albums"]) if args["Runtime"]["max_concurrent_albums"] else None+# Output Argsself.errored_output = args['Runtime']['output_errored_urls']self.errored_file = args['Files']['errored_urls_file']@@ -321,7 +337,7 @@ class DownloadDirector:cascade_tasks = []for title, Cascade in self.Forums.threads.items():cascade_tasks.append(self.start_cascade(forum_task, title, Cascade))- await asyncio.gather(*cascade_tasks)+ await asyncio.gather(*_limit_concurrency(cascade_tasks, self.CDL_Helper.threads_limit))await clear()completed_files, skipped_files, failed_files = self.Progress_Master.OverallFileProgress.return_totals()@@ -335,7 +351,7 @@ class DownloadDirector:domain_tasks = []for domain, domain_obj in Cascade.domains.items():domain_tasks.append(self.start_domain(cascade_task, title, domain, domain_obj))- await asyncio.gather(*domain_tasks)+ await asyncio.gather(*_limit_concurrency(domain_tasks, self.CDL_Helper.domains_limit))self.Progress_Master.CascadeProgress.mark_cascade_completed(cascade_task)self.Progress_Master.ForumProgress.advance_forum(forum_task)@@ -347,7 +363,7 @@ class DownloadDirector:album_tasks = []for album, album_obj in domain_obj.albums.items():album_tasks.append(self.start_album(downloader, domain_task, domain, album, album_obj))- await asyncio.gather(*album_tasks)+ await asyncio.gather(*_limit_concurrency(album_tasks, self.CDL_Helper.albums_limit))self.Progress_Master.CascadeProgress.advance_cascade(cascade_task)self.Progress_Master.DomainProgress.mark_domain_completed(domain, domain_task)diff --git a/cyberdrop_dl/main.py b/cyberdrop_dl/main.pyindex 4d9efd45b..5d5743f53 100644--- a/cyberdrop_dl/main.py+++ b/cyberdrop_dl/main.py@@ -69,13 +69,16 @@ def parse_args() -> argparse.Namespace:runtime_opts.add_argument("--block-sub-folders", help="block sub folders from being created", action="store_true")runtime_opts.add_argument("--disable-attempt-limit", help="disables the attempt limitation", action="store_true")runtime_opts.add_argument("--include-id", help="include the ID in the download folder name", action="store_true")+ runtime_opts.add_argument("--max_concurrent-threads", type=int, default=config_group["max_concurrent_threads"], help="Number of threads to download simultaneously (default: %(default)s)")+ runtime_opts.add_argument("--max_concurrent-domains", type=int, default=config_group["max_concurrent_domains"], help="Number of domains to download simultaneously (default: %(default)s)")+ runtime_opts.add_argument("--max_concurrent-albums", type=int, default=config_group["max_concurrent_albums"], help="Number of albums to download simultaneously (default: %(default)s)")+ runtime_opts.add_argument("--max_concurrent-downloads-per-domain", type=int, default=config_group["max_concurrent_downloads_per_domain"], help="Number of simultaneous downloads per domain (default: %(default)s)")runtime_opts.add_argument("--skip-download-mark-completed", help="sets the scraped files as downloaded without downloading", action="store_true")runtime_opts.add_argument("--output-errored-urls", help="sets the failed urls to be output to the errored urls file", action="store_true")runtime_opts.add_argument("--output-unsupported-urls", help="sets the unsupported urls to be output to the unsupported urls file", action="store_true")runtime_opts.add_argument("--proxy", help="HTTP/HTTPS proxy used for downloading, format [protocal]://[ip]:[port]", default=config_group["proxy"])runtime_opts.add_argument("--remove-bunkr-identifier", help="removes the bunkr added identifier from output filenames", action="store_true")runtime_opts.add_argument("--required-free-space", type=int, default=config_group["required_free_space"], help="required free space (in gigabytes) for the program to run (default: %(default)s)")- runtime_opts.add_argument("--simultaneous-downloads-per-domain", type=int, default=config_group["simultaneous_downloads_per_domain"], help="Number of simultaneous downloads to use per domain (default: %(default)s)")# Sortingconfig_group = config_data["Sorting"]