Compare commits

..

4 Commits

Author SHA1 Message Date
03988f0988 fix:l close download_manager flux on app exit 2025-12-14 09:35:25 +01:00
9eba702a0a feat: reuse connections for better performance 2025-12-14 09:35:05 +01:00
f61f4ec55e build: update uv.lock 2025-12-14 09:34:53 +01:00
b45ff86061 build: add httpx dependency 2025-12-14 09:34:47 +01:00
4 changed files with 17 additions and 5 deletions

View File

@@ -95,6 +95,8 @@ class Auditui(App):
def on_unmount(self) -> None:
"""Clean up on app exit."""
self.playback.stop()
if self.download_manager:
self.download_manager.close()
def on_key(self, event: Key) -> None:
"""Handle key presses."""

View File

@@ -24,6 +24,7 @@ class DownloadManager:
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)
def get_or_download(self, asin: str, notify: StatusCallback | None = None) -> Path | None:
"""Get local path of AAX file, downloading if missing."""
@@ -108,11 +109,9 @@ class DownloadManager:
"key": asin,
"codec": codec,
}
response = httpx.get(
response = self._http_client.get(
url=DOWNLOAD_URL,
params=params,
follow_redirects=False,
auth=self.auth,
)
response.raise_for_status()
@@ -131,7 +130,7 @@ class DownloadManager:
) -> Path | None:
"""Download file from URL to destination."""
try:
with httpx.stream("GET", url) as response:
with self._http_client.stream("GET", url) as response:
response.raise_for_status()
total_size = int(response.headers.get("content-length", 0))
downloaded = 0
@@ -149,3 +148,8 @@ class DownloadManager:
return dest_path
except Exception:
return None
def close(self) -> None:
"""Close the HTTP client and release resources."""
if hasattr(self, "_http_client"):
self._http_client.close()

View File

@@ -4,4 +4,8 @@ version = "0.1.0"
description = "An Audible TUI client"
readme = "README.md"
requires-python = ">=3.13"
dependencies = ["audible>=0.10.0", "textual>=6.7.1"]
dependencies = [
"audible>=0.10.0",
"httpx>=0.28.1",
"textual>=6.7.1",
]

2
uv.lock generated
View File

@@ -37,12 +37,14 @@ version = "0.1.0"
source = { virtual = "." }
dependencies = [
{ name = "audible" },
{ name = "httpx" },
{ name = "textual" },
]
[package.metadata]
requires-dist = [
{ name = "audible", specifier = ">=0.10.0" },
{ name = "httpx", specifier = ">=0.28.1" },
{ name = "textual", specifier = ">=6.7.1" },
]