Support urllib3 > 2

This commit is contained in:
7x11x13
2024-08-24 13:01:08 -04:00
parent 8e5d50b6f3
commit e7a083aa9d
4 changed files with 50 additions and 16 deletions
+3 -1
View File
@@ -65,6 +65,7 @@ from docopt import docopt
from tqdm import tqdm
from free_bandcamp_downloader import __version__, logger
from free_bandcamp_downloader.bandcamp_http_adapter import BandcampHTTPAdapter
@dataclass
@@ -138,6 +139,7 @@ class BCFreeDownloader:
def _init_session(self, cookies_file: Optional[str], identity: Optional[str]):
self.session = requests.Session()
self.session.mount("https://", BandcampHTTPAdapter())
if cookies_file:
cj = MozillaCookieJar(cookies_file)
cj.load()
@@ -319,7 +321,7 @@ class BCFreeDownloader:
# the one that corresponds to the track release (t) or album release (a)
# physical releases are p, and discography offers are b, so this should be fine
head_data = next(obj for obj in head_data if obj["@id"] == url)
if not "offers" in head_data:
if "offers" not in head_data:
raise BCFreeDownloadError(f"{url} has no digital download. Skipping...")
album_data.title = head_data["name"]
@@ -0,0 +1,32 @@
from requests.adapters import HTTPAdapter
from urllib3.util.ssl_ import create_urllib3_context
# https://github.com/urllib3/urllib3/issues/3439#issuecomment-2306400349
class BandcampHTTPAdapter(HTTPAdapter):
def init_poolmanager(self, connections, maxsize, block=False, **pool_kwargs):
ctx = create_urllib3_context()
ctx.load_default_certs()
DEFAULT_CIPHERS = ":".join(
[
"ECDHE+AESGCM",
"ECDHE+CHACHA20",
"DHE+AESGCM",
"DHE+CHACHA20",
"ECDH+AESGCM",
"DH+AESGCM",
"ECDH+AES",
"DH+AES",
"RSA+AESGCM",
"RSA+AES",
"!aNULL",
"!eNULL",
"!MD5",
"!DSS",
"!AESCCM",
]
)
ctx.set_ciphers(DEFAULT_CIPHERS)
return super().init_poolmanager(
connections, maxsize, block, **pool_kwargs, ssl_context=ctx
)