Skip to content

Bulk asynchronous downloader for multiple file hosts

Fix retry limiter.

Jules-WinnfieldX7e0915ebf007
diff --git a/cyberdrop_dl/__init__.py b/cyberdrop_dl/__init__.py
index 8acd9410c..c2908cf34 100644
--- a/cyberdrop_dl/__init__.py
+++ b/cyberdrop_dl/__init__.py
@@ -1 +1 @@
-__version__ = "2.22.3"
+__version__ = "2.22.4"
diff --git a/cyberdrop_dl/main.py b/cyberdrop_dl/main.py
index d6a436a70..7654c5bd8 100644
--- a/cyberdrop_dl/main.py
+++ b/cyberdrop_dl/main.py
@@ -1,8 +1,9 @@
import argparse
+from argparse import Namespace
import asyncio
import logging
from pathlib import Path
-from argparse import Namespace
+import sys
from colorama import Fore
from yarl import URL
@@ -101,7 +102,14 @@ def main(args=None):
format="%(asctime)s:%(levelname)s:%(module)s:%(filename)s:%(lineno)d:%(message)s",
filemode="w"
)
- asyncio.get_event_loop().run_until_complete(download_all(args))
+ if sys.version_info[0] == 3 and sys.version_info[1] >= 8 and sys.platform.startswith('win'):
+ asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
+
+ loop = asyncio.get_event_loop()
+ loop.run_until_complete(download_all(args))
+ loop.run_until_complete(asyncio.sleep(1))
+ loop.close()
+
if __name__ == '__main__':
diff --git a/cyberdrop_dl/utils/downloaders.py b/cyberdrop_dl/utils/downloaders.py
index d1681cceb..74f250ea0 100644
--- a/cyberdrop_dl/utils/downloaders.py
+++ b/cyberdrop_dl/utils/downloaders.py
@@ -33,10 +33,11 @@ def retry(f):
return await f(self, *args, **kwargs)
except FailureException:
if not self.disable_attempt_limit:
- if self.current_attempt >= self.attempts - 1:
+ if self.current_attempt[str(args[0])] >= self.attempts - 1:
+ logger.debug('Skipping %s...' % args[0])
raise
logger.debug('Retrying %s...' % args[0])
- self.attempts += 1
+ self.current_attempt[str(args[0])] += 1
await asyncio.sleep(2)
return wrapper
@@ -78,7 +79,7 @@ class Downloader:
self.File_Lock = FileLock()
self.attempts = attempts
- self.current_attempt = 0
+ self.current_attempt = {}
self.disable_attempt_limit = disable_attempt_limit
self.exclude_videos = exclude_videos
@@ -103,6 +104,7 @@ class Downloader:
show_progress: bool = True
) -> None:
"""Download the content of given URL"""
+ self.current_attempt[str(url)] = 0
headers = {'Referer': str(referral), 'user-agent': user_agent}
# return if completed already