feat: compact duration formatting
This commit is contained in:
@@ -217,7 +217,7 @@ class LibraryClient:
|
|||||||
def format_duration(
|
def format_duration(
|
||||||
value: int | None, unit: str = "minutes", default_none: str | None = None
|
value: int | None, unit: str = "minutes", default_none: str | None = None
|
||||||
) -> str | None:
|
) -> str | None:
|
||||||
"""Format duration value into a human-readable string."""
|
"""Format duration value into a compact string."""
|
||||||
if value is None or value <= 0:
|
if value is None or value <= 0:
|
||||||
return default_none
|
return default_none
|
||||||
|
|
||||||
@@ -227,13 +227,9 @@ class LibraryClient:
|
|||||||
|
|
||||||
hours, minutes = divmod(total_minutes, 60)
|
hours, minutes = divmod(total_minutes, 60)
|
||||||
|
|
||||||
parts = []
|
if hours > 0:
|
||||||
if hours:
|
return f"{hours}h{minutes:02d}" if minutes else f"{hours}h"
|
||||||
parts.append(f"{hours} hour{'s' if hours != 1 else ''}")
|
return f"{minutes}m"
|
||||||
if minutes:
|
|
||||||
parts.append(f"{minutes} minute{'s' if minutes != 1 else ''}")
|
|
||||||
|
|
||||||
return " ".join(parts) if parts else default_none
|
|
||||||
|
|
||||||
def _get_total_duration(self, asin: str, item: dict | None = None) -> float | None:
|
def _get_total_duration(self, asin: str, item: dict | None = None) -> float | None:
|
||||||
"""Get total duration in seconds, trying item data first, then API."""
|
"""Get total duration in seconds, trying item data first, then API."""
|
||||||
@@ -274,7 +270,7 @@ class LibraryClient:
|
|||||||
except (OSError, ValueError, KeyError):
|
except (OSError, ValueError, KeyError):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def mark_as_unfinished(self, asin: str, item: dict | None = None) -> bool:
|
def mark_as_unfinished(self, asin: str) -> bool:
|
||||||
"""Mark a book as unfinished by restoring saved position."""
|
"""Mark a book as unfinished by restoring saved position."""
|
||||||
saved_position = self._saved_positions.pop(asin, None)
|
saved_position = self._saved_positions.pop(asin, None)
|
||||||
if saved_position is None:
|
if saved_position is None:
|
||||||
|
|||||||
Reference in New Issue
Block a user