feat: now display download status in MB
This commit is contained in:
@@ -9,7 +9,13 @@ import audible
|
|||||||
import httpx
|
import httpx
|
||||||
from audible.activation_bytes import get_activation_bytes
|
from audible.activation_bytes import get_activation_bytes
|
||||||
|
|
||||||
from .constants import CACHE_DIR, DEFAULT_CHUNK_SIZE, 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]
|
StatusCallback = Callable[[str], None]
|
||||||
|
|
||||||
@@ -29,15 +35,15 @@ class DownloadManager:
|
|||||||
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.chunk_size = chunk_size
|
self.chunk_size = chunk_size
|
||||||
self._http_client = httpx.Client(
|
self._http_client = httpx.Client(auth=auth, timeout=30.0, follow_redirects=True)
|
||||||
auth=auth, timeout=30.0, follow_redirects=True)
|
|
||||||
self._download_client = httpx.Client(
|
self._download_client = httpx.Client(
|
||||||
timeout=httpx.Timeout(connect=30.0, read=None,
|
timeout=httpx.Timeout(connect=30.0, read=None, write=30.0, pool=30.0),
|
||||||
write=30.0, pool=30.0),
|
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
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."""
|
||||||
title = self._get_name_from_asin(asin) or asin
|
title = self._get_name_from_asin(asin) or asin
|
||||||
safe_title = self._sanitize_filename(title)
|
safe_title = self._sanitize_filename(title)
|
||||||
@@ -140,7 +146,10 @@ class DownloadManager:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def _get_download_link(
|
def _get_download_link(
|
||||||
self, asin: str, codec: str = DEFAULT_CODEC, notify: StatusCallback | None = None
|
self,
|
||||||
|
asin: str,
|
||||||
|
codec: str = DEFAULT_CODEC,
|
||||||
|
notify: StatusCallback | None = None,
|
||||||
) -> str | None:
|
) -> str | None:
|
||||||
"""Get download link for book."""
|
"""Get download link for book."""
|
||||||
if self.auth.adp_token is None:
|
if self.auth.adp_token is None:
|
||||||
@@ -193,8 +202,10 @@ class DownloadManager:
|
|||||||
downloaded += len(chunk)
|
downloaded += len(chunk)
|
||||||
if total_size > 0 and notify:
|
if total_size > 0 and notify:
|
||||||
percent = (downloaded / total_size) * 100
|
percent = (downloaded / total_size) * 100
|
||||||
|
downloaded_mb = downloaded / (1024 * 1024)
|
||||||
|
total_mb = total_size / (1024 * 1024)
|
||||||
notify(
|
notify(
|
||||||
f"Downloading: {percent:.1f}% ({downloaded}/{total_size} bytes)"
|
f"Downloading: {percent:.1f}% ({downloaded_mb:.1f}/{total_mb:.1f} MB)"
|
||||||
)
|
)
|
||||||
|
|
||||||
return dest_path
|
return dest_path
|
||||||
|
|||||||
Reference in New Issue
Block a user