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:
|
def on_unmount(self) -> None:
|
||||||
"""Clean up on app exit."""
|
"""Clean up on app exit."""
|
||||||
self.playback.stop()
|
self.playback.stop()
|
||||||
|
if self.download_manager:
|
||||||
|
self.download_manager.close()
|
||||||
|
|
||||||
def on_key(self, event: Key) -> None:
|
def on_key(self, event: Key) -> None:
|
||||||
"""Handle key presses."""
|
"""Handle key presses."""
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ class DownloadManager:
|
|||||||
self.client = client
|
self.client = client
|
||||||
self.cache_dir = cache_dir
|
self.cache_dir = cache_dir
|
||||||
self.cache_dir.mkdir(parents=True, exist_ok=True)
|
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:
|
def get_or_download(self, asin: str, notify: StatusCallback | None = None) -> Path | None:
|
||||||
"""Get local path of AAX file, downloading if missing."""
|
"""Get local path of AAX file, downloading if missing."""
|
||||||
@@ -108,11 +109,9 @@ class DownloadManager:
|
|||||||
"key": asin,
|
"key": asin,
|
||||||
"codec": codec,
|
"codec": codec,
|
||||||
}
|
}
|
||||||
response = httpx.get(
|
response = self._http_client.get(
|
||||||
url=DOWNLOAD_URL,
|
url=DOWNLOAD_URL,
|
||||||
params=params,
|
params=params,
|
||||||
follow_redirects=False,
|
|
||||||
auth=self.auth,
|
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|
||||||
@@ -131,7 +130,7 @@ class DownloadManager:
|
|||||||
) -> Path | None:
|
) -> Path | None:
|
||||||
"""Download file from URL to destination."""
|
"""Download file from URL to destination."""
|
||||||
try:
|
try:
|
||||||
with httpx.stream("GET", url) as response:
|
with self._http_client.stream("GET", url) as response:
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
total_size = int(response.headers.get("content-length", 0))
|
total_size = int(response.headers.get("content-length", 0))
|
||||||
downloaded = 0
|
downloaded = 0
|
||||||
@@ -149,3 +148,8 @@ class DownloadManager:
|
|||||||
return dest_path
|
return dest_path
|
||||||
except Exception:
|
except Exception:
|
||||||
return None
|
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"
|
description = "An Audible TUI client"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.13"
|
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 = "." }
|
source = { virtual = "." }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "audible" },
|
{ name = "audible" },
|
||||||
|
{ name = "httpx" },
|
||||||
{ name = "textual" },
|
{ name = "textual" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[package.metadata]
|
[package.metadata]
|
||||||
requires-dist = [
|
requires-dist = [
|
||||||
{ name = "audible", specifier = ">=0.10.0" },
|
{ name = "audible", specifier = ">=0.10.0" },
|
||||||
|
{ name = "httpx", specifier = ">=0.28.1" },
|
||||||
{ name = "textual", specifier = ">=6.7.1" },
|
{ name = "textual", specifier = ">=6.7.1" },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user