diff options
author | Simon Sawicki <contact@grub4k.xyz> | 2024-10-01 02:13:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-01 02:13:48 +0200 |
commit | e59c82a74cda5139eb3928c75b0bd45484dbe7f0 (patch) | |
tree | f41b6eae79ece0d67f141710fb6e51f1f0baaabd /yt_dlp/cookies.py | |
parent | f91645aceaf13926cf35be2c1dfef61b3aab97fb (diff) |
[cookies] Fix cookie load error handling (#11140)
Authored by: Grub4K
Diffstat (limited to 'yt_dlp/cookies.py')
-rw-r--r-- | yt_dlp/cookies.py | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/yt_dlp/cookies.py b/yt_dlp/cookies.py index cff8d74a7..4a69c576b 100644 --- a/yt_dlp/cookies.py +++ b/yt_dlp/cookies.py @@ -34,6 +34,7 @@ from .dependencies import ( from .minicurses import MultilinePrinter, QuietMultilinePrinter from .utils import ( DownloadError, + YoutubeDLError, Popen, error_to_str, expand_path, @@ -86,24 +87,31 @@ def _create_progress_bar(logger): return printer +class CookieLoadError(YoutubeDLError): + pass + + def load_cookies(cookie_file, browser_specification, ydl): - cookie_jars = [] - if browser_specification is not None: - browser_name, profile, keyring, container = _parse_browser_specification(*browser_specification) - cookie_jars.append( - extract_cookies_from_browser(browser_name, profile, YDLLogger(ydl), keyring=keyring, container=container)) - - if cookie_file is not None: - is_filename = is_path_like(cookie_file) - if is_filename: - cookie_file = expand_path(cookie_file) - - jar = YoutubeDLCookieJar(cookie_file) - if not is_filename or os.access(cookie_file, os.R_OK): - jar.load() - cookie_jars.append(jar) - - return _merge_cookie_jars(cookie_jars) + try: + cookie_jars = [] + if browser_specification is not None: + browser_name, profile, keyring, container = _parse_browser_specification(*browser_specification) + cookie_jars.append( + extract_cookies_from_browser(browser_name, profile, YDLLogger(ydl), keyring=keyring, container=container)) + + if cookie_file is not None: + is_filename = is_path_like(cookie_file) + if is_filename: + cookie_file = expand_path(cookie_file) + + jar = YoutubeDLCookieJar(cookie_file) + if not is_filename or os.access(cookie_file, os.R_OK): + jar.load() + cookie_jars.append(jar) + + return _merge_cookie_jars(cookie_jars) + except Exception: + raise CookieLoadError('failed to load cookies') def extract_cookies_from_browser(browser_name, profile=None, logger=YDLLogger(), *, keyring=None, container=None): |