Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
add optional vim keybindings (#840)
Browse files Browse the repository at this point in the history
  • Loading branch information
Silencer5179 authored Mar 8, 2024
1 parent ffda05e commit 481559e
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 44 deletions.
4 changes: 3 additions & 1 deletion cyberdrop_dl/managers/args_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(self):
self.no_ui = False
self.load_config_from_args = False
self.load_config_name = ""
self.vi_mode = None

self.other_links: list = []

Expand All @@ -38,7 +39,8 @@ def startup(self) -> None:

self.immediate_download = self.parsed_args['download']
self.load_config_name = self.parsed_args['config']

self.vi_mode = self.parsed_args['vi_mode']

if self.parsed_args['no_ui']:
self.immediate_download = True
self.no_ui = True
Expand Down
2 changes: 2 additions & 0 deletions cyberdrop_dl/managers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(self):
self.task_group: asyncio.TaskGroup = field(init=False)
self.task_list: list = []
self.scrape_mapper = field(init=False)
self.vi_mode: bool = None

def startup(self) -> None:
"""Startup process for the manager"""
Expand All @@ -53,6 +54,7 @@ def startup(self) -> None:
self.cache_manager.startup(self.path_manager.cache_dir / "cache.yaml")
self.config_manager = ConfigManager(self)
self.config_manager.startup()
self.vi_mode = self.config_manager.global_settings_data['General']['vi_mode'] if self.args_manager.vi_mode == None else self.args_manager.vi_mode

self.path_manager.startup()
self.log_manager = LogManager(self)
Expand Down
18 changes: 12 additions & 6 deletions cyberdrop_dl/ui/prompts/general_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ def main_prompt(manager: Manager) -> int:
Choice(9, "Donate"),
Choice(10, "Exit"),
], long_instruction="ARROW KEYS: Navigate | ENTER: Select",
vi_mode=manager.vi_mode,
).execute()

return action


def manage_configs_prompt() -> int:
def manage_configs_prompt(manager: Manager) -> int:
"""Manage Configs Prompt"""
console.clear()
action = inquirer.select(
Expand All @@ -59,12 +60,13 @@ def manage_configs_prompt() -> int:
Choice(6, "Edit Global Values"),
Choice(7, "Done"),
], long_instruction="ARROW KEYS: Navigate | ENTER: Select",
vi_mode=manager.vi_mode,
).execute()

return action


def select_config_prompt(configs: List) -> str:
def select_config_prompt(manager: Manager, configs: List) -> str:
"""Select a config file from a list of configs"""
choice = inquirer.fuzzy(
choices=configs,
Expand All @@ -73,6 +75,7 @@ def select_config_prompt(configs: List) -> str:
invalid_message="Need to select a config.",
message="Select a config file:",
long_instruction="ARROW KEYS: Navigate | TYPE: Filter | TAB: select, ENTER: Finish Selection",
vi_mode=manager.vi_mode,
).execute()

return choice
Expand All @@ -89,14 +92,16 @@ def import_cyberdrop_v4_items_prompt(manager: Manager) -> None:
Choice(1, "Import Config"),
Choice(2, "Import download_history.sql"),
Choice(3, "Done"),
], long_instruction="ARROW KEYS: Navigate | ENTER: Select"
], long_instruction="ARROW KEYS: Navigate | ENTER: Select",
vi_mode=manager.vi_mode,
).execute()

# Import Config
if action == 1:
new_config_name = inquirer.text(
message="What should this config be called?",
validate=EmptyInputValidator("Input should not be empty")
validate=EmptyInputValidator("Input should not be empty"),
vi_mode=manager.vi_mode,
).execute()

if (manager.path_manager.config_dir / new_config_name).is_dir():
Expand All @@ -120,6 +125,7 @@ def import_cyberdrop_v4_items_prompt(manager: Manager) -> None:
message="Select the download_history.sql file to import",
default=home_path,
validate=PathValidator(is_file=True, message="Input is not a file"),
vi_mode=manager.vi_mode,
).execute()

transfer_v4_db(import_download_history_path, manager.path_manager.history_db)
Expand All @@ -129,7 +135,7 @@ def import_cyberdrop_v4_items_prompt(manager: Manager) -> None:
break


def donations_prompt() -> None:
def donations_prompt(manager: Manager) -> None:
"""Donations prompt"""
console.clear()
console.print("[bold]Donations[/bold]")
Expand All @@ -147,4 +153,4 @@ def donations_prompt() -> None:
console.print("")
console.print("Thank you for your support!")
console.print("")
inquirer.confirm(message="Press enter to return to the main menu.").execute()
inquirer.confirm(message="Press enter to return to the main menu.", vi_mode=manager.vi_mode).execute()
30 changes: 25 additions & 5 deletions cyberdrop_dl/ui/prompts/settings_authentication_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def edit_authentication_values_prompt(manager: Manager) -> None:
Choice(5, "Edit Imgur Client ID"),
Choice(6, "Edit PixelDrain API Key"),
Choice(7, "Done"),
], long_instruction="ARROW KEYS: Navigate | ENTER: Select"
], long_instruction="ARROW KEYS: Navigate | ENTER: Select",
vi_mode=manager.vi_mode,
).execute()

# Edit Forums
Expand All @@ -56,6 +57,7 @@ def edit_authentication_values_prompt(manager: Manager) -> None:
message="Enter the GoFile API Key:",
default=auth["GoFile"]["gofile_api_key"],
long_instruction="You can get your premium GoFile API Key from https://gofile.io/myProfile",
vi_mode=manager.vi_mode,
).execute()
auth["GoFile"]["gofile_api_key"] = gofile_api_key

Expand All @@ -66,7 +68,8 @@ def edit_authentication_values_prompt(manager: Manager) -> None:
message="Enter the Imgur Client ID:",
default=auth["Imgur"]["imgur_client_id"],
long_instruction="You can create an app and get your client ID "
"from https://imgur.com/account/settings/apps"
"from https://imgur.com/account/settings/apps",
vi_mode=manager.vi_mode,
).execute()
auth["Imgur"]["imgur_client_id"] = imgur_client_id

Expand All @@ -76,7 +79,8 @@ def edit_authentication_values_prompt(manager: Manager) -> None:
pixeldrain_api_key = inquirer.text(
message="Enter the PixelDrain API Key:",
default=auth["PixelDrain"]["pixeldrain_api_key"],
long_instruction="You can get your premium API Key from https://pixeldrain.com/user/api_keys"
long_instruction="You can get your premium API Key from https://pixeldrain.com/user/api_keys",
vi_mode=manager.vi_mode,
).execute()
auth["PixelDrain"]["pixeldrain_api_key"] = pixeldrain_api_key

Expand All @@ -97,7 +101,8 @@ def edit_forum_authentication_values_prompt(manager: Manager) -> None:
Choice(1, "Browser Cookie Extraction"),
Choice(2, "Enter Cookie Values Manually"),
Choice(3, "Done"),
], long_instruction="ARROW KEYS: Navigate | ENTER: Select"
], long_instruction="ARROW KEYS: Navigate | ENTER: Select",
vi_mode=manager.vi_mode,
).execute()

# Browser Cookie Extraction
Expand All @@ -112,7 +117,8 @@ def edit_forum_authentication_values_prompt(manager: Manager) -> None:
Choice("opera", "Opera"),
Choice("brave", "Brave"),
Choice(1, "Done"),
], long_instruction="ARROW KEYS: Navigate | ENTER: Select"
], long_instruction="ARROW KEYS: Navigate | ENTER: Select",
vi_mode=manager.vi_mode,
).execute()

# Done
Expand All @@ -139,64 +145,78 @@ def edit_forum_authentication_values_prompt(manager: Manager) -> None:
celebforum_username = inquirer.text(
message="Enter your CelebForum Username:",
default=manager.config_manager.authentication_data["Forums"]["celebforum_username"],
vi_mode=manager.vi_mode,
).execute()
celebforum_password = inquirer.text(
message="Enter your CelebForum Password:",
default=manager.config_manager.authentication_data["Forums"]["celebforum_password"],
vi_mode=manager.vi_mode,
).execute()

f95zone_username = inquirer.text(
message="Enter your F95Zone Username:",
default=manager.config_manager.authentication_data["Forums"]["f95zone_username"],
vi_mode=manager.vi_mode,
).execute()
f95zone_password = inquirer.text(
message="Enter your F95Zone Password:",
default=manager.config_manager.authentication_data["Forums"]["f95zone_password"],
vi_mode=manager.vi_mode,
).execute()

leakedmodels_username = inquirer.text(
message="Enter your LeakedModels Username:",
default=manager.config_manager.authentication_data["Forums"]["leakedmodels_username"],
vi_mode=manager.vi_mode,
).execute()
leakedmodels_password = inquirer.text(
message="Enter your LeakedModels Password:",
default=manager.config_manager.authentication_data["Forums"]["leakedmodels_password"],
vi_mode=manager.vi_mode,
).execute()

nudostar_username = inquirer.text(
message="Enter your NudoStar Username:",
default=manager.config_manager.authentication_data["Forums"]["nudostar_username"],
vi_mode=manager.vi_mode,
).execute()
nudostar_password = inquirer.text(
message="Enter your NudoStar Password:",
default=manager.config_manager.authentication_data["Forums"]["nudostar_password"],
vi_mode=manager.vi_mode,
).execute()

simpcity_username = inquirer.text(
message="Enter your SimpCity Username:",
default=manager.config_manager.authentication_data["Forums"]["simpcity_username"],
vi_mode=manager.vi_mode,
).execute()
simpcity_password = inquirer.text(
message="Enter your SimpCity Password:",
default=manager.config_manager.authentication_data["Forums"]["simpcity_password"],
vi_mode=manager.vi_mode,
).execute()

socialmediagirls_username = inquirer.text(
message="Enter your SocialMediaGirls Username:",
default=manager.config_manager.authentication_data["Forums"]["socialmediagirls_username"],
vi_mode=manager.vi_mode,
).execute()
socialmediagirls_password = inquirer.text(
message="Enter your SocialMediaGirls Password:",
default=manager.config_manager.authentication_data["Forums"]["socialmediagirls_password"],
vi_mode=manager.vi_mode,
).execute()

xbunker_username = inquirer.text(
message="Enter your XBunker Username:",
default=manager.config_manager.authentication_data["Forums"]["xbunker_username"],
vi_mode=manager.vi_mode,
).execute()
xbunker_password = inquirer.text(
message="Enter your XBunker Password:",
default=manager.config_manager.authentication_data["Forums"]["xbunker_password"],
vi_mode=manager.vi_mode,
).execute()

manager.config_manager.authentication_data["Forums"]["celebforum_username"] = celebforum_username
Expand Down
30 changes: 25 additions & 5 deletions cyberdrop_dl/ui/prompts/settings_global_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def edit_global_settings_prompt(manager: Manager) -> None:
Choice(2, "Edit Rate Limiting Settings"),
Choice(3, "Done"),
],
vi_mode=manager.vi_mode,
).execute()

# Edit General Settings
Expand All @@ -45,34 +46,45 @@ def edit_general_settings_prompt(manager: Manager) -> None:
"""Edit the general settings"""
console.clear()
console.print("Editing General Settings")
allow_insecure_connections = inquirer.confirm("Allow insecure connections?").execute()
allow_insecure_connections = inquirer.confirm("Allow insecure connections?", vi_mode=manager.vi_mode).execute()
user_agent = inquirer.text(
message="User Agent:",
default=manager.config_manager.global_settings_data['General']['user_agent'],
validate=EmptyInputValidator("Input should not be empty")
validate=EmptyInputValidator("Input should not be empty"),
vi_mode=manager.vi_mode,
).execute()
proxy = inquirer.text(
message="Proxy:",
default=manager.config_manager.global_settings_data['General']['proxy']
default=manager.config_manager.global_settings_data['General']['proxy'],
vi_mode=manager.vi_mode,
).execute()
flaresolverr = inquirer.text(
message="FlareSolverr (IP:PORT):",
default=manager.config_manager.global_settings_data['General']['flaresolverr']
default=manager.config_manager.global_settings_data['General']['flaresolverr'],
vi_mode=manager.vi_mode,
).execute()
max_filename_length = inquirer.number(
message="Max Filename Length:",
default=int(manager.config_manager.global_settings_data['General']['max_file_name_length']),
float_allowed=False,
vi_mode=manager.vi_mode,
).execute()
max_folder_name_length = inquirer.number(
message="Max Folder Name Length:",
default=int(manager.config_manager.global_settings_data['General']['max_folder_name_length']),
float_allowed=False,
vi_mode=manager.vi_mode,
).execute()
required_free_space = inquirer.number(
message="Required Free Space (in GB):",
default=int(manager.config_manager.global_settings_data['General']['required_free_space']),
float_allowed=False,
vi_mode=manager.vi_mode,
).execute()
manager.vi_mode = inquirer.confirm(
message="Enable VI/VIM keybindings?",
default=bool(manager.config_manager.global_settings_data['General']['vi_mode']),
vi_mode=manager.vi_mode,
).execute()

manager.config_manager.global_settings_data['General']['allow_insecure_connections'] = allow_insecure_connections
Expand All @@ -82,7 +94,7 @@ def edit_general_settings_prompt(manager: Manager) -> None:
manager.config_manager.global_settings_data['General']['max_filename_length'] = int(max_filename_length)
manager.config_manager.global_settings_data['General']['max_folder_name_length'] = int(max_folder_name_length)
manager.config_manager.global_settings_data['General']['required_free_space'] = int(required_free_space)

manager.config_manager.global_settings_data['General']['vi_mode'] = manager.vi_mode

def edit_progress_settings_prompt(manager: Manager) -> None:
"""Edit the progress settings"""
Expand All @@ -92,6 +104,7 @@ def edit_progress_settings_prompt(manager: Manager) -> None:
message="Refresh Rate:",
default=int(manager.config_manager.global_settings_data['Progress_Options']['refresh_rate']),
float_allowed=False,
vi_mode=manager.vi_mode,
).execute()

manager.config_manager.global_settings_data['Progress_Options']['refresh_rate'] = int(refresh_rate)
Expand All @@ -105,37 +118,44 @@ def edit_rate_limiting_settings_prompt(manager: Manager) -> None:
message="Connection Timeout (in seconds):",
default=int(manager.config_manager.global_settings_data['Rate_Limiting_Options']['connection_timeout']),
float_allowed=False,
vi_mode=manager.vi_mode,
).execute()
read_timeout = inquirer.number(
message="Read Timeout (in seconds):",
default=int(manager.config_manager.global_settings_data['Rate_Limiting_Options']['read_timeout']),
float_allowed=False,
vi_mode=manager.vi_mode,
).execute()
download_attempts = inquirer.number(
message="Download Attempts:",
default=int(manager.config_manager.global_settings_data['Rate_Limiting_Options']['download_attempts']),
float_allowed=False,
vi_mode=manager.vi_mode,
).execute()
rate_limit = inquirer.number(
message="Maximum number of requests per second:",
default=int(manager.config_manager.global_settings_data['Rate_Limiting_Options']['rate_limit']),
float_allowed=False,
vi_mode=manager.vi_mode,
).execute()
throttle = inquirer.number(
message="Delay between requests during the download stage:",
default=float(manager.config_manager.global_settings_data['Rate_Limiting_Options']['download_delay']),
float_allowed=True,
vi_mode=manager.vi_mode,
).execute()

max_simultaneous_downloads = inquirer.number(
message="Maximum number of simultaneous downloads:",
default=int(manager.config_manager.global_settings_data['Rate_Limiting_Options']['max_simultaneous_downloads']),
float_allowed=False,
vi_mode=manager.vi_mode,
).execute()
max_simultaneous_downloads_per_domain = inquirer.number(
message="Maximum number of simultaneous downloads per domain:",
default=int(manager.config_manager.global_settings_data['Rate_Limiting_Options']['max_simultaneous_downloads_per_domain']),
float_allowed=False,
vi_mode=manager.vi_mode,
).execute()

manager.config_manager.global_settings_data['Rate_Limiting_Options']['connection_timeout'] = int(connection_timeout)
Expand Down
Loading

0 comments on commit 481559e

Please sign in to comment.