From f321272b7c158181b252955e28d5c4c7e367c699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 25 Jul 2024 17:30:29 +0200 Subject: [PATCH] [ytdl] fix --cookies-from-browser option parsing --- gallery_dl/ytdl.py | 18 +++++++++++++++++- test/test_ytdl.py | 14 ++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/gallery_dl/ytdl.py b/gallery_dl/ytdl.py index 0a0bf864..d4fdedc4 100644 --- a/gallery_dl/ytdl.py +++ b/gallery_dl/ytdl.py @@ -249,6 +249,22 @@ def parse_command_line(module, argv): None if opts.match_filter is None else module.match_filter_func(opts.match_filter)) + cookiesfrombrowser = getattr(opts, "cookiesfrombrowser", None) + if cookiesfrombrowser: + match = re.fullmatch(r"""(?x) + (?P[^+:]+) + (?:\s*\+\s*(?P[^:]+))? + (?:\s*:\s*(?!:)(?P.+?))? + (?:\s*::\s*(?P.+))? + """, cookiesfrombrowser) + if match: + browser, keyring, profile, container = match.groups() + if keyring is not None: + keyring = keyring.upper() + cookiesfrombrowser = (browser.lower(), profile, keyring, container) + else: + cookiesfrombrowser = None + return { "usenetrc": opts.usenetrc, "netrc_location": getattr(opts, "netrc_location", None), @@ -364,7 +380,7 @@ def parse_command_line(module, argv): "skip_playlist_after_errors": getattr( opts, "skip_playlist_after_errors", None), "cookiefile": opts.cookiefile, - "cookiesfrombrowser": getattr(opts, "cookiesfrombrowser", None), + "cookiesfrombrowser": cookiesfrombrowser, "nocheckcertificate": opts.no_check_certificate, "prefer_insecure": opts.prefer_insecure, "proxy": opts.proxy, diff --git a/test/test_ytdl.py b/test/test_ytdl.py index 878ac85b..fd2e40a8 100644 --- a/test/test_ytdl.py +++ b/test/test_ytdl.py @@ -294,6 +294,20 @@ class Test_CommandlineArguments_YtDlp(Test_CommandlineArguments): self._(["--geo-bypass-ip-block", "198.51.100.14/24"], "geo_bypass", "198.51.100.14/24") + def test_cookiesfrombrowser(self): + self._(["--cookies-from-browser", "firefox"], + "cookiesfrombrowser", ("firefox", None, None, None)) + self._(["--cookies-from-browser", "firefox:profile"], + "cookiesfrombrowser", ("firefox", "profile", None, None)) + self._(["--cookies-from-browser", "firefox+keyring"], + "cookiesfrombrowser", ("firefox", None, "KEYRING", None)) + self._(["--cookies-from-browser", "firefox::container"], + "cookiesfrombrowser", ("firefox", None, None, "container")) + self._(["--cookies-from-browser", + "firefox+keyring:profile::container"], + "cookiesfrombrowser", + ("firefox", "profile", "KEYRING", "container")) + if __name__ == "__main__": unittest.main(warnings="ignore")