From 7aa78c8899e33a2e1cb6c2a3623f8c000402c1c6 Mon Sep 17 00:00:00 2001 From: Jules-WinnfieldX Date: Tue, 5 Dec 2023 17:33:22 -0700 Subject: [PATCH] add error wrapper for cookie extraction --- cyberdrop_dl/__init__.py | 2 +- .../utils/args/browser_cookie_extraction.py | 22 +++++++++++++++++++ pyproject.toml | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/cyberdrop_dl/__init__.py b/cyberdrop_dl/__init__.py index 9ec9c0a04..f41e335b7 100644 --- a/cyberdrop_dl/__init__.py +++ b/cyberdrop_dl/__init__.py @@ -1 +1 @@ -__version__ = "5.0.47" +__version__ = "5.0.48" diff --git a/cyberdrop_dl/utils/args/browser_cookie_extraction.py b/cyberdrop_dl/utils/args/browser_cookie_extraction.py index 94286022c..b7af735b4 100644 --- a/cyberdrop_dl/utils/args/browser_cookie_extraction.py +++ b/cyberdrop_dl/utils/args/browser_cookie_extraction.py @@ -1,8 +1,11 @@ from __future__ import annotations +from functools import wraps from typing import TYPE_CHECKING import browser_cookie3 +from InquirerPy import inquirer +from rich.console import Console from cyberdrop_dl.utils.dataclasses.supported_domains import SupportedDomains @@ -12,7 +15,25 @@ from cyberdrop_dl.managers.manager import Manager +def cookie_wrapper(func): + """Wrapper handles errors for url scraping""" + @wraps(func) + def wrapper(self, *args, **kwargs): + try: + return func(self, *args, **kwargs) + except PermissionError: + console = Console() + console.clear() + console.print(f"We've encountered a Permissions Error. Please close all browsers and try again.", style="bold red") + console.print("If you are still having issues, make sure all browsers processes are closed in a Task Manager.", style="bold red") + console.print("Nothing has been saved.", style="bold red") + inquirer.confirm(message="Press enter to return menu.").execute() + return + return wrapper + + # noinspection PyProtectedMember +@cookie_wrapper def get_forum_cookies(manager: Manager, browser: str) -> None: """Get the cookies for the forums""" auth_args: Dict = manager.config_manager.authentication_data @@ -31,6 +52,7 @@ def get_forum_cookies(manager: Manager, browser: str) -> None: # noinspection PyProtectedMember +@cookie_wrapper def get_ddos_guard_cookies(manager: Manager, browser: str) -> None: """Get the cookies for DDOS-Guard""" auth_args: Dict = manager.config_manager.authentication_data diff --git a/pyproject.toml b/pyproject.toml index 85291b252..171e6d0bd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cyberdrop-dl" -version = "5.0.47" +version = "5.0.48" description = "Bulk downloader for multiple file hosts" authors = ["Jules Winnfield "] readme = "README.md"