Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
change how deduope works and improve docs
datawhores8be7346eab96
diff --git a/cyberdrop_dl/clients/download_client.py b/cyberdrop_dl/clients/download_client.pyindex 986959819..8a6107d00 100644--- a/cyberdrop_dl/clients/download_client.py+++ b/cyberdrop_dl/clients/download_client.py@@ -200,6 +200,8 @@ class DownloadClient:await self.manager.hash_manager.hash_client.hash_item_during_download(media_item)if downloaded or self.manager.config_manager.global_settings_data['Dupe_Cleanup_Options']['dedupe_already_downloaded']:self.manager.path_manager.add_completed(media_item)+ if not downloaded:+ self.manager.path_manager.add_prev(media_item)except Exception as e:await log(f"Error handling media item completion: {str(e)}", 10)diff --git a/cyberdrop_dl/clients/hash_client.py b/cyberdrop_dl/clients/hash_client.pyindex 2fdfaa5d3..f3ed657b0 100644--- a/cyberdrop_dl/clients/hash_client.py+++ b/cyberdrop_dl/clients/hash_client.py@@ -35,7 +35,7 @@ class HashClient:yieldawait self.manager.close()async def startup(self):- self.prev_hashes=set(self.manager.db_manager.hash_table.get_all_unique_hashes())+ self.prev_hashes=set(await self.manager.db_manager.hash_table.get_all_unique_hashes())@@ -90,8 +90,7 @@ class HashClient:returnhashes_dict=defaultdict(lambda: defaultdict(list))# first compare downloads to each other- for media_item in list(self.manager.path_manager.completed_downloads):-+ for media_item in list(self.manager.path_manager.completed_downloads):hash=await self.hash_item(media_item.complete_file,media_item.original_filename,media_item.referer)item=media_item.complete_file.absolute()try:@@ -107,9 +106,12 @@ class HashClient:for size, files in size_dict.items():selected_file = Nonefor file in files:- if file.is_file():+ if file.is_file() and file in self.manager.path_manager.prev_downloads_paths:selected_file = file- break+ break+ elif file.is_file():+ selected_file = file+ continuefor file in filter(lambda x:x!=selected_file,files):try:send2trash(file)@@ -135,7 +137,7 @@ class HashClient:# Filter out files with the same path as any file in other_filesfiltered_matches = [match for match in all_matches if str(match) not in other_files]#Filter files based on if the file exists- filtered_matches = list(filter(lambda x: x.exists(),filtered_matches ))+ filtered_matches = list(filter(lambda x: x.exists(),filtered_matches ))#what do do with prev matches and current fileif len(filtered_matches) == 0:@@ -161,8 +163,15 @@ class HashClient:await self.manager.progress_manager.hash_progress.add_removed_prev_file()except OSError:continue-- if not self.manager.config_manager.global_settings_data['Dupe_Cleanup_Options']['keep_new_download'] and hash in self.prev_hashes:+ if self.manager.config_manager.global_settings_data['Dupe_Cleanup_Options']['keep_new_download']:+ continue+ elif hash not in self.prev_hashes:+ continue+ elif self.manager.config_manager.global_settings_data['Dupe_Cleanup_Options']['keep_prev_download']:+ send2trash(ele)+ elif selected_file in self.manager.path_manager.prev_downloads_paths:+ continue+ else:try:if ele.exists():send2trash(ele)diff --git a/cyberdrop_dl/managers/hash_manager.py b/cyberdrop_dl/managers/hash_manager.pyindex f070b707c..b8b62bfcd 100644--- a/cyberdrop_dl/managers/hash_manager.py+++ b/cyberdrop_dl/managers/hash_manager.py@@ -6,7 +6,9 @@ class HashManager:def __init__(self,manager):self.hasher = self._get_hasher() # Initialize hasher in constructorself.hash_client = HashClient(manager) # Initialize hash client in constructor-+ async def startup(self):+ await self.hash_client.startup()+def _get_hasher(self):"""Tries to import xxhash, otherwise falls back to hashlib.md5"""try:diff --git a/cyberdrop_dl/managers/manager.py b/cyberdrop_dl/managers/manager.pyindex c2156d65b..e3c8a983e 100644--- a/cyberdrop_dl/managers/manager.py+++ b/cyberdrop_dl/managers/manager.py@@ -94,6 +94,7 @@ class Manager:self.download_manager = DownloadManager(self)if not isinstance(self.hash_manager, HashManager):self.hash_manager = HashManager(self)+ await self.hash_manager.startup()if not isinstance(self.live_manager, LiveManager):self.live_manager = LiveManager(self)if not isinstance(self.console_manager, ConsoleManager):@@ -114,6 +115,7 @@ class Manager:await self.db_manager.startup()if not isinstance(self.hash_manager, HashManager):self.hash_manager = HashManager(self)+ await self.hash_manager.startup()if not isinstance(self.live_manager, LiveManager):self.live_manager = LiveManager(self)if not isinstance(self.console_manager, ConsoleManager):diff --git a/cyberdrop_dl/managers/path_manager.py b/cyberdrop_dl/managers/path_manager.pyindex f0c0b49f2..caaf2b60d 100644--- a/cyberdrop_dl/managers/path_manager.py+++ b/cyberdrop_dl/managers/path_manager.py@@ -36,6 +36,9 @@ class PathManager:self.download_error_log: Path = field(init=False)self.scrape_error_log: Path = field(init=False)self._completed_downloads=set()+ self._completed_downloads_set=set()+ self._prev_downloads=set()+ self._prev_downloads_set=set()@@ -76,6 +79,20 @@ class PathManager:def add_completed(self,media_item:MediaItem):self._completed_downloads.add(media_item)+ self._completed_downloads_set.add(media_item.complete_file.absolute())+ def add_prev(self,media_item:MediaItem):+ self._prev_downloads.add(media_item)+ self._prev_downloads_set.add(media_item.complete_file.absolute())@propertydef completed_downloads(self):- return self._completed_downloads\ No newline at end of file+ return self._completed_downloads+ @property+ def prev_downloads(self):+ return self._prev_downloads+ @property+ def completed_downloads_paths(self):+ return self._completed_downloads_set++ @property+ def prev_downloads_paths(self):+ return self._prev_downloads_set\ No newline at end of filediff --git a/cyberdrop_dl/utils/database/tables/hash_table.py b/cyberdrop_dl/utils/database/tables/hash_table.pyindex 3874e3377..54a794f67 100644--- a/cyberdrop_dl/utils/database/tables/hash_table.py+++ b/cyberdrop_dl/utils/database/tables/hash_table.py@@ -135,7 +135,7 @@ WHERE download_filename = ? AND folder = ?;""",return False- async def get_all_hashes(self):+ async def get_all_unique_hashes(self):"""Retrieves a list of (folder, filename) tuples based on a given hash.@@ -151,7 +151,7 @@ WHERE download_filename = ? AND folder = ?;""",try:await cursor.execute("SELECT DISTINCT hash FROM hash")results = await cursor.fetchall()- return results+ return list(map(lambda x: x[0], results))except Exception as e:console.print(f"Error retrieving folder and filename: {e}")return []diff --git a/docs/reference/configuration-options/global-settings.md b/docs/reference/configuration-options/global-settings.mdindex 5d4610ec9..c839c12e8 100644--- a/docs/reference/configuration-options/global-settings.md+++ b/docs/reference/configuration-options/global-settings.md@@ -117,6 +117,52 @@ Set to 0 or None to disable</details>+<details>++<summary>UI Options</summary>++These are options for enable/disable dupe clean up+***++* dedupe\_already\_downloaded+Allows files skipped for already existing on the filesystem to be added to the list of files to process for deduping++***++* delete\_after\_download++This toggles the deduping process, which happens after all downloads have finished++***++* hash\_while\_downloading++With this set as True. Files can be hash after each download, rather than all together++***++* keep_new_download+If enabled for each hash and size match one download will be kept on the system.++If disabled all current files will be deleted if the following is all true+- This is not the first time the hash has appeared in the filesystem+- The file did not exist on the filesystem prior to the current run++or++- keep prev_download is set to true, this ignores if file exists on the filesystem or not+++* keep\_prev\_download+prev downloads are files that are match with the list of files to be processed. A previous download is one not processed by the urls given and that exists in the database for the same hash and file size++If enabled then at least one existing previous download will be kept on system.++If not enabled all previous downloads will be deleted++</details>++<details><summary>UI Options</summary>