From 839394343e48eff883078f11b007ca01c4ff014a Mon Sep 17 00:00:00 2001 From: Kharec Date: Sun, 14 Dec 2025 09:37:47 +0100 Subject: [PATCH] feat: make chunk size configurable --- auditui/downloads.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/auditui/downloads.py b/auditui/downloads.py index fe44641..b5a36df 100644 --- a/auditui/downloads.py +++ b/auditui/downloads.py @@ -9,7 +9,7 @@ import audible import httpx from audible.activation_bytes import get_activation_bytes -from .constants import CACHE_DIR, DEFAULT_CODEC, DOWNLOAD_URL, MIN_FILE_SIZE +from .constants import CACHE_DIR, DEFAULT_CHUNK_SIZE, DEFAULT_CODEC, DOWNLOAD_URL, MIN_FILE_SIZE StatusCallback = Callable[[str], None] @@ -18,13 +18,19 @@ class DownloadManager: """Handle retrieval and download of Audible titles.""" def __init__( - self, auth: audible.Authenticator, client: audible.Client, cache_dir: Path = CACHE_DIR + self, + auth: audible.Authenticator, + client: audible.Client, + cache_dir: Path = CACHE_DIR, + chunk_size: int = DEFAULT_CHUNK_SIZE, ) -> None: self.auth = auth self.client = client self.cache_dir = cache_dir self.cache_dir.mkdir(parents=True, exist_ok=True) - self._http_client = httpx.Client(auth=auth, timeout=30.0, follow_redirects=False) + self.chunk_size = chunk_size + self._http_client = httpx.Client( + auth=auth, timeout=30.0, follow_redirects=False) def get_or_download(self, asin: str, notify: StatusCallback | None = None) -> Path | None: """Get local path of AAX file, downloading if missing.""" @@ -136,7 +142,7 @@ class DownloadManager: downloaded = 0 with open(dest_path, "wb") as file_handle: - for chunk in response.iter_bytes(chunk_size=8192): + for chunk in response.iter_bytes(chunk_size=self.chunk_size): file_handle.write(chunk) downloaded += len(chunk) if total_size > 0 and notify: