Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
Add clear cache menu option
Jacob3b40bf1d8b0c
diff --git a/cyberdrop_dl/managers/config_manager.py b/cyberdrop_dl/managers/config_manager.pyindex 3ee8e46f9..2b57a40ff 100644--- a/cyberdrop_dl/managers/config_manager.py+++ b/cyberdrop_dl/managers/config_manager.py@@ -54,8 +54,6 @@ class ConfigManager:self.pydantic_config = Trueself.manager.cache_manager.save("pydantic_config", True)- self.manager.cache_manager.load_request_cache()-def load_configs(self) -> None:"""Loads all the configs."""self._load_authentication_config()diff --git a/cyberdrop_dl/managers/manager.py b/cyberdrop_dl/managers/manager.pyindex c73a504d6..1627ed7a7 100644--- a/cyberdrop_dl/managers/manager.py+++ b/cyberdrop_dl/managers/manager.py@@ -77,6 +77,7 @@ class Manager:self.config_manager = ConfigManager(self)self.config_manager.startup()self.args_consolidation()+ self.cache_manager.load_request_cache()self.vi_mode = self.config_manager.global_settings_data.ui_options.vi_modeself.path_manager.startup()diff --git a/cyberdrop_dl/ui/program_ui.py b/cyberdrop_dl/ui/program_ui.pyindex 7c82fde94..741a83b96 100644--- a/cyberdrop_dl/ui/program_ui.py+++ b/cyberdrop_dl/ui/program_ui.py@@ -1,5 +1,6 @@from __future__ import annotations+import asyncioimport sysfrom functools import wrapsfrom textwrap import dedent@@ -170,7 +171,16 @@ class ProgramUI:enter_to_continue()def _clear_cache(self) -> None:- self.print_error("function reserved for future version")+ domains = user_prompts.domains_prompt(domain_message="Select site(s) to clear cache for:")+ if not domains:+ console.print("No domains selected", style="red")+ enter_to_continue()+ return+ urls = user_prompts.filter_cache_urls(self.manager, domains)+ for url in urls:+ asyncio.run(self.manager.cache_manager.request_cache.delete_url(url))+ console.print("Finished clearing the cache", style="green")+ enter_to_continue()def _edit_auth_config(self) -> None:config_file = self.manager.path_manager.config_folder / "authentication.yaml"@@ -251,6 +261,7 @@ class ProgramUI:def _process_answer(self, answer: Any, options_map=dict) -> Choice | None:"""Checks prompt answer and executes corresponding function."""if answer == EXIT_CHOICE.value:+ asyncio.run(self.manager.cache_manager.close())sys.exit(0)if answer == DONE_CHOICE.value:return DONE_CHOICEdiff --git a/cyberdrop_dl/ui/prompts/user_prompts.py b/cyberdrop_dl/ui/prompts/user_prompts.pyindex fb0d1b951..5640c9807 100644--- a/cyberdrop_dl/ui/prompts/user_prompts.py+++ b/cyberdrop_dl/ui/prompts/user_prompts.py@@ -1,5 +1,6 @@from __future__ import annotations+import asynciofrom typing import TYPE_CHECKINGfrom InquirerPy import get_style@@ -17,6 +18,8 @@ from cyberdrop_dl.utils.utilities import clear_termif TYPE_CHECKING:from pathlib import Path+ from yarl import URL+from cyberdrop_dl.managers.manager import Managerconsole = Console()@@ -166,6 +169,30 @@ def browser_prompt() -> str:return basic_prompts.ask_checkbox(choices, message="Select the browser(s) for extraction:")+""" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CACHE PROMPTS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""+++async def _get_urls(manager: Manager) -> set[URL]:+ urls = set()+ async for url in manager.cache_manager.request_cache.get_urls():+ urls.add(url)+ return urls+++def filter_cache_urls(manager: Manager, domains: list) -> set[URL]:+ urls_to_remove = set()+ cached_urls = asyncio.run(_get_urls(manager))+ cached_urls_copy = cached_urls.copy()+ for domain in domains:+ cached_urls = cached_urls_copy.copy()+ cached_urls_copy = cached_urls.copy()+ for url in cached_urls:+ if url.host == domain:+ urls_to_remove.add(url)+ cached_urls_copy.remove(url)+ return urls_to_remove++""" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ V4 IMPORT PROMPTS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""