From e7926ae9f4e5fa258696551a39295402819280c9 Mon Sep 17 00:00:00 2001 From: dirkf Date: Fri, 28 Jul 2023 06:03:14 +0100 Subject: [utils] Rework decoding of `Content-Encoding`s * support nested encodings * support optional `br` encoding, if brotli package is installed * support optional 'compress' encoding, if ncompress package is installed * response `Content-Encoding` has only unprocessed encodings, or removed * response `Content-Length` is decoded length (usable for filesize metadata) * use zlib for both deflate and gzip decompression * some elements taken from yt-dlp: thx especially coletdjnz --- youtube_dl/compat.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'youtube_dl/compat.py') diff --git a/youtube_dl/compat.py b/youtube_dl/compat.py index da6d70ec4..54ad64674 100644 --- a/youtube_dl/compat.py +++ b/youtube_dl/compat.py @@ -3200,6 +3200,18 @@ except AttributeError: def compat_datetime_timedelta_total_seconds(td): return (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6 +# optional decompression packages +# PyPi brotli package implements 'br' Content-Encoding +try: + import brotli as compat_brotli +except ImportError: + compat_brotli = None +# PyPi ncompress package implements 'compress' Content-Encoding +try: + import ncompress as compat_ncompress +except ImportError: + compat_ncompress = None + legacy = [ 'compat_HTMLParseError', @@ -3234,6 +3246,7 @@ __all__ = [ 'compat_Struct', 'compat_base64_b64decode', 'compat_basestring', + 'compat_brotli', 'compat_casefold', 'compat_chr', 'compat_collections_abc', @@ -3259,6 +3272,7 @@ __all__ = [ 'compat_itertools_zip_longest', 'compat_kwargs', 'compat_map', + 'compat_ncompress', 'compat_numeric_types', 'compat_open', 'compat_ord', -- cgit 1.4.1