Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
Add overall progress, add options to disable all sections.
Jules-WinnfieldX03c6b9f1546d
diff --git a/cyberdrop_dl/base_functions/config_manager.py b/cyberdrop_dl/base_functions/config_manager.pyindex cb6f60b54..1fa5eaf02 100644--- a/cyberdrop_dl/base_functions/config_manager.py+++ b/cyberdrop_dl/base_functions/config_manager.py@@ -7,7 +7,7 @@ import yamlfrom cyberdrop_dl.base_functions.base_functions import logfrom cyberdrop_dl.base_functions.config_schema import config_default, authentication_args, files_args, \- jdownloader_args, runtime_args, forum_args, ignore_args, ratelimiting_args, sorting_args+ jdownloader_args, runtime_args, forum_args, ignore_args, ratelimiting_args, sorting_args, progress_argsdef create_config(config: Path, passed_args=None, remake=None):@@ -24,12 +24,24 @@ def create_config(config: Path, passed_args=None, remake=None):for arg in files_args:if arg in passed_args.keys():config_data[0]["Configuration"]["Files"][arg] = str(passed_args[arg])+ for arg in forum_args:+ if arg in passed_args.keys():+ config_data[0]["Configuration"]["Forum_Options"][arg] = passed_args[arg]for arg in jdownloader_args:if arg in passed_args.keys():config_data[0]["Configuration"]["JDownloader"][arg] = passed_args[arg]+ for arg in progress_args:+ if arg in passed_args.keys():+ config_data[0]["Configuration"]["Progress_Options"][arg] = passed_args[arg]+ for arg in ratelimiting_args:+ if arg in passed_args.keys():+ config_data[0]["Configuration"]["Ratelimiting"][arg] = passed_args[arg]for arg in runtime_args:if arg in passed_args.keys():config_data[0]["Configuration"]["Runtime"][arg] = passed_args[arg]+ for arg in sorting_args:+ if arg in passed_args.keys():+ config_data[0]["Configuration"]["Sorting"][arg] = passed_args[arg]with open(config, 'w') as yamlfile:yaml.dump(config_data, yamlfile)@@ -54,6 +66,8 @@ def validate_config(config: Path):recreate = 1if not set(jdownloader_args).issubset(set(data['JDownloader'].keys())):recreate = 1+ if not set(progress_args).issubset(set(data['Progress_Options'].keys())):+ recreate = 1if not set(ratelimiting_args).issubset(set(data['Ratelimiting'].keys())):recreate = 1if not set(runtime_args).issubset(set(data['Runtime'].keys())):@@ -66,7 +80,8 @@ def validate_config(config: Path):args = {}args_list = [data['Authentication'], data['Files'], data['Forum_Options'], data['Ignore'],- data['JDownloader'], data['Ratelimiting'], data['Runtime'], data['Sorting']]+ data['JDownloader'], data['Progress_Options'], data['Ratelimiting'], data['Runtime'],+ data['Sorting']]for dic in args_list:args.update(dic)create_config(config, args, True)@@ -105,6 +120,9 @@ def run_args(config: Path, cmd_arg: dict):for arg in jdownloader_args:if arg in cmd_arg.keys():config_data["JDownloader"][arg] = cmd_arg[arg]+ for arg in progress_args:+ if arg in cmd_arg.keys():+ config_data["Progress_Options"][arg] = cmd_arg[arg]for arg in ratelimiting_args:if arg in cmd_arg.keys():config_data["Ratelimiting"][arg] = cmd_arg[arg]@@ -132,6 +150,7 @@ async def document_args(args: dict):await log(f"Using forum option arguments: {print_args['Forum_Options']}", quiet=True)await log(f"Using ignore arguments: {print_args['Ignore']}", quiet=True)await log(f"Using jdownloader arguments: {print_args['JDownloader']}", quiet=True)+ await log(f"Using progress option arguments: {print_args['Progress_Options']}", quiet=True)await log(f"Using ratelimiting arguments: {print_args['Ratelimiting']}", quiet=True)await log(f"Using runtime arguments: {print_args['Runtime']}", quiet=True)await log(f"Using sorting arguments: {print_args['Sorting']}", quiet=True)diff --git a/cyberdrop_dl/base_functions/config_schema.py b/cyberdrop_dl/base_functions/config_schema.pyindex 99eb814cd..d748edd01 100644--- a/cyberdrop_dl/base_functions/config_schema.py+++ b/cyberdrop_dl/base_functions/config_schema.py@@ -39,6 +39,14 @@ config_default = ["ignore_history": False,"skip_hosts": [],},+ "Progress_Options": {+ "dont_show_overall_progress": False,+ "dont_show_forum_progress": False,+ "dont_show_thread_progress": False,+ "dont_show_domain_progress": False,+ "dont_show_album_progress": False,+ "dont_show_file_progress": False+ },"Ratelimiting": {"connection_timeout": 15,"ratelimit": 50,@@ -85,6 +93,9 @@ ignore_args = ["exclude_videos", "exclude_images", "exclude_audio", "exclude_othjdownloader_args = ["apply_jdownloader", "jdownloader_username", "jdownloader_password", "jdownloader_device"]+progress_args = ["dont_show_overall_progress", "dont_show_forum_progress", "dont_show_thread_progress",+ "dont_show_domain_progress", "dont_show_album_progress", "dont_show_file_progress"]+ratelimiting_args = ["connection_timeout", "ratelimit", "throttle"]runtime_args = ["simultaneous_downloads_per_domain", "allow_insecure_connections", "attempts", "disable_attempt_limit",diff --git a/cyberdrop_dl/base_functions/data_classes.py b/cyberdrop_dl/base_functions/data_classes.pyindex 19dfeee20..aaf293fa5 100644--- a/cyberdrop_dl/base_functions/data_classes.py+++ b/cyberdrop_dl/base_functions/data_classes.py@@ -124,6 +124,13 @@ class CascadeItem:return Falsereturn True+ async def get_total(self):+ total = 0+ for _, domain in self.domains.items():+ for _, album in domain.albums.items():+ total += len(album.media)+ return total+async def append_title(self, title: str):if not title:return@@ -180,6 +187,14 @@ class ForumItem:return Falsereturn True+ async def get_total(self):+ total = 0+ for _, Cascade in self.threads.items():+ for _, domain in Cascade.domains.items():+ for _, album in domain.albums.items():+ total += len(album.media)+ return total+async def dedupe(self):for _, Cascade in self.threads.items():for _, domain in Cascade.domains.items():diff --git a/cyberdrop_dl/downloader/downloaders.py b/cyberdrop_dl/downloader/downloaders.pyindex e979e6999..9b94ada81 100644--- a/cyberdrop_dl/downloader/downloaders.py+++ b/cyberdrop_dl/downloader/downloaders.py@@ -14,7 +14,7 @@ from rich.progress import TaskIDfrom yarl import URLfrom .progress_definitions import get_forum_table, cascade_progress, domain_progress, album_progress, file_progress, \- forum_progress, get_cascade_table+ forum_progress, get_cascade_table, overall_file_progressfrom cyberdrop_dl.base_functions.base_functions import log, logger, check_free_space, allowed_filetype, get_db_path, \clearfrom cyberdrop_dl.base_functions.error_classes import DownloadFailure@@ -42,6 +42,7 @@ def retry(f):if self.current_attempt[args[3]] >= self.allowed_attempts - 1:await self.output_failed(args[2], e)logger.debug('Skipping %s...', args[2].url, exc_info=True)+ overall_file_progress.advance(self.files.failed_files_task_id, 1)self.files.failed_files += 1returnlogger.debug(e.message)@@ -52,11 +53,14 @@ def retry(f):class Files:- """Class that keeps that of completed, skipped and failed files"""+ """Class that keeps track of completed, skipped and failed files"""- def __init__(self):+ def __init__(self, completed, skipped, failed):+ self.completed_files_task_id = completedself.completed_files = 0+ self.skipped_files_task_id = skippedself.skipped_files = 0+ self.failed_files_task_id = failedself.failed_files = 0@@ -103,8 +107,7 @@ class Downloader:async def start_domain(self, cascade_task: TaskID):"""Handler for domains and the progress bars for it"""- domain_task = domain_progress.add_task("[light_pink3]" + self.domain.upper(), progress_type="domain",- total=len(self.domain_obj.albums))+ domain_task = domain_progress.add_task("[light_pink3]" + self.domain.upper(), total=len(self.domain_obj.albums))for album, album_obj in self.domain_obj.albums.items():await self.start_album(domain_task, album, album_obj)cascade_progress.advance(cascade_task, 1)@@ -119,8 +122,7 @@ class Downloader:task_description = task_description[:37] + "..."else:task_description = task_description.ljust(40)- album_task = album_progress.add_task("[pink3]" + task_description.upper(), progress_type="album",- total=len(album_obj.media))+ album_task = album_progress.add_task("[pink3]" + task_description.upper(), total=len(album_obj.media))download_tasks = []for media in album_obj.media:download_tasks.append(self.start_file(album_task, album, media))@@ -132,6 +134,7 @@ class Downloader:"""Handler for files and the progress bars for it"""if media.complete:await log(f"Previously Downloaded: {media.filename}", quiet=True)+ overall_file_progress.advance(self.files.skipped_files_task_id, 1)self.files.skipped_files += 1album_progress.advance(album_task, 1)return@@ -140,6 +143,7 @@ class Downloader:complete = await self.SQL_Helper.check_complete_singular(self.domain, url_path)if complete:await log(f"Previously Downloaded: {media.filename}", quiet=True)+ overall_file_progress.advance(self.files.skipped_files_task_id, 1)self.files.skipped_files += 1album_progress.advance(album_task, 1)return@@ -152,6 +156,7 @@ class Downloader:"""File downloader"""if not await check_free_space(self.required_free_space, self.download_dir):await log("We've run out of free space.", quiet=True)+ overall_file_progress.advance(self.files.skipped_files_task_id, 1)self.files.skipped_files += 1album_progress.advance(album_task, 1)return@@ -159,6 +164,7 @@ class Downloader:if not await allowed_filetype(media, self.exclude_images, self.exclude_videos, self.exclude_audio,self.exclude_other):await log(f"Blocked by file extension: {media.filename}", quiet=True)+ overall_file_progress.advance(self.files.skipped_files_task_id, 1)self.files.skipped_files += 1album_progress.advance(album_task, 1)return@@ -180,27 +186,18 @@ class Downloader:complete_file = (self.download_dir / album / media.filename)partial_file = complete_file.with_suffix(complete_file.suffix + '.part')+ fake_download = False+ if self.mark_downloaded:+ fake_download = True+complete_file, partial_file, proceed = await self.check_file_exists(complete_file, partial_file, media,album, url_path, original_filename,current_throttle)if not proceed:- await self.SQL_Helper.update_pre_download(complete_file, media.filename, url_path,- original_filename)- await log(f"Previously Downloaded: {media.filename}", quiet=True)- self.files.skipped_files += 1- await self.File_Lock.remove_lock(original_filename)- await self.SQL_Helper.mark_complete(url_path, original_filename)- if url_path in self.current_attempt.keys():- self.current_attempt.pop(url_path)- album_progress.advance(album_task, 1)- return+ fake_download = Trueawait self.SQL_Helper.update_pre_download(complete_file, media.filename, url_path, original_filename)- fake_download = False- if self.mark_downloaded:- fake_download = True-resume_point = 0await self.SQL_Helper.sql_insert_temp(str(partial_file))range_num = None@@ -234,7 +231,12 @@ class Downloader:if media.url.parts[-1] in self.current_attempt.keys():self.current_attempt.pop(media.url.parts[-1])- self.files.completed_files += 1+ if fake_download:+ overall_file_progress.advance(self.files.skipped_files_task_id, 1)+ self.files.skipped_files += 1+ else:+ overall_file_progress.advance(self.files.completed_files_task_id, 1)+ self.files.completed_files += 1album_progress.advance(album_task, 1)file_progress.update(file_task, visible=False)@@ -263,6 +265,7 @@ class Downloader:if 400 <= e.code < 500 and e.code != 429:logger.debug("We ran into a 400 level error: %s", str(e.code))await log(f"Failed Download: {media.filename}", quiet=True)+ overall_file_progress.advance(self.files.failed_files_task_id, 1)self.files.failed_files += 1if url_path in self.current_attempt.keys():self.current_attempt.pop(url_path)@@ -335,10 +338,12 @@ async def download_cascade(args: dict, Cascade: CascadeItem, SQL_Helper: SQLHelpscraper: ScrapeMapper) -> None:"""Handler for cascades and the progress bars for it"""user_threads = args["Runtime"]["simultaneous_downloads_per_domain"]- files = Files()-- progress_table = await get_cascade_table()+ progress_table = await get_cascade_table(args["Progress_Options"])+ total_files = await Cascade.get_total()+ files = Files(overall_file_progress.add_task("[green]Completed", total=total_files),+ overall_file_progress.add_task("[yellow]Skipped", total=total_files),+ overall_file_progress.add_task("[red]Failed", total=total_files))with Live(progress_table, refresh_per_second=30):cascade_task = cascade_progress.add_task("[light_salmon3]Domains", progress_type="cascade",total=len(Cascade.domains))@@ -366,15 +371,16 @@ async def download_forums(args: dict, Forums: ForumItem, SQL_Helper: SQLHelper,scraper: ScrapeMapper) -> None:"""Handler for forum threads and the progress bars for it"""user_threads = args["Runtime"]["simultaneous_downloads_per_domain"]- files = Files()-- progress_table = await get_forum_table()+ progress_table = await get_forum_table(args["Progress_Options"])+ total_files = await Forums.get_total()+ files = Files(overall_file_progress.add_task("[green]Completed", total=total_files),+ overall_file_progress.add_task("[yellow]Skipped", total=total_files),+ overall_file_progress.add_task("[red]Failed", total=total_files))with Live(progress_table, refresh_per_second=30):- forum_task = forum_progress.add_task("[orange3]FORUM THREADS", progress_type="forum", total=len(Forums.threads))+ forum_task = forum_progress.add_task("[orange3]FORUM THREADS", total=len(Forums.threads))for title, Cascade in Forums.threads.items():- cascade_task = cascade_progress.add_task("[light_salmon3]" + title.upper(), progress_type="cascade",- total=len(Cascade.domains))+ cascade_task = cascade_progress.add_task("[light_salmon3]" + title.upper(), total=len(Cascade.domains))downloaders = []tasks = []diff --git a/cyberdrop_dl/downloader/progress_definitions.py b/cyberdrop_dl/downloader/progress_definitions.pyindex 23eac5c4d..77a9f4cc0 100644--- a/cyberdrop_dl/downloader/progress_definitions.py+++ b/cyberdrop_dl/downloader/progress_definitions.py@@ -1,3 +1,5 @@+from __future__ import annotations+from rich.panel import Panelfrom rich.progress import Progress, BarColumn, SpinnerColumn, TransferSpeedColumn, DownloadColumn, TimeRemainingColumnfrom rich.table import Table@@ -22,6 +24,11 @@ album_progress = Progress("[progress.description]{task.description}","[progress.percentage]{task.percentage:>3.2f}%","{task.completed} of {task.total} Files Completed")+overall_file_progress = Progress("[progress.description]{task.description}",+ BarColumn(bar_width=None),+ "[progress.percentage]{task.percentage:>3.2f}%",+ "{task.completed} of {task.total} Files Completed")+file_progress = Progress(SpinnerColumn(),"[progress.description]{task.description}",BarColumn(bar_width=None),@@ -34,22 +41,35 @@ file_progress = Progress(SpinnerColumn(),TimeRemainingColumn())-async def get_forum_table():+async def get_forum_table(progress_options: dict):"""Table creator for forum threads"""progress_table = Table.grid(expand=True)- progress_table.add_row(Panel.fit(forum_progress, title="Total Thread", border_style="green", padding=(1, 1)))- progress_table.add_row(Panel.fit(cascade_progress, title="Current Thread", border_style="green", padding=(1, 1)))- progress_table.add_row(Panel.fit(domain_progress, title="Domains Being Downloaded", border_style="green", padding=(1, 1)))- progress_table.add_row(Panel.fit(album_progress, title="Albums Being Downloaded", border_style="green", padding=(1, 1)))- progress_table.add_row(Panel.fit(file_progress, title="[b]Files Being Downloaded", border_style="green", padding=(1, 1)))+ if not progress_options['dont_show_overall_progress']:+ progress_table.add_row(Panel.fit(overall_file_progress, title="Overall Progress", border_style="green", padding=(1, 1)))+ if not progress_options['dont_show_forum_progress']:+ progress_table.add_row(Panel.fit(forum_progress, title="Total Thread", border_style="green", padding=(1, 1)))+ if not progress_options['dont_show_thread_progress']:+ progress_table.add_row(Panel.fit(cascade_progress, title="Current Thread", border_style="green", padding=(1, 1)))+ if not progress_options['dont_show_domain_progress']:+ progress_table.add_row(Panel.fit(domain_progress, title="Domains Being Downloaded", border_style="green", padding=(1, 1)))+ if not progress_options['dont_show_album_progress']:+ progress_table.add_row(Panel.fit(album_progress, title="Albums Being Downloaded", border_style="green", padding=(1, 1)))+ if not progress_options['dont_show_file_progress']:+ progress_table.add_row(Panel.fit(file_progress, title="[b]Files Being Downloaded", border_style="green", padding=(1, 1)))return progress_table-async def get_cascade_table():+async def get_cascade_table(progress_options: dict):"""Table creator for cascade objects"""progress_table = Table.grid(expand=True)- progress_table.add_row(Panel.fit(cascade_progress, title="Current Thread", border_style="green", padding=(1, 1)))- progress_table.add_row(Panel.fit(domain_progress, title="Domains Being Downloaded", border_style="green", padding=(1, 1)))- progress_table.add_row(Panel.fit(album_progress, title="Albums Being Downloaded", border_style="green", padding=(1, 1)))- progress_table.add_row(Panel.fit(file_progress, title="[b]Files Being Downloaded", border_style="green", padding=(1, 1)))+ if not progress_options['dont_show_overall_progress']:+ progress_table.add_row(Panel.fit(overall_file_progress, title="Overall Progress", border_style="green", padding=(1, 1)))+ if not progress_options['dont_show_thread_progress']:+ progress_table.add_row(Panel.fit(cascade_progress, title="Current Thread", border_style="green", padding=(1, 1)))+ if not progress_options['dont_show_domain_progress']:+ progress_table.add_row(Panel.fit(domain_progress, title="Domains Being Downloaded", border_style="green", padding=(1, 1)))+ if not progress_options['dont_show_album_progress']:+ progress_table.add_row(Panel.fit(album_progress, title="Albums Being Downloaded", border_style="green", padding=(1, 1)))+ if not progress_options['dont_show_file_progress']:+ progress_table.add_row(Panel.fit(file_progress, title="[b]Files Being Downloaded", border_style="green", padding=(1, 1)))return progress_tablediff --git a/cyberdrop_dl/main.py b/cyberdrop_dl/main.pyindex 8e8607dc4..0edf78640 100644--- a/cyberdrop_dl/main.py+++ b/cyberdrop_dl/main.py@@ -88,6 +88,14 @@ def parse_args() -> argparse.Namespace:parser.add_argument("--jdownloader-password", type=str, help="password to login to jdownloader", default=None)parser.add_argument("--jdownloader-device", type=str, help="device name to login to for jdownloader", default=None)+ # Progress Options+ parser.add_argument("--dont-show-overall-progress", help="Removes overall progress section while downloading", action="store_true")+ parser.add_argument("--dont-show-forum-progress", help="Removes forum progress section while downloading", action="store_true")+ parser.add_argument("--dont-show-thread-progress", help="Removes thread progress section while downloading", action="store_true")+ parser.add_argument("--dont-show-domain-progress", help="Removes domain progress section while downloading", action="store_true")+ parser.add_argument("--dont-show-album-progress", help="Removes album progress section while downloading", action="store_true")+ parser.add_argument("--dont-show-file-progress", help="Removes file progress section while downloading", action="store_true")+# Linksparser.add_argument("links", metavar="link", nargs="*", help="link to content to download (passing multiple links is supported)", default=[])args = parser.parse_args()