diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index de7abde..079d88e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,8 +8,8 @@ jobs: tests: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2.3.4 - - uses: cachix/install-nix-action@v13 + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v27 with: nix_path: nixpkgs=channel:nixos-unstable - run: nix-shell --command "mypy audiobookdl" diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 6c53537..6bbd949 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -8,8 +8,8 @@ jobs: tests: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2.3.4 - - uses: cachix/install-nix-action@v13 + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v27 with: nix_path: nixpkgs=channel:nixos-unstable - run: nix-shell --command "python3 -m pytest" diff --git a/audiobookdl/sources/source/__init__.py b/audiobookdl/sources/source/__init__.py index d61aa35..c9243bc 100644 --- a/audiobookdl/sources/source/__init__.py +++ b/audiobookdl/sources/source/__init__.py @@ -1,7 +1,7 @@ # Internal imports from . import networking from audiobookdl import logging, AudiobookFile, Chapter, AudiobookMetadata, Cover, Result, Audiobook, BookId -from audiobookdl.exceptions import DataNotPresent +from audiobookdl.exceptions import DataNotPresent, GenericAudiobookDLException from audiobookdl.utils import CustomSSLContextHTTPAdapter # External imports @@ -177,19 +177,20 @@ def find_all_in_page(self, url: str, regex: str, **kwargs) -> list: get_stream_files = networking.get_stream_files def create_ssl_context(self, options: Any) -> SSLContext: - # Custom SSLContext's are broken in requests version 2.32.0/2.32.1/2.32.2 - # fixed in version 2.32.3: https://github.com/psf/requests/pull/6716 - ssl_context: SSLContext = urllib3.util.create_urllib3_context() # type: ignore[attr-defined] - - # Workaround for regression in requests version 2.32.3 - # https://github.com/psf/requests/issues/6730 - ssl_context.load_default_certs() - - # Prevent the padding extension from appearing in the TLS ClientHello - # It's used by Cloudflare for bot detection - # See issue #106 - ssl_context.options &= ~(1 << 4) # SSL_OP_TLSEXT_PADDING - return ssl_context + try: + ssl_context: SSLContext = urllib3.util.create_urllib3_context() # type: ignore[attr-defined] + + # Workaround for regression in requests version 2.32.3 + # https://github.com/psf/requests/issues/6730 + ssl_context.load_default_certs() + + # Prevent the padding extension from appearing in the TLS ClientHello + # It's used by Cloudflare for bot detection + # See issue #106 + ssl_context.options &= ~(1 << 4) # SSL_OP_TLSEXT_PADDING + return ssl_context + except AttributeError: # AttributeError: module 'urllib3.util' has no attribute 'create_urllib3_context' + raise GenericAudiobookDLException(f"Please update urllib3 to version >= 2 using the command 'pip install -U urllib3'") def create_session(self, options: Any) -> requests.Session: session = requests.Session() diff --git a/pyproject.toml b/pyproject.toml index 4645d23..69a8cdc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,11 +24,12 @@ dependencies = [ "m3u8", "mutagen", "pillow", + "pycountry", "pycryptodome", "requests", "rich", "tomli", - "pycountry", + "urllib3>=2", ] dynamic = ["version"] diff --git a/shell.nix b/shell.nix index 965c3a9..d0e2835 100644 --- a/shell.nix +++ b/shell.nix @@ -3,7 +3,7 @@ with import {}; mkShell { buildInputs = [ ffmpeg - (python3.withPackages(ps: with ps; [ + (python312.withPackages(ps: with ps; [ mutagen requests rich @@ -17,6 +17,7 @@ mkShell { tomli attrs pycountry + urllib3 # Test pytest