Skip to content

Bulk asynchronous downloader for multiple file hosts

Attempt output for aiorun error handling.

Jules-WinnfieldX9edef87b5f82
diff --git a/cyberdrop_dl/__init__.py b/cyberdrop_dl/__init__.py
index 2bc63ad33..4d9cc5794 100644
--- a/cyberdrop_dl/__init__.py
+++ b/cyberdrop_dl/__init__.py
@@ -1 +1 @@
-__version__ = "4.2.78"
+__version__ = "4.2.79"
diff --git a/cyberdrop_dl/downloader/progress_definitions.py b/cyberdrop_dl/downloader/progress_definitions.py
index ad6195838..0b04238d6 100644
--- a/cyberdrop_dl/downloader/progress_definitions.py
+++ b/cyberdrop_dl/downloader/progress_definitions.py
@@ -156,8 +156,8 @@ class _Progress:
else:
self.overflow.update(self.overflow_task_id, visible=False)
- async def add_task(self, description: str, total: int) -> TaskID:
- if total == 0:
+ async def add_task(self, description: str, total: int, initiated: bool) -> TaskID:
+ if not initiated:
task_id = self.progress.add_task(self.progress_str.format(color=self.color, description=description), total=total, visible=False)
self.uninitiated_tasks.append(task_id)
elif len(self.visible_tasks) >= self.tasks_visibility_limit:
@@ -189,6 +189,10 @@ class _Progress:
self.completed_tasks.append(task_id)
async def advance_task(self, task_id: TaskID, amount: int) -> None:
+ if task_id in self.uninitiated_tasks:
+ self.uninitiated_tasks.remove(task_id)
+ self.invisible_tasks.append(task_id)
+ await self.redraw()
self.progress.advance(task_id, amount)
async def update_total(self, task_id: TaskID, total: int) -> None:
@@ -211,7 +215,7 @@ class ForumProgress:
self.progress = _Progress(self.forum_progress, progressions.forum_progress_overflow, self.color, "Threads", 5)
async def add_forum(self, total_tasks: int) -> TaskID:
- return await self.progress.add_task("FORUM THREADS", total_tasks)
+ return await self.progress.add_task("FORUM THREADS", total_tasks, True)
async def advance_forum(self, task_id: TaskID) -> None:
await self.progress.advance_task(task_id, 1)
@@ -227,7 +231,7 @@ class CascadeProgress:
self.progress = _Progress(self.cascade_progress, progressions.cascade_progress_overflow, self.color, "Threads", visible_tasks_limit)
async def add_cascade(self, title: str, total_domains: int) -> TaskID:
- task_id = await self.progress.add_task(title.upper(), total_domains)
+ task_id = await self.progress.add_task(title.upper(), total_domains, True)
await self.progress.redraw()
return task_id
@@ -254,7 +258,7 @@ class DomainProgress:
self.domain_totals[domain] += total_albums
await self.progress.update_total(self.domains[domain], self.domain_totals[domain])
else:
- self.domains[domain] = await self.progress.add_task(domain.upper(), total_albums)
+ self.domains[domain] = await self.progress.add_task(domain.upper(), total_albums, True)
self.domain_totals[domain] = total_albums
await self.progress.redraw()
@@ -291,7 +295,7 @@ class AlbumProgress:
self.albums_totals[task_description] += total_files
await self.progress.update_total(self.albums[task_description], self.albums_totals[task_description])
else:
- self.albums[task_description] = await self.progress.add_task(task_description, total_files)
+ self.albums[task_description] = await self.progress.add_task(task_description, total_files, True)
self.albums_totals[task_description] = total_files
await self.progress.redraw()
@@ -325,7 +329,7 @@ class FileProgress:
task_description = task_description.encode("ascii", "ignore").decode().strip()
task_description = adjust_title(task_description)
- task_id = await self.progress.add_task(task_description.upper(), expected_size if expected_size else 0)
+ task_id = await self.progress.add_task(task_description.upper(), expected_size if expected_size else 0, False)
await self.progress.redraw()
return task_id
diff --git a/cyberdrop_dl/main.py b/cyberdrop_dl/main.py
index f8143f2ad..562a5d6f1 100644
--- a/cyberdrop_dl/main.py
+++ b/cyberdrop_dl/main.py
@@ -336,7 +336,17 @@ def main(args=None):
)
with contextlib.suppress(RuntimeError, asyncio.CancelledError):
- aiorun.run(director(args, links), stop_on_unhandled_errors=True)
+ loop = asyncio.new_event_loop()
+ asyncio.set_event_loop(loop)
+
+ def handler(loop, context):
+ # https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.call_exception_handler
+ log(f'Stopping loop due to error: {context["exception"]}', quiet=True)
+ loop.stop()
+
+ loop.set_exception_handler(handler)
+ loop.create_task(director(args, links))
+ aiorun.run(loop=loop)
if __name__ == '__main__':