From efd49aef734285f15e78010386ad701d078d9a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 5 Jun 2025 13:54:51 +0200 Subject: [PATCH] allow using predefined Firefox/Chrome 'headers' & 'ciphers' --- docs/configuration.rst | 23 ++++++++++++++++------- gallery_dl/extractor/common.py | 12 ++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index ecbe980b..b76bd501 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -726,7 +726,8 @@ Description extractor.*.headers ------------------- Type - ``object`` (`name` -> `value`) + * ``"string"`` + * ``object`` (`name` -> `value`) Default .. code:: json @@ -744,18 +745,23 @@ Description To disable sending a header, set its value to ``null``. + Set this option to ``"firefox"`` or ``"chrome"`` + to use these browser's default headers. + extractor.*.ciphers ------------------- Type - ``list`` of ``strings`` + * ``string`` + * ``list`` of ``strings`` Example - .. code:: json + * ``"firefox"`` + * .. code:: json - ["ECDHE-ECDSA-AES128-GCM-SHA256", - "ECDHE-RSA-AES128-GCM-SHA256", - "ECDHE-ECDSA-CHACHA20-POLY1305", - "ECDHE-RSA-CHACHA20-POLY1305"] + ["ECDHE-ECDSA-AES128-GCM-SHA256", + "ECDHE-RSA-AES128-GCM-SHA256", + "ECDHE-ECDSA-CHACHA20-POLY1305", + "ECDHE-RSA-CHACHA20-POLY1305"] Description List of TLS/SSL cipher suites in @@ -763,6 +769,9 @@ Description to be passed to `ssl.SSLContext.set_ciphers() `__ + Set this option to ``"firefox"`` or ``"chrome"`` + to use these browser's default ciphers. + extractor.*.tls12 ----------------- diff --git a/gallery_dl/extractor/common.py b/gallery_dl/extractor/common.py index ac261bdd..79cefeac 100644 --- a/gallery_dl/extractor/common.py +++ b/gallery_dl/extractor/common.py @@ -430,7 +430,10 @@ class Extractor(): headers["User-Agent"] = useragent headers["Accept"] = "*/*" headers["Accept-Language"] = "en-US,en;q=0.5" + ssl_ciphers = self.ciphers + if ssl_ciphers is not None and ssl_ciphers in SSL_CIPHERS: + ssl_ciphers = SSL_CIPHERS[ssl_ciphers] if BROTLI: headers["Accept-Encoding"] = "gzip, deflate, br" @@ -448,12 +451,21 @@ class Extractor(): custom_headers = self.config("headers") if custom_headers: + if isinstance(custom_headers, str): + if custom_headers in HTTP_HEADERS: + custom_headers = HTTP_HEADERS[custom_headers] + else: + self.log.error("Invalid 'headers' value '%s'", + custom_headers) + custom_headers = () headers.update(custom_headers) custom_ciphers = self.config("ciphers") if custom_ciphers: if isinstance(custom_ciphers, list): ssl_ciphers = ":".join(custom_ciphers) + elif custom_ciphers in SSL_CIPHERS: + ssl_ciphers = SSL_CIPHERS[custom_ciphers] else: ssl_ciphers = custom_ciphers