Compare commits
4 Commits
6824d00088
...
03988f0988
| Author | SHA1 | Date | |
|---|---|---|---|
| 03988f0988 | |||
| 9eba702a0a | |||
| f61f4ec55e | |||
| b45ff86061 |
@@ -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."""
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
2
uv.lock
generated
@@ -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" },
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user