Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
Add exclude args and functionality
Jules-WinnfieldX8b75cab8cc61
diff --git a/README.md b/README.mdindex 6bbfbbdd6..497c19510 100644--- a/README.md+++ b/README.md@@ -74,6 +74,10 @@ optional arguments:--threads THREADS number of threads to use (0 = max)--attempts ATTEMPTS number of attempts to download each file--include-id include the ID in the download folder name+ --exclude-videos exclude video files from downloading+ --exclude-images exclude image files from downloading+ --exclude-audio exclude audio files from downloading+ --exclude-other exclude other files from downloading```# Creditdiff --git a/cyberdrop_dl/__init__.py b/cyberdrop_dl/__init__.pyindex 21e33ba2c..e3b571e0f 100644--- a/cyberdrop_dl/__init__.py+++ b/cyberdrop_dl/__init__.py@@ -1 +1 @@-__version__ = "2.10.3"+__version__ = "2.10.4"diff --git a/cyberdrop_dl/main.py b/cyberdrop_dl/main.pyindex b1f92f6c1..f81496030 100644--- a/cyberdrop_dl/main.py+++ b/cyberdrop_dl/main.py@@ -19,6 +19,10 @@ def parse_args():parser.add_argument("--threads", type=int, help="number of threads to use (0 = max)", default=0)parser.add_argument("--attempts", type=int, help="number of attempts to download each file", default=10)parser.add_argument("--include-id", help="include the ID in the download folder name", action="store_true")+ parser.add_argument("--exclude-videos", help="skip downloading of video files", action="store_true")+ parser.add_argument("--exclude-images", help="skip downloading of image files", action="store_true")+ parser.add_argument("--exclude-audio", help="skip downloading of audio files", action="store_true")+ parser.add_argument("--exclude-other", help="skip downloading of images", action="store_true")parser.add_argument("links", metavar="link", nargs="*",help="link to content to download (passing multiple links is supported)", default=[])args = parser.parse_args()@@ -54,8 +58,10 @@ async def download_all(args: argparse.Namespace):log("This program does not currently support password protected albums.", Fore.RED)exit(0)clear()- downloaders = get_downloaders(content_object, folder=Path(args.output_folder),- attempts=args.attempts, threads=args.threads)+ downloaders = get_downloaders(content_object, folder=Path(args.output_folder), attempts=args.attempts,+ threads=args.threads, exclude_videos=args.exclude_videos,+ exclude_images=args.exclude_images, exclude_audio=args.exclude_audio,+ exclude_other=args.exclude_other)for downloader in downloaders:await downloader.download_content()diff --git a/cyberdrop_dl/utils/downloaders.py b/cyberdrop_dl/utils/downloaders.pyindex b6517aa8d..fad1e5a9b 100644--- a/cyberdrop_dl/utils/downloaders.py+++ b/cyberdrop_dl/utils/downloaders.py@@ -65,13 +65,18 @@ async def throttle(self, url: URL) -> None:class Downloader:- def __init__(self, album_obj: AlbumItem, morsels, folder: Path, title: str, attempts: int, max_workers: int):+ def __init__(self, album_obj: AlbumItem, morsels, folder: Path, title: str, attempts: int, max_workers: int,+ exclude_videos: bool, exclude_images: bool, exclude_audio: bool, exclude_other: bool):self.album_obj = album_objself.morsels = morselsself.folder = folderself.title = titleself.attempts = attemptsself.max_workers = max_workers+ self.exclude_videos = exclude_videos+ self.exclude_images = exclude_images+ self.exclude_audio = exclude_audio+ self.exclude_other = exclude_otherself._semaphore = asyncio.Semaphore(max_workers)self.delay = {'media-files.bunkr.is': 2}self.throttle_times = {}@@ -105,6 +110,25 @@ class Downloader:if (self.folder / self.title / filename).exists():return+ # Skip based on CLI arg.+ ext = '.' + filename.split('.')[-1]+ if self.exclude_videos:+ if ext in FILE_FORMATS['Videos']:+ logging.debug("Skipping " + filename)+ return+ if self.exclude_images:+ if ext in FILE_FORMATS['Images']:+ logging.debug("Skipping " + filename)+ return+ if self.exclude_audio:+ if ext in FILE_FORMATS['Audio']:+ logging.debug("Skipping " + filename)+ return+ if self.exclude_other:+ if ext in FILE_FORMATS['Other']:+ logging.debug("Skipping " + filename)+ return+resume_point = 0complete_file = (self.folder / self.title / filename)temp_file = complete_file.with_suffix(complete_file.suffix + '.part')@@ -217,7 +241,8 @@ def simple_cookies(cookies):return morsels-def get_downloaders(Cascade: CascadeItem, folder: Path, attempts: int, threads: int) -> List[Downloader]:+def get_downloaders(Cascade: CascadeItem, folder: Path, attempts: int, threads: int, exclude_videos: bool,+ exclude_images: bool, exclude_audio: bool, exclude_other: bool) -> 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 asthe first one, so we need to classify them one by one, sort them to@@ -234,6 +259,8 @@ def get_downloaders(Cascade: CascadeItem, folder: Path, attempts: int, threads:max_workers = 2 if (max_workers > 2) else max_workersfor title, album_obj in domain_obj.albums.items():downloader = Downloader(album_obj, morsels=morsels, title=title, folder=folder,- attempts=attempts, max_workers=max_workers)+ attempts=attempts, max_workers=max_workers, exclude_videos=exclude_videos,+ exclude_images=exclude_images, exclude_audio=exclude_audio,+ exclude_other=exclude_other)downloaders.append(downloader)return downloaders