Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
perf: hash multiple files at the same time (#160)
NTFSvolume14ae2167ad58
diff --git a/cyberdrop_dl/hasher.py b/cyberdrop_dl/hasher.pyindex 82dad3760..5f489b529 100644--- a/cyberdrop_dl/hasher.py+++ b/cyberdrop_dl/hasher.py@@ -102,8 +102,9 @@ class Hasher:try:self._tui = tui- async for file in aio.rglob(path, "*"):- _ = await self.update_db_and_retrive_hash(file)+ async with asyncio.TaskGroup() as tg:+ async for file in aio.rglob(path, "*"):+ _ = tg.create_task(self.update_db_and_retrive_hash(file))finally:self._tui = old_tui@@ -148,15 +149,17 @@ class Hasher:except IsADirectoryError:return- with self._tui.new_file(file):- logger.info("Computing hashes of '%s'", file)- hash = await self._update_db_and_retrive_hash(file, original_filename, referer, hash_type="xxh128")- if self.config.add_md5_hash:- await self._update_db_and_retrive_hash(file, original_filename, referer, hash_type="md5")- if self.config.add_sha256_hash:- await self._update_db_and_retrive_hash(file, original_filename, referer, hash_type="sha256")-- return hash+ async with self._sem:+ with self._tui.new_file(file):+ async with asyncio.TaskGroup() as tg:+ logger.info("Computing hashes of '%s'", file)+ hash = tg.create_task(self._update_db_and_retrive_hash(file, original_filename, referer, "xxh128"))+ if self.config.add_md5_hash:+ tg.create_task(self._update_db_and_retrive_hash(file, original_filename, referer, "md5"))+ if self.config.add_sha256_hash:+ tg.create_task(self._update_db_and_retrive_hash(file, original_filename, referer, "sha256"))++ return hash.result()async def _update_db_and_retrive_hash(self,diff --git a/cyberdrop_dl/progress/hashing.py b/cyberdrop_dl/progress/hashing.pyindex caa3fdeb7..5e02a1284 100644--- a/cyberdrop_dl/progress/hashing.py+++ b/cyberdrop_dl/progress/hashing.py@@ -79,9 +79,7 @@ class HashingUI(LiveUI):self._progress.update(task_id, total=current_total, completed=getattr(self._stats, name))self._total = current_total- self._panel.subtitle = (- f"Files: [white]{current_total:,}[/white], Hashes: [white]{self._stats.computed_hashes:,}[/white]"- )+ self._panel.subtitle = f"Files: [white]{current_total:,}[/white], New Computed Hashes: [white]{self._stats.computed_hashes:,}[/white]"return self._paneldef new_file(self, file: Path):@@ -94,6 +92,8 @@ class HashingUI(LiveUI):def add_completed(self, hash_type: Literal["xxh128", "md5", "sha256"]):setattr(self._stats, hash_type, getattr(self._stats, hash_type) + 1)+ if hash_type == "xxh128":+ self.stats.new_hashed += 1if __name__ == "__main__":