Skip to content

Bulk asynchronous downloader for multiple file hosts

Add basic proxy support

Lincoln8472552b866c
diff --git a/cyberdrop_dl/client/client.py b/cyberdrop_dl/client/client.py
index c3b978015..ccfcaeb9c 100644
--- a/cyberdrop_dl/client/client.py
+++ b/cyberdrop_dl/client/client.py
@@ -119,13 +119,13 @@ class DownloadSession:
async def download_file(self, url: URL, referer: str, current_throttle: int, range: str, original_filename: str,
filename: str, temp_file: str, resume_point: int, show_progress: bool,
- File_Lock: FileLock, folder: Path, title: str):
+ File_Lock: FileLock, folder: Path, title: str, proxy: str):
headers = {'Referer': referer, 'user-agent': self.client.user_agent}
if range:
headers['Range'] = range
await throttle(self, current_throttle, url.host)
async with self.client_session.get(url, headers=headers, ssl=self.client.ssl_context,
- raise_for_status=True) as resp:
+ raise_for_status=True, proxy=proxy) as resp:
content_type = resp.headers.get('Content-Type')
if 'text' in content_type.lower() or 'html' in content_type.lower():
logger.debug("Server for %s is either down or the file no longer exists", str(url))
diff --git a/cyberdrop_dl/client/downloaders.py b/cyberdrop_dl/client/downloaders.py
index 34a6e635f..526941c74 100644
--- a/cyberdrop_dl/client/downloaders.py
+++ b/cyberdrop_dl/client/downloaders.py
@@ -53,7 +53,7 @@ def retry(f):
class Downloader:
def __init__(self, album_obj: AlbumItem, folder: Path, title: str, attempts: int,
disable_attempt_limit: bool, max_workers: int, excludes: Dict[str, bool], SQL_helper: SQLHelper,
- client: Client):
+ client: Client, proxy: str):
self.album_obj = album_obj
self.client = client
self.folder = folder
@@ -72,6 +72,8 @@ class Downloader:
self._semaphore = asyncio.Semaphore(max_workers)
self.delay = {'cyberfile.is': 1, 'anonfiles.com': 1}
+ self.proxy = proxy
+
"""Changed from aiohttp exceptions caught to FailureException to allow for partial downloads."""
@retry
@@ -195,7 +197,7 @@ class Downloader:
await session.download_file(url, referer, current_throttle, range, original_filename, filename,
temp_file, resume_point, show_progress, self.File_Lock, self.folder,
- self.title)
+ self.title, self.proxy)
await self.rename_file(filename, url, db_path)
await self.File_Lock.remove_lock(original_filename)
@@ -271,7 +273,7 @@ class Downloader:
async def get_downloaders(Cascade: CascadeItem, folder: Path, attempts: int, disable_attempt_limit: bool,
- max_workers: int, excludes: Dict[str, bool], SQL_helper: SQLHelper, client: Client) -> List[Downloader]:
+ max_workers: int, excludes: Dict[str, bool], SQL_helper: SQLHelper, client: Client, proxy: str) -> List[Downloader]:
"""Get a list of downloaders for each supported type of URLs.
We shouldn't just assume that each URL will have the same netloc as
the first one, so we need to classify them one by one, sort them to
@@ -288,6 +290,6 @@ async def get_downloaders(Cascade: CascadeItem, folder: Path, attempts: int, dis
for title, album_obj in domain_obj.albums.items():
downloader = Downloader(album_obj, title=title, folder=folder, attempts=attempts,
disable_attempt_limit=disable_attempt_limit, max_workers=max_workers_temp,
- excludes=excludes, SQL_helper=SQL_helper, client=client)
+ excludes=excludes, SQL_helper=SQL_helper, client=client, proxy=proxy)
downloaders.append(downloader)
return downloaders
diff --git a/cyberdrop_dl/main.py b/cyberdrop_dl/main.py
index 56d9072e9..730042bf6 100644
--- a/cyberdrop_dl/main.py
+++ b/cyberdrop_dl/main.py
@@ -38,6 +38,7 @@ def parse_args():
parser.add_argument("--exclude-other", help="skip downloading of images", action="store_true")
parser.add_argument("--ignore-history", help="This ignores previous download history", action="store_true")
parser.add_argument("--output-last-forum-post", help="Separates forum scraping into folders by post number", action="store_true")
+ parser.add_argument("--proxy", help="HTTP/HTTPS proxy used for downloading, format [protocal]://[ip]:[port]", default=None)
parser.add_argument("--separate-posts", help="Separates forum scraping into folders by post number", action="store_true")
parser.add_argument("--xbunker-username", type=str, help="username to login to xbunker", default=None)
parser.add_argument("--xbunker-password", type=str, help="password to login to xbunker", default=None)
@@ -111,7 +112,7 @@ async def download_all(args: argparse.Namespace):
downloaders = await get_downloaders(content_object, folder=args.output_folder, attempts=args.attempts,
disable_attempt_limit=args.disable_attempt_limit, max_workers=threads,
- excludes=excludes, SQL_helper=SQL_helper, client=client)
+ excludes=excludes, SQL_helper=SQL_helper, client=client, proxy=args.proxy)
for downloader in downloaders:
await downloader.download_content(conn_timeout=args.connection_timeout)