refactor: different formatting
This commit is contained in:
@@ -40,14 +40,13 @@ class Auditui:
|
|||||||
|
|
||||||
email = input("Email: ")
|
email = input("Email: ")
|
||||||
password = getpass("Password: ")
|
password = getpass("Password: ")
|
||||||
marketplace = input(
|
marketplace = (
|
||||||
"Marketplace locale (default: US): ").strip().upper() or "US"
|
input("Marketplace locale (default: US): ").strip().upper() or "US"
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.auth = audible.Authenticator.from_login(
|
self.auth = audible.Authenticator.from_login(
|
||||||
username=email,
|
username=email, password=password, locale=marketplace
|
||||||
password=password,
|
|
||||||
locale=marketplace
|
|
||||||
)
|
)
|
||||||
|
|
||||||
auth_file.parent.mkdir(parents=True, exist_ok=True)
|
auth_file.parent.mkdir(parents=True, exist_ok=True)
|
||||||
@@ -58,11 +57,11 @@ class Auditui:
|
|||||||
print(f"Authentication failed: {e}")
|
print(f"Authentication failed: {e}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def format_duration(self, value, unit='minutes', default_none=None):
|
def format_duration(self, value, unit="minutes", default_none=None):
|
||||||
if value is None or value <= 0:
|
if value is None or value <= 0:
|
||||||
return default_none
|
return default_none
|
||||||
|
|
||||||
if unit == 'seconds':
|
if unit == "seconds":
|
||||||
total_minutes = int(value) // 60
|
total_minutes = int(value) // 60
|
||||||
else:
|
else:
|
||||||
total_minutes = int(value)
|
total_minutes = int(value)
|
||||||
@@ -78,9 +77,11 @@ class Auditui:
|
|||||||
|
|
||||||
def _extract_title(self, item):
|
def _extract_title(self, item):
|
||||||
product = item.get("product", {})
|
product = item.get("product", {})
|
||||||
return (product.get("title") or
|
return (
|
||||||
item.get("title") or
|
product.get("title")
|
||||||
product.get("asin", "Unknown Title"))
|
or item.get("title")
|
||||||
|
or product.get("asin", "Unknown Title")
|
||||||
|
)
|
||||||
|
|
||||||
def _extract_authors(self, item):
|
def _extract_authors(self, item):
|
||||||
product = item.get("product", {})
|
product = item.get("product", {})
|
||||||
@@ -96,7 +97,7 @@ class Auditui:
|
|||||||
"runtime_length",
|
"runtime_length",
|
||||||
"vLength",
|
"vLength",
|
||||||
"length",
|
"length",
|
||||||
"duration"
|
"duration",
|
||||||
]
|
]
|
||||||
|
|
||||||
runtime = None
|
runtime = None
|
||||||
@@ -125,7 +126,8 @@ class Auditui:
|
|||||||
if isinstance(listening_status, dict):
|
if isinstance(listening_status, dict):
|
||||||
if percent_complete is None:
|
if percent_complete is None:
|
||||||
percent_complete = listening_status.get("percent_complete")
|
percent_complete = listening_status.get("percent_complete")
|
||||||
time_remaining_seconds = listening_status.get("time_remaining_seconds")
|
time_remaining_seconds = listening_status.get(
|
||||||
|
"time_remaining_seconds")
|
||||||
else:
|
else:
|
||||||
time_remaining_seconds = None
|
time_remaining_seconds = None
|
||||||
|
|
||||||
@@ -143,8 +145,10 @@ class Auditui:
|
|||||||
author_names = self._extract_authors(item)
|
author_names = self._extract_authors(item)
|
||||||
minutes = self._extract_runtime_minutes(item)
|
minutes = self._extract_runtime_minutes(item)
|
||||||
runtime_str = self.format_duration(
|
runtime_str = self.format_duration(
|
||||||
minutes, unit='minutes', default_none="Unknown length")
|
minutes, unit="minutes", default_none="Unknown length"
|
||||||
percent_complete, time_remaining_seconds = self._extract_progress_info(item)
|
)
|
||||||
|
percent_complete, time_remaining_seconds = self._extract_progress_info(
|
||||||
|
item)
|
||||||
|
|
||||||
print(f"{idx}. {title}")
|
print(f"{idx}. {title}")
|
||||||
if author_names:
|
if author_names:
|
||||||
@@ -157,7 +161,8 @@ class Auditui:
|
|||||||
|
|
||||||
if time_remaining_seconds:
|
if time_remaining_seconds:
|
||||||
time_remaining_str = self.format_duration(
|
time_remaining_str = self.format_duration(
|
||||||
time_remaining_seconds, unit='seconds')
|
time_remaining_seconds, unit="seconds"
|
||||||
|
)
|
||||||
if time_remaining_str:
|
if time_remaining_str:
|
||||||
print(f" Time remaining: {time_remaining_str}")
|
print(f" Time remaining: {time_remaining_str}")
|
||||||
|
|
||||||
@@ -176,7 +181,7 @@ class Auditui:
|
|||||||
path="library",
|
path="library",
|
||||||
num_results=page_size,
|
num_results=page_size,
|
||||||
page=page,
|
page=page,
|
||||||
response_groups=response_groups
|
response_groups=response_groups,
|
||||||
)
|
)
|
||||||
|
|
||||||
items = library.get("items", [])
|
items = library.get("items", [])
|
||||||
@@ -232,14 +237,21 @@ class Auditui:
|
|||||||
|
|
||||||
if isinstance(listening_status, dict):
|
if isinstance(listening_status, dict):
|
||||||
is_finished_flag = is_finished_flag or listening_status.get(
|
is_finished_flag = is_finished_flag or listening_status.get(
|
||||||
"is_finished", False)
|
"is_finished", False
|
||||||
percent_complete = percent_complete if percent_complete is not None else listening_status.get(
|
)
|
||||||
"percent_complete", 0)
|
percent_complete = (
|
||||||
|
percent_complete
|
||||||
|
if percent_complete is not None
|
||||||
|
else listening_status.get("percent_complete", 0)
|
||||||
|
)
|
||||||
|
|
||||||
is_finished = False
|
is_finished = False
|
||||||
if is_finished_flag is True:
|
if is_finished_flag is True:
|
||||||
is_finished = True
|
is_finished = True
|
||||||
elif isinstance(percent_complete, (int, float)) and percent_complete >= 100:
|
elif (
|
||||||
|
isinstance(percent_complete, (int, float))
|
||||||
|
and percent_complete >= 100
|
||||||
|
):
|
||||||
is_finished = True
|
is_finished = True
|
||||||
|
|
||||||
if is_finished:
|
if is_finished:
|
||||||
@@ -248,7 +260,9 @@ class Auditui:
|
|||||||
unfinished_items.append(item)
|
unfinished_items.append(item)
|
||||||
|
|
||||||
print(
|
print(
|
||||||
f"Found {len(unfinished_items)} unfinished books (filtered out {finished_count} finished books).\n")
|
f"Found {len(unfinished_items)} unfinished books (filtered out {
|
||||||
|
finished_count} finished books).\n"
|
||||||
|
)
|
||||||
|
|
||||||
if not unfinished_items:
|
if not unfinished_items:
|
||||||
print("No unfinished books found.")
|
print("No unfinished books found.")
|
||||||
|
|||||||
Reference in New Issue
Block a user