Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
merge fix
datawhores43d5304a56b3
diff --git a/cyberdrop_dl/clients/hash_client.py b/cyberdrop_dl/clients/hash_client.pyindex 95da32e71..ab5d62c55 100644--- a/cyberdrop_dl/clients/hash_client.py+++ b/cyberdrop_dl/clients/hash_client.py@@ -105,38 +105,16 @@ class HashClient:async with self.manager.live_manager.get_remove_file_via_hash_live():# #remove downloaded files, so each group only has the first downloaded file- for hash, size_dict in hashes_dict.items():- for size, files in size_dict.items():- selected_file = None- for file in files:- if file.is_file() and file in self.manager.path_manager.prev_downloads_paths:- selected_file = file- break- elif file.is_file():- selected_file = file- continue- for file in filter(lambda x: x != selected_file, files):- try:- self.send2trash(file)- await log(f"Sent new download : {str(file)} to trash with hash {hash}", 10)- await self.manager.progress_manager.hash_progress.add_removed_file()- except OSError:- pass-- if selected_file:- size_dict[size] = {'selected': selected_file,- 'others': list(map(lambda x: str(x.absolute()), files))}- else:- del size_dict[size]+ final_dict=await self.get_candiate_per_group(hashes_dict)- for hash, size_dict in hashes_dict.items():+ for hash, size_dict in final_dict.items():for size, data in size_dict.items():selected_file = data['selected']other_files = data['others']# Get all matches from the databaseall_matches = list(map(lambda x: pathlib.Path(x[0], x[1]),- await self.manager.db_manager.hash_table.get_files_with_hash_matches(hash,+ await self.manager.db_manager.hash_table.get_files_with_hash_matches(hash,size)))# Filter out files with the same path as any file in other_files@@ -144,12 +122,13 @@ class HashClient:# Filter files based on if the file existsexisting_other_matches = list(filter(lambda x: x.exists(), other_matches))- # what do do with prev matches and current file- if len(existing_other_matches) == 0:- pass- elif not self.manager.config_manager.global_settings_data['Dupe_Cleanup_Options'][- 'keep_prev_download']:- for ele in existing_other_matches:+ # skip if both true+ if self.keep_all_files:+ return++ # keep a previous downloads+ if self.keep_one_prev_download_only:+ for ele in existing_other_matches[1:]:if not ele.exists():continuetry:@@ -158,9 +137,10 @@ class HashClient:await self.manager.progress_manager.hash_progress.add_removed_prev_file()except OSError:continue- # delete all prev match except for one- else:- for ele in existing_other_matches[1:]:+ return+ #delete all prev files+ else :+ for ele in existing_other_matches:if not ele.exists():continuetry:@@ -169,16 +149,14 @@ class HashClient:await self.manager.progress_manager.hash_progress.add_removed_prev_file()except OSError:continue+ #keep current downloadif self.manager.config_manager.global_settings_data['Dupe_Cleanup_Options']['keep_new_download']:continue- elif not self.manager.config_manager.global_settings_data['Dupe_Cleanup_Options'][- 'keep_prev_download']:+ elif hash not in self.prev_hashes:continueelif selected_file in self.manager.path_manager.prev_downloads_paths:continue- elif hash not in self.prev_hashes:- continue-+ # delete current downloadelse:try:if ele.exists():@@ -189,9 +167,47 @@ class HashClient:except OSError:pass+ async def get_candiate_per_group(self,hashes_dict):+ for hash, size_dict in hashes_dict.items():+ for size, files in size_dict.items():+ selected_file = None+ for file in files:+ if file.is_file() and file in self.manager.path_manager.prev_downloads_paths:+ selected_file = file+ break+ elif file.is_file():+ selected_file = file+ continue+ for file in filter(lambda x: x != selected_file, files):+ try:+ self.send2trash(file)+ await log(f"Sent new download : {str(file)} to trash with hash {hash}", 10)+ await self.manager.progress_manager.hash_progress.add_removed_file()+ except OSError:+ pass++ if selected_file:+ size_dict[size] = {'selected': selected_file,+ 'others': list(map(lambda x: str(x.absolute()), files))}+ else:+ del size_dict[size]+ return hashes_dictdef send2trash(self, path):if self.manager.config_manager.global_settings_data['Dupe_Cleanup_Options']['delete_off_disk']:pathlib.Path(path).unlink(missing_ok=True)else:send2trash(path)++ @property+ def keep_all_files(self):+ return self.manager.config_manager.global_settings_data['Dupe_Cleanup_Options']['keep_prev_download'] and self.manager.config_manager.global_settings_data['Dupe_Cleanup_Options']['keep_new_download']+ @property+ def keep_one_prev_download_only(self):+ both_false=(not self.manager.config_manager.global_settings_data['Dupe_Cleanup_Options']['keep_prev_download'] and not self.manager.config_manager.global_settings_data['Dupe_Cleanup_Options']['keep_new_download'])++ prev_true=(self.manager.config_manager.global_settings_data['Dupe_Cleanup_Options'][+ 'keep_prev_download'])+ if both_false or prev_true:+ return True+ return False