Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
add post_runtime to no ui option and ui option store completed paths in path manager via manager class
datawhores4f8f9296f749
diff --git a/cyberdrop_dl/clients/download_client.py b/cyberdrop_dl/clients/download_client.pyindex 94df891c0..38251ecc0 100644--- a/cyberdrop_dl/clients/download_client.py+++ b/cyberdrop_dl/clients/download_client.py@@ -7,7 +7,7 @@ import osfrom http import HTTPStatusfrom functools import wraps, partialfrom pathlib import Path-from typing import TYPE_CHECKING, Tuple+from typing import TYPE_CHECKING, Tuple,Listimport aiofilesimport aiohttp@@ -59,8 +59,8 @@ class DownloadClient:self._timeouts = aiohttp.ClientTimeout(total=client_manager.read_timeout + client_manager.connection_timeout,connect=client_manager.connection_timeout)self._global_limiter = self.client_manager.global_rate_limiter-self.trace_configs = []+ self._file_path=Noneif os.getenv("PYCHARM_HOSTED") is not None:async def on_request_start(session, trace_config_ctx, params):await log(f"Starting download {params.method} request to {params.url}", 40)@@ -116,6 +116,7 @@ class DownloadClient:await log(f"Skipping {media_item.url} as it has already been downloaded", 10)await self.manager.progress_manager.download_progress.add_previously_completed(False)await self.mark_completed(media_item, domain)+return Falseext = Path(media_item.filename).suffix.lower()@@ -167,6 +168,7 @@ class DownloadClient:if downloaded:media_item.partial_file.rename(media_item.complete_file)await self.mark_completed(media_item, domain)+ self.file_path=media_itemreturn downloaded"""~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""@@ -174,12 +176,14 @@ class DownloadClient:async def mark_incomplete(self, media_item: MediaItem, domain: str) -> None:"""Marks the media item as incomplete in the database"""await self.manager.db_manager.history_table.insert_incompleted(domain, media_item)-+async def mark_completed(self, media_item: MediaItem, domain: str) -> None:- """Marks the media item as completed in the database"""+ """Marks the media item as completed in the database and adds to the completed list"""await self.manager.db_manager.history_table.mark_complete(domain, media_item)+ self.manager.path_manager.add_completed(media_item)"""~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""+async def get_download_dir(self, media_item: MediaItem) -> Path:"""Returns the download directory for the media item"""@@ -296,3 +300,13 @@ class DownloadClient:if max_other_filesize and media.filesize > max_other_filesize:return Falsereturn True++ @property+ def file_path(self) -> List[str]:+ return self._file_path+ @file_path.setter+ def file_path(self, media_item: MediaItem):+ self._file_path = media_item.filename+++diff --git a/cyberdrop_dl/main.py b/cyberdrop_dl/main.pyindex 2268dd924..bd5378da3 100644--- a/cyberdrop_dl/main.py+++ b/cyberdrop_dl/main.py@@ -43,7 +43,13 @@ async def runtime(manager: Manager) -> None:async with asyncio.TaskGroup() as task_group:manager.task_group = task_groupawait scrape_mapper.start()-++async def post_runtime(manager: Manager) -> None:+ """Actions to complete after main runtime, and before ui shutdown"""+ #checking and removing dupes+ downloads=manager.path_manager.completed_downloads+ for download in downloads:+ print(download)async def director(manager: Manager) -> None:"""Runs the program and handles the UI"""@@ -109,8 +115,10 @@ async def director(manager: Manager) -> None:if not manager.args_manager.no_ui:with Live(manager.progress_manager.layout, refresh_per_second=manager.config_manager.global_settings_data['UI_Options']['refresh_rate']):await runtime(manager)+ await post_runtime(manager)else:await runtime(manager)+ await post_runtime(manager)except Exception as e:print("\nAn error occurred, please report this to the developer")print(e)@@ -134,6 +142,10 @@ async def director(manager: Manager) -> None:await log("Updating Last Forum Post...", 20)await manager.log_manager.update_last_forum_post()++ # add the stuff here++await log("Printing Stats...", 20)await manager.progress_manager.print_stats()diff --git a/cyberdrop_dl/managers/client_manager.py b/cyberdrop_dl/managers/client_manager.pyindex ca2d6fe32..383ff2dd9 100644--- a/cyberdrop_dl/managers/client_manager.py+++ b/cyberdrop_dl/managers/client_manager.py@@ -59,6 +59,7 @@ class ClientManager:"""~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""+async def get_downloader_spacer(self, key: str) -> float:"""Returns the download spacer for a domain"""if key in self.download_spacer:@@ -118,6 +119,5 @@ class ClientManager:raise DownloadFailure(status=CustomHTTPStatus.IM_A_TEAPOT, message="No content-type in response header")raise DownloadFailure(status=status, message=f"HTTP status code {status}: {phrase}")-async def check_bucket(self,size):await self._leaky_bucket.acquire(size)diff --git a/cyberdrop_dl/managers/path_manager.py b/cyberdrop_dl/managers/path_manager.pyindex a21f049c7..0a03f4f9a 100644--- a/cyberdrop_dl/managers/path_manager.py+++ b/cyberdrop_dl/managers/path_manager.py@@ -2,6 +2,7 @@ import osfrom dataclasses import fieldfrom pathlib import Pathfrom typing import TYPE_CHECKING+from cyberdrop_dl.utils.dataclasses.url_objects import MediaItemif TYPE_CHECKING:from cyberdrop_dl.managers.manager import Manager@@ -34,7 +35,10 @@ class PathManager:self.unsupported_urls_log: Path = field(init=False)self.download_error_log: Path = field(init=False)self.scrape_error_log: Path = field(init=False)+ self._completed_downloads=[]++def pre_startup(self) -> None:if self.manager.args_manager.appdata_dir:global APP_STORAGE@@ -69,3 +73,9 @@ class PathManager:if not self.input_file.is_file():self.input_file.touch(exist_ok=True)self.history_db.touch(exist_ok=True)++ def add_completed(self,media:MediaItem):+ self._completed_downloads.append(media.complete_file.absolute())+ @property+ def completed_downloads(self):+ return self._completed_downloads\ No newline at end of file