Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
Async functions should not call open or synchronous os methods (#468)
Arkadiy Illarionov4cc6d7f40e2e
diff --git a/cyberdrop_dl/base_functions/base_functions.py b/cyberdrop_dl/base_functions/base_functions.pyindex 8876dcda2..067030709 100644--- a/cyberdrop_dl/base_functions/base_functions.py+++ b/cyberdrop_dl/base_functions/base_functions.py@@ -1,5 +1,6 @@from __future__ import annotations+import asyncioimport loggingimport osimport re@@ -44,7 +45,8 @@ MAX_FILENAME_LENGTH = 95async def clear() -> None:"""Clears the terminal screen"""- os.system('cls' if os.name == 'nt' else 'clear')+ clear_screen_proc = await asyncio.create_subprocess_shell('cls' if os.name == 'nt' else 'clear')+ await clear_screen_proc.wait()def log(text: str, quiet: bool = False, style: str = "") -> None:diff --git a/cyberdrop_dl/main.py b/cyberdrop_dl/main.pyindex dcae83f93..254902d32 100644--- a/cyberdrop_dl/main.py+++ b/cyberdrop_dl/main.py@@ -6,9 +6,10 @@ import refrom pathlib import Pathfrom typing import Dict, List+import aiofilesfrom yarl import URL-from cyberdrop_dl.base_functions.base_functions import clear, log, purge_dir, ErrorFileWriter+from cyberdrop_dl.base_functions.base_functions import ErrorFileWriter, clear, log, purge_dirfrom cyberdrop_dl.base_functions.config_manager import document_args, run_argsfrom cyberdrop_dl.base_functions.config_schema import config_defaultfrom cyberdrop_dl.base_functions.sorting_functions import Sorter@@ -202,8 +203,8 @@ async def consolidate_links(args: Dict, links: List) -> List:"""We consolidate links from command line and from URLs.txt into a singular list"""links = list(map(URL, links))if args["Files"]["input_file"].is_file():- with open(args["Files"]["input_file"], "r", encoding="utf8") as f:- links += await regex_links([line.rstrip() for line in f])+ async with aiofiles.open(args["Files"]["input_file"], "r", encoding="utf8") as f:+ links += await regex_links([line.rstrip() async for line in f])links = list(filter(None, links))if not links:@@ -258,11 +259,10 @@ async def director(args: Dict, links: List) -> None:await asyncio.sleep(5)await clear()- if args['Progress_Options']['hide_new_progress']:- if not await Forums.is_empty():+ if not await Forums.is_empty():+ if args['Progress_Options']['hide_new_progress']:await old_download_forums(args, Forums, SQL_Helper, client)- else:- if not await Forums.is_empty():+ else:download_director = DownloadDirector(args, Forums, SQL_Helper, client, error_writer)await download_director.start()