Skip to content

Bulk asynchronous downloader for multiple file hosts

add use of hash while downloading seperate mark_complete into two helpers

datawhores705f7e3e76d7
diff --git a/cyberdrop_dl/clients/download_client.py b/cyberdrop_dl/clients/download_client.py
index 38251ecc0..70b3714c4 100644
--- a/cyberdrop_dl/clients/download_client.py
+++ b/cyberdrop_dl/clients/download_client.py
@@ -15,6 +15,7 @@ from aiohttp import ClientSession
from cyberdrop_dl.clients.errors import DownloadFailure, InvalidContentTypeFailure
from cyberdrop_dl.utils.utilities import FILE_FORMATS, log
+from cyberdrop_dl.clients.hash_client import HashClient
if TYPE_CHECKING:
from typing import Callable, Coroutine, Any
@@ -116,7 +117,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 False
ext = Path(media_item.filename).suffix.lower()
@@ -178,9 +179,18 @@ class DownloadClient:
await self.manager.db_manager.history_table.insert_incompleted(domain, media_item)
async def mark_completed(self, media_item: MediaItem, domain: str) -> None:
+ await self._add_db(media_item,domain)
+ await self._handle_media_item_completion(media_item)
+
+ async def _add_db(self,media_item: MediaItem, domain: str):
"""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)
+
+ async def _handle_media_item_completion(self, media_item) -> None:
+ """Handle hashing completed items and adds item to the completed list"""
self.manager.path_manager.add_completed(media_item)
+ if self.manager.config_manager.global_settings_data['Dupe_Cleanup_Options']['hash_while_downloading']:
+ await HashClient(self.manager).hash_item(media_item.complete_file)
"""~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""
diff --git a/cyberdrop_dl/clients/hash_client.py b/cyberdrop_dl/clients/hash_client.py
index b02a5629a..37630b6fb 100644
--- a/cyberdrop_dl/clients/hash_client.py
+++ b/cyberdrop_dl/clients/hash_client.py
@@ -23,9 +23,9 @@ class HashClient:
if not pathlib.Path(path).is_dir():
raise Exception("Path is not a directory")
for file in pathlib.Path(path).glob("**/*"):
- await self._hash_item_helper(file)
+ await self.hash_item(file)
- async def _hash_item_helper(self,file):
+ async def hash_item(self,file):
hash=await self.manager.db_manager.hash_table.get_file_hash_exists(file)
if not hash and file.exists():
hash = await self.manager.hash_manager.hash_file(file)
@@ -38,7 +38,7 @@ class HashClient:
hashes_dict=defaultdict(list)
# first compare downloads to each other
for item in self.manager.path_manager.completed_downloads:
- hash=await self._hash_item_helper(item)
+ hash=await self.hash_item(item)
if hash:
hashes_dict[hash].append(item)
#remove downloaded files, so each group only has the first downloaded file
diff --git a/cyberdrop_dl/utils/database/tables/hash_table.py b/cyberdrop_dl/utils/database/tables/hash_table.py
index 4059ecd9b..e3e7ffb3c 100644
--- a/cyberdrop_dl/utils/database/tables/hash_table.py
+++ b/cyberdrop_dl/utils/database/tables/hash_table.py
@@ -30,7 +30,7 @@ class HashTable:
try:
# Extract folder, filename, and size from the full path
- path = pathlib.Path(full_path)
+ path = pathlib.Path(full_path).absolute()
folder = str(path.parent)
filename = path.name
size = path.stat().st_size