Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
Deduplicate task_description adjustment
Arkadiy Illarionov6d06e12618b0
diff --git a/cyberdrop_dl/base_functions/base_functions.py b/cyberdrop_dl/base_functions/base_functions.pyindex 2bad099e2..46b4abf03 100644--- a/cyberdrop_dl/base_functions/base_functions.py+++ b/cyberdrop_dl/base_functions/base_functions.py@@ -32,6 +32,11 @@ logger = logging.getLogger(__name__)MAX_FILENAME_LENGTH = 95+async def adjust(s: str, length: int = 40, placeholder: str = "...") -> str:+ """Collapse and truncate or pad the given string to fit in the given length"""+ return f"{s[:length - len(placeholder)]}{placeholder}" if len(s) >= length else s.ljust(length)++async def clear() -> None:"""Clears the terminal screen"""os.system('cls' if os.name == 'nt' else 'clear')diff --git a/cyberdrop_dl/client/client.py b/cyberdrop_dl/client/client.pyindex f31701ac4..1f4d659a0 100644--- a/cyberdrop_dl/client/client.py+++ b/cyberdrop_dl/client/client.py@@ -8,20 +8,19 @@ from http import HTTPStatusfrom pathlib import Pathimport aiofiles+import aiohttp+import certififrom bs4 import BeautifulSoup-from tqdm import tqdmfrom rich.progress import TaskID+from tqdm import tqdmfrom yarl import URL-import aiohttp-import certifi--from cyberdrop_dl.downloader.progress_definitions import file_progress-from .rate_limiting import AsyncRateLimiter, throttle-from ..base_functions.base_functions import logger+from ..base_functions.base_functions import adjust, loggerfrom ..base_functions.data_classes import MediaItemfrom ..base_functions.error_classes import DownloadFailure, InvalidContentTypeFailurefrom ..downloader.downloader_utils import CustomHTTPStatus+from ..downloader.progress_definitions import file_progress+from .rate_limiting import AsyncRateLimiter, throttleclass Client:@@ -171,11 +170,7 @@ class DownloadSession:total = int(resp.headers.get('Content-Length', str(0))) + resume_pointfile.parent.mkdir(parents=True, exist_ok=True)- task_description = media.url.host + ": " + media.filename- if len(task_description) >= 40:- task_description = task_description[:37] + "..."- else:- task_description = task_description.ljust(40)+ task_description = adjust(f"{media.url.host}: {media.filename}")with tqdm(total=total, unit_scale=True, unit='B', leave=False, initial=resume_point,desc=task_description) as progress:diff --git a/cyberdrop_dl/downloader/downloaders.py b/cyberdrop_dl/downloader/downloaders.pyindex 5407a9f09..8aa5feaaa 100644--- a/cyberdrop_dl/downloader/downloaders.py+++ b/cyberdrop_dl/downloader/downloaders.py@@ -10,9 +10,9 @@ import aiofilesimport aiohttp.client_exceptionsfrom rich.live import Livefrom rich.progress import TaskID-from yarl import URLfrom cyberdrop_dl.base_functions.base_functions import (+ adjust,clear,log,logger,@@ -116,10 +116,7 @@ class Downloader:returntask_description = album.split('/')[-1]task_description = task_description.encode("ascii", "ignore").decode().strip()- if len(task_description) >= 40:- task_description = task_description[:37] + "..."- else:- task_description = task_description.ljust(40)+ task_description = adjust(task_description)album_task = album_progress.add_task("[pink3]" + task_description.upper(), total=len(album_obj.media))download_tasks = []for media in album_obj.media:@@ -213,12 +210,8 @@ class Downloader:if range_num:headers['Range'] = range_num- task_description = media.filename- task_description = task_description.encode("ascii", "ignore").decode().strip()- if len(task_description) >= 40:- task_description = task_description[:37] + "..."- else:- task_description = task_description.ljust(40)+ task_description = media.filename.encode("ascii", "ignore").decode().strip()+ task_description = adjust(task_description)file_task = file_progress.add_task("[plum3]" + task_description, progress_type="file")if not await self.SQL_Helper.sql_check_old_existing(url_path) and not fake_download: