1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 10:42:34 +01:00

[ytdl] fix --cookies-from-browser option parsing

This commit is contained in:
Mike Fährmann 2024-07-25 17:30:29 +02:00
parent 540eaa5add
commit f321272b7c
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 31 additions and 1 deletions

View File

@ -249,6 +249,22 @@ def parse_command_line(module, argv):
None if opts.match_filter is None None if opts.match_filter is None
else module.match_filter_func(opts.match_filter)) else module.match_filter_func(opts.match_filter))
cookiesfrombrowser = getattr(opts, "cookiesfrombrowser", None)
if cookiesfrombrowser:
match = re.fullmatch(r"""(?x)
(?P<name>[^+:]+)
(?:\s*\+\s*(?P<keyring>[^:]+))?
(?:\s*:\s*(?!:)(?P<profile>.+?))?
(?:\s*::\s*(?P<container>.+))?
""", 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 { return {
"usenetrc": opts.usenetrc, "usenetrc": opts.usenetrc,
"netrc_location": getattr(opts, "netrc_location", None), "netrc_location": getattr(opts, "netrc_location", None),
@ -364,7 +380,7 @@ def parse_command_line(module, argv):
"skip_playlist_after_errors": getattr( "skip_playlist_after_errors": getattr(
opts, "skip_playlist_after_errors", None), opts, "skip_playlist_after_errors", None),
"cookiefile": opts.cookiefile, "cookiefile": opts.cookiefile,
"cookiesfrombrowser": getattr(opts, "cookiesfrombrowser", None), "cookiesfrombrowser": cookiesfrombrowser,
"nocheckcertificate": opts.no_check_certificate, "nocheckcertificate": opts.no_check_certificate,
"prefer_insecure": opts.prefer_insecure, "prefer_insecure": opts.prefer_insecure,
"proxy": opts.proxy, "proxy": opts.proxy,

View File

@ -294,6 +294,20 @@ class Test_CommandlineArguments_YtDlp(Test_CommandlineArguments):
self._(["--geo-bypass-ip-block", "198.51.100.14/24"], self._(["--geo-bypass-ip-block", "198.51.100.14/24"],
"geo_bypass", "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__": if __name__ == "__main__":
unittest.main(warnings="ignore") unittest.main(warnings="ignore")