Skip to content

Commit

Permalink
refactor: fix prompts for deduping changes
Browse files Browse the repository at this point in the history
  • Loading branch information
datawhores committed Nov 19, 2024
1 parent 2b3b76c commit 657dacb
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 36 deletions.
4 changes: 2 additions & 2 deletions cyberdrop_dl/clients/hash_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ def _get_key_from_file(file: Path | str):
return str(Path(file).absolute())
async def hash_item_helper(self, file: Path | str, original_filename: str, referer: URL):
hash=await self.hash_item(file, original_filename,referer,hash_type=self.xxhash)
if self.manager.config_manager.settings_data["Dupe_Cleanup_Options"]["allow_md5_hash"]:
if self.manager.config_manager.settings_data["Dupe_Cleanup_Options"]["add_md5_hash"]:
await self.hash_item(file, original_filename,referer,hash_type=self.md5)
if self.manager.config_manager.settings_data["Dupe_Cleanup_Options"]["allow_sha256_hash"]:
if self.manager.config_manager.settings_data["Dupe_Cleanup_Options"]["add_sha256_hash"]:
await self.hash_item(file, original_filename, referer, hash_type=self.sha256)
return hash

Expand Down
2 changes: 1 addition & 1 deletion cyberdrop_dl/scraper/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
remove_trailing_slash,
)
from cyberdrop_dl.scraper.jdownloader import JDownloader
from cyberdrop_dl.utils.constants import BLOCKED_DOMAINS, PRELEASE_TAGS, REGEX_LINKS
from cyberdrop_dl.utils.constants import BLOCKED_DOMAINS,REGEX_LINKS
from cyberdrop_dl.utils.data_enums_classes.url_objects import MediaItem, ScrapeItem
from cyberdrop_dl.utils.logger import log
from cyberdrop_dl.utils.utilities import get_download_path, get_filename_and_ext
Expand Down
62 changes: 33 additions & 29 deletions cyberdrop_dl/ui/prompts/settings_global_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,50 +217,54 @@ def edit_dupe_settings_prompt(manager: Manager) -> None:
console.clear()
console.print("Editing Duplicate File Settings")

delete_after = inquirer.select(
message="Toggle duplicate files deletion using hashes:",
default=manager.config_manager.settings_data["s"]["delete_after_download"],
choices=[Choice(True, "True"), Choice(False, "False")],
hashing = inquirer.select(
message="Enable File Hashing from disk",
default=manager.config_manager.settings_data["Dupe_Cleanup_Options"]["hashing"],
choices=[Choice(0, "Turn Hashing OFF"), Choice(1, "Hash via xxh128 after each download"),Choice(2, "Hash via xxh128 after all downloads")],
vi_mode=manager.vi_mode,
).execute()

dedupe_already_downloaded = inquirer.select(
message="How to handle files already on system: ",
default=manager.config_manager.settings_data["Dupe_Cleanup_Options"]["dedupe_already_downloaded"],
choices=[Choice(True, "Mark Existing Files as 'new'"), Choice(False, "Skip Existing Files")],

dedupe = inquirer.select(
message="Modify How files are deduped",
default=manager.config_manager.settings_data["Dupe_Cleanup_Options"]["hashing"],
choices=[Choice(0, "Turn Deduping OFF"), Choice(1, "KEEP_OLDEST"),Choice(2, "KEEP_NEWEST"),Choice(3, "KEEP_OLDEST_ALL"),Choice(4, "KEEP_NEWEST_ALL")],
vi_mode=manager.vi_mode,
).execute()

keep_current = inquirer.select(
message="What to do with new file when deduping: ",
long_instruction="Keep a curent file. Current files are files that were either downloaded or a file was skipped for already existing when dedupe_already_downloaded is true",
default=manager.config_manager.settings_data["Dupe_Cleanup_Options"]["keep_new_download"],
choices=[Choice(True, "Keep one current file"), Choice(False, "Delete selected current file"), Choice(None, "Keep all current files wth same hash")],
send_deleted_to_trash = inquirer.select(
message="How to handle removal of files: ",
default=manager.config_manager.settings_data["Dupe_Cleanup_Options"]["send_deleted_to_trash"],
choices=[ Choice(True, "Send to Trash"),Choice(False, "Permanently Delete File")],
vi_mode=manager.vi_mode,
).execute()

keep_prev = inquirer.select(
message="What to do with previous file(s) when deduping:",
default=manager.config_manager.settings_data["Dupe_Cleanup_Options"],
long_instruction="Any file that is not in the list of current files with a matching hash",
choices=[Choice(True, "Keep a previous file "),Choice(None, "Keep all previous files")],

add_md5_hash = inquirer.select(
message="md5 hashing: ",
default=manager.config_manager.settings_data["Dupe_Cleanup_Options"]["add_md5_hash"],
choices=[ Choice(True, "Add md5 hashes when hashing from disk"),Choice(False, "skip md5 hashing when hashing from disk")],
vi_mode=manager.vi_mode,
).execute()

delete_off_disk = inquirer.select(
message="How to handle removal of files: ",
default=manager.config_manager.settings_data["Dupe_Cleanup_Options"]["delete_off_disk"],
choices=[Choice(True, "Permanently Delete File"), Choice(False, "Send to Trash")],

add_sha256_hash = inquirer.select(
message="md5 hashing: ",
default=manager.config_manager.settings_data["Dupe_Cleanup_Options"]["add_sha256_hash"],
choices=[ Choice(True, "Add sha256 hashes when hashing from disk"),Choice(False, "skip sha256 hashing when hashing from disk")],
vi_mode=manager.vi_mode,
).execute()

manager.config_manager.settings_data["Dupe_Cleanup_Options"]["delete_after_download"] = delete_after
manager.config_manager.settings_data["Dupe_Cleanup_Options"]["keep_prev_download"] = keep_prev
manager.config_manager.settings_data["Dupe_Cleanup_Options"]["keep_new_download"] = keep_current
manager.config_manager.settings_data["Dupe_Cleanup_Options"]["hashing"] = hashing
manager.config_manager.settings_data["Dupe_Cleanup_Options"]["dedupe"] = dedupe



manager.config_manager.settings_data["Dupe_Cleanup_Options"]["send_deleted_to_trash"] = send_deleted_to_trash

manager.config_manager.settings_data["Dupe_Cleanup_Options"]["add_md5_hash"] = add_md5_hash

manager.config_manager.settings_data["Dupe_Cleanup_Options"]["add_sha256_hash"] = add_sha256_hash

manager.config_manager.settings_data["Dupe_Cleanup_Options"]["dedupe_already_downloaded"] = (
dedupe_already_downloaded
)

manager.config_manager.settings_data["Dupe_Cleanup_Options"]["delete_off_disk"] = delete_off_disk

2 changes: 1 addition & 1 deletion cyberdrop_dl/ui/prompts/user_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from cyberdrop_dl.ui.prompts.defaults import ALL_CHOICE, DONE_CHOICE, EXIT_CHOICE
from cyberdrop_dl.utils.constants import BROWSERS, RESERVED_CONFIG_NAMES
from cyberdrop_dl.utils.cookie_extraction import get_cookies_from_browsers
from cyberdrop_dl.utils.dataclasses.supported_domains import SupportedDomains
from cyberdrop_dl.utils.data_enums_classes.supported_domains import SupportedDomains
from cyberdrop_dl.utils.utilities import clear_term

if TYPE_CHECKING:
Expand Down
4 changes: 2 additions & 2 deletions cyberdrop_dl/utils/args/config_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@
"Dupe_Cleanup_Options": {
"hashing":"IN_PLACE",
"dedupe": "KEEP_OLDEST_ALL",
"allow_md5_hash": False,
"allow_sha256_hash": False,
"add_md5_hash": False,
"add_sha256_hash": False,
"send_deleted_to_trash": True,
},

Expand Down
2 changes: 1 addition & 1 deletion cyberdrop_dl/utils/cookie_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from rich.console import Console

from cyberdrop_dl.dependencies import browser_cookie3
from cyberdrop_dl.utils.dataclasses.supported_domains import SupportedDomains
from cyberdrop_dl.utils.data_enums_classes.supported_domains import SupportedDomains

if TYPE_CHECKING:
from http.cookiejar import CookieJar
Expand Down

0 comments on commit 657dacb

Please sign in to comment.