Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
Implement basic filesize check
Jules-WinnfieldXd1809065d572
diff --git a/cyberdrop_dl/base_functions/config_schema.py b/cyberdrop_dl/base_functions/config_schema.pyindex 316c93801..12296bb79 100644--- a/cyberdrop_dl/base_functions/config_schema.py+++ b/cyberdrop_dl/base_functions/config_schema.py@@ -73,6 +73,12 @@ config_default: Dict = {"attempts": 10,"block_sub_folders": False,"disable_attempt_limit": False,+ "filesize_minimum_images": 0,+ "filesize_minimum_other": 0,+ "filesize_minimum_videos": 0,+ "filesize_maximum_images": 0,+ "filesize_maximum_other": 0,+ "filesize_maximum_videos": 0,"include_id": False,"max_concurrent_threads": 0,"max_concurrent_domains": 0,diff --git a/cyberdrop_dl/downloader/downloaders.py b/cyberdrop_dl/downloader/downloaders.pyindex 9e6452e72..64eb3ac0a 100644--- a/cyberdrop_dl/downloader/downloaders.py+++ b/cyberdrop_dl/downloader/downloaders.py@@ -12,6 +12,7 @@ import aiohttp.client_exceptionsfrom rich.live import Livefrom cyberdrop_dl.base_functions.base_functions import (+ FILE_FORMATS,clear,log,logger,@@ -90,6 +91,14 @@ class CDLHelper:self.proxy = args["Runtime"]["proxy"]self.required_free_space = args["Runtime"]["required_free_space"]+ # Filesize limits+ self.filesize_minimum_images = args["Runtime"]["filesize_minimum_images"]+ self.filesize_minimum_other = args["Runtime"]["filesize_minimum_other"]+ self.filesize_minimum_videos = args["Runtime"]["filesize_minimum_videos"]+ self.filesize_maximum_images = args["Runtime"]["filesize_maximum_images"]+ self.filesize_maximum_other = args["Runtime"]["filesize_maximum_other"]+ self.filesize_maximum_videos = args["Runtime"]["filesize_maximum_videos"]+# Concurrency Limitsself.threads_limit = asyncio.Semaphore(args["Runtime"]["max_concurrent_threads"]) if args["Runtime"]["max_concurrent_threads"] else Noneself.domains_limit = asyncio.Semaphore(args["Runtime"]["max_concurrent_domains"]) if args["Runtime"]["max_concurrent_domains"] else None@@ -102,6 +111,24 @@ class CDLHelper:"""Get the throttle for a domain"""return self.delay.get(domain, self.client.throttle)+ def check_filesize_limits(self, media: MediaItem, content_size: int) -> bool:+ if media.ext in FILE_FORMATS['Images']:+ if content_size < self.filesize_minimum_images:+ return False+ if self.filesize_maximum_images and content_size > self.filesize_maximum_images:+ return False+ elif media.ext in FILE_FORMATS['Videos']:+ if content_size < self.filesize_minimum_videos:+ return False+ if self.filesize_maximum_videos and content_size > self.filesize_maximum_videos:+ return False+ else:+ if content_size < self.filesize_minimum_other:+ return False+ if self.filesize_maximum_other and content_size > self.filesize_maximum_other:+ return False+ return True+class Downloader:"""Downloader class, directs downloading for domain objects"""@@ -253,6 +280,11 @@ class Downloader:if not expected_size:expected_size = await self.download_session.get_filesize(media.url, str(media.referer),current_throttle)+ proceed = self.CDL_Helper.check_filesize_limits(media, expected_size)+ if not proceed:+ log(f"Filesize outside limits: {media.url}", quiet=True)+ break+if complete_file.exists() and complete_file.stat().st_size == expected_size:proceed = Falsebreak