Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
I think this is a valid fix for stuck downloads. Implements timeouts for downloader again, but catch those exceptions separately and check against partial filesize to determine retry.
Jules-WinnfieldX45eb31b95595
diff --git a/cyberdrop_dl/client/client.py b/cyberdrop_dl/client/client.pyindex 543192d46..bc329280c 100644--- a/cyberdrop_dl/client/client.py+++ b/cyberdrop_dl/client/client.py@@ -120,7 +120,8 @@ class DownloadSession:def __init__(self, client: Client):self.client = clientself.headers = {"user-agent": client.user_agent}- self.timeouts = aiohttp.ClientTimeout(total=None, connect=self.client.connect_timeout, sock_read=None)+ self.timeouts = aiohttp.ClientTimeout(total=300 + self.client.connect_timeout,+ connect=self.client.connect_timeout, sock_read=300)self.client_session = aiohttp.ClientSession(headers=self.headers, raise_for_status=True,cookie_jar=self.client.cookies, timeout=self.timeouts)self.throttle_times: Dict[str, float] = {}diff --git a/cyberdrop_dl/downloader/downloader_utils.py b/cyberdrop_dl/downloader/downloader_utils.pyindex a044f171a..6d36c444a 100644--- a/cyberdrop_dl/downloader/downloader_utils.py+++ b/cyberdrop_dl/downloader/downloader_utils.py@@ -80,6 +80,7 @@ def retry(f):return Nonelogger.debug(e.message)logger.debug(f'Retrying ({self.current_attempt[url_path]}) {media.url}...')- self.current_attempt[url_path] += 1+ if e.code != 999:+ self.current_attempt[url_path] += 1return wrapperdiff --git a/cyberdrop_dl/downloader/downloaders.py b/cyberdrop_dl/downloader/downloaders.pyindex 3477a32b8..305368f76 100644--- a/cyberdrop_dl/downloader/downloaders.py+++ b/cyberdrop_dl/downloader/downloaders.py@@ -152,6 +152,7 @@ class Downloader:max_workers = get_threads_number(CDL_Helper.args, domain)self._semaphore = asyncio.Semaphore(max_workers)self.current_attempt: Dict[str, int] = {}+ self.current_attempt_filesize: Dict[str, int] = {}self.download_session = DownloadSession(CDL_Helper.client)@@ -246,10 +247,29 @@ class Downloader:await self.CDL_Helper.File_Lock.remove_lock(filename)return+ except (aiohttp.client_exceptions.ServerDisconnectedError, asyncio.TimeoutError,+ aiohttp.client_exceptions.ServerTimeoutError) as e:+ if await self.CDL_Helper.File_Lock.check_lock(filename):+ await self.CDL_Helper.File_Lock.remove_lock(filename)++ with contextlib.suppress(Exception):+ await self.Progress_Master.FileProgress.remove_file(file_task)++ if partial_file.is_file():+ size = partial_file.stat().st_size+ if partial_file.name not in self.current_attempt_filesize:+ self.current_attempt_filesize[filename] = size+ elif self.current_attempt_filesize[filename] > size:+ self.current_attempt_filesize[filename] = size+ else:+ raise DownloadFailure(code=getattr(e, "code", 1), message="Download timeout reached, retrying")+ raise DownloadFailure(code=999, message="Download timeout reached, retrying")++ raise DownloadFailure(code=getattr(e, "code", 1), message=repr(e))+except (aiohttp.client_exceptions.ClientPayloadError, aiohttp.client_exceptions.ClientOSError,- aiohttp.client_exceptions.ServerDisconnectedError, asyncio.TimeoutError,- aiohttp.client_exceptions.ClientResponseError, aiohttp.client_exceptions.ServerTimeoutError,- DownloadFailure, FileNotFoundError, PermissionError) as e:+ aiohttp.client_exceptions.ClientResponseError, DownloadFailure, FileNotFoundError,+ PermissionError) as e:if await self.CDL_Helper.File_Lock.check_lock(filename):await self.CDL_Helper.File_Lock.remove_lock(filename)