Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
Added option to clear cookies for selected websites
Jacob0891c57606d1
diff --git a/cyberdrop_dl/ui/program_ui.py b/cyberdrop_dl/ui/program_ui.pyindex 0f4fa0b12..2b86f0768 100644--- a/cyberdrop_dl/ui/program_ui.py+++ b/cyberdrop_dl/ui/program_ui.py@@ -15,6 +15,7 @@ from cyberdrop_dl.dependencies import browser_cookie3from cyberdrop_dl.ui.prompts import user_promptsfrom cyberdrop_dl.ui.prompts.basic_prompts import ask_dir_path, enter_to_continuefrom cyberdrop_dl.ui.prompts.defaults import DONE_CHOICE, EXIT_CHOICE+from cyberdrop_dl.utils.cookie_extraction import clear_cookiesfrom cyberdrop_dl.utils.transfer.transfer_v4_config import transfer_v4_configfrom cyberdrop_dl.utils.transfer.transfer_v4_db import transfer_v4_dbfrom cyberdrop_dl.utils.utilities import check_latest_pypi, clear_term, open_in_text_editor@@ -151,17 +152,24 @@ class ProgramUI:1: self._change_default_config,2: self._create_new_config,3: self._delete_config,- 4: self._delete_cached_responses,- 5: self._edit_config,- 6: self._edit_auth_config,- 7: self._edit_global_config,- 8: self._edit_auto_cookies_extration,- 9: self._import_cookies_now,+ 4: self._edit_config,+ 5: self._edit_auth_config,+ 6: self._edit_global_config,+ 7: self._edit_auto_cookies_extration,+ 8: self._import_cookies_now,+ 9: self._clear_cookies,+ 10: self._clear_cache,}answer = user_prompts.manage_configs(self.manager)return self._process_answer(answer, options_map)- def _delete_cached_responses(self) -> None:+ def _clear_cookies(self) -> None:+ domains = user_prompts.domains_prompt(domain_message="Select site(s) to clear cookies for:")+ clear_cookies(self.manager, domains)+ console.print("Finished clearing cookies", style="green")+ enter_to_continue()++ def _clear_cache(self) -> None:self.print_error("function reserved for future version")def _edit_auth_config(self) -> None:diff --git a/cyberdrop_dl/ui/prompts/basic_prompts.py b/cyberdrop_dl/ui/prompts/basic_prompts.pyindex f97be86f8..d97b6ae4d 100644--- a/cyberdrop_dl/ui/prompts/basic_prompts.py+++ b/cyberdrop_dl/ui/prompts/basic_prompts.py@@ -94,7 +94,7 @@ def create_choices(choices.append(append_last)separator_indexes = []- for group in options_groups[:-1]:+ for group in options_groups:separator_indexes.append(len(group) + (separator_indexes[-1] if separator_indexes else 0))for count, index in enumerate(separator_indexes):diff --git a/cyberdrop_dl/ui/prompts/user_prompts.py b/cyberdrop_dl/ui/prompts/user_prompts.pyindex 85bce0edf..e0fb39c3d 100644--- a/cyberdrop_dl/ui/prompts/user_prompts.py+++ b/cyberdrop_dl/ui/prompts/user_prompts.py@@ -63,16 +63,17 @@ def manage_configs(manager: Manager) -> int:"Change default config","Create a new config","Delete a config",- "Clear cached responses",],"group_2": ["Edit current config","Edit authentication config",- "Edit global config ",+ "Edit global config",+ ],+ "group_3": ["Edit auto cookie extraction settings", "Import cookies now", "Clear cookies"],+ "group_4": [+ "Clear cache",],- "group 3": ["Edit auto cookie extraction settings", "Import cookies now"],}-choices = basic_prompts.create_choices(OPTIONS)return basic_prompts.ask_choice(choices)@@ -123,23 +124,29 @@ def auto_cookie_extraction(manager: Manager):manager.config_manager.write_updated_settings_config()-def extract_cookies(manager: Manager, *, dry_run: bool = False) -> None:- """Asks the user to select browser(s) and domains(s) to import cookies from."""+def domains_prompt(*, domain_message: str = "Select site(s):") -> list[str]:+ """Asks the user to select website(s) for cookie actions and cache actions."""OPTIONS = [["forum", "file-host"]]choices = basic_prompts.create_choices(OPTIONS)- domain_type = basic_prompts.ask_choice(choices, message="Select categorie:")+ domain_type = basic_prompts.ask_choice(choices, message="Select category:")if domain_type == DONE_CHOICE.value:- return+ return []all_domains = list(FORUMS.values()) if domain_type == 1 else list(WEBSITES.values())domain_choices = [Choice(site) for site in all_domains] + [ALL_CHOICE]- domains = basic_prompts.ask_checkbox(domain_choices, message="Select site(s) to import cookies from:")- browsers = browser_prompt()-+ domains = basic_prompts.ask_checkbox(domain_choices, message=domain_message)if ALL_CHOICE.value in domains:domains = all_domains+ return domains+++def extract_cookies(manager: Manager, *, dry_run: bool = False) -> None:+ """Asks the user to select browser(s) and domains(s) to import cookies from."""++ domains = domains_prompt(domain_message="Select site(s) to import cookies from:")+ browsers = browser_prompt()if ALL_CHOICE.value in browsers:browsers = list(BROWSERS)diff --git a/cyberdrop_dl/utils/cookie_extraction.py b/cyberdrop_dl/utils/cookie_extraction.pyindex b9a2986a8..fb8549a19 100644--- a/cyberdrop_dl/utils/cookie_extraction.py+++ b/cyberdrop_dl/utils/cookie_extraction.py@@ -91,3 +91,14 @@ def update_forum_config_cookies(manager: Manager, forum: str, cookie: CookieJar)forum_dict[f"{forum_domain}_xf_user_cookie"] = cookie._cookies[forum_domain]["/"]["xf_user"].valueforum_dict[f"{forum_domain}_xf_user_cookie"] = cookie._cookies["www." + forum_domain]["/"]["xf_user"].valueauth_args.forums = auth_args.forums.model_copy(update=forum_dict)+++def clear_cookies(manager: Manager, domains: list[str] | None = None) -> None:+ if not domains and domains is not None:+ raise ValueError("No domains selected")++ for domain in domains:+ cookie_jar = MozillaCookieJar()+ manager.path_manager.cookies_dir.mkdir(parents=True, exist_ok=True)+ cookie_file_path = manager.path_manager.cookies_dir / f"{domain}.txt"+ cookie_jar.save(cookie_file_path, ignore_discard=True, ignore_expires=True)