From 6186ff764b75f9e9eda433b998616c3d47ba8e0a Mon Sep 17 00:00:00 2001 From: Andy Date: Wed, 4 Feb 2026 12:31:49 -0700 Subject: [PATCH] fix(progress): force track bar completion on terminal states --- unshackle/core/tracks/tracks.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/unshackle/core/tracks/tracks.py b/unshackle/core/tracks/tracks.py index ce41d10..ff0e646 100644 --- a/unshackle/core/tracks/tracks.py +++ b/unshackle/core/tracks/tracks.py @@ -95,7 +95,7 @@ class Tracks: return rep - def tree(self, add_progress: bool = False) -> tuple[Tree, list[partial]]: + def tree(self, add_progress: bool = False) -> tuple[Tree, list[Callable[..., None]]]: all_tracks = [*list(self), *self.chapters, *self.attachments] progress_callables = [] @@ -121,7 +121,26 @@ class Tracks: speed_estimate_period=10, ) task = progress.add_task("", downloaded="-") - progress_callables.append(partial(progress.update, task_id=task)) + + current_total = 100.0 + + def update_track_progress(task_id: int = task, **kwargs) -> None: + """ + Ensure terminal status states render as a fully completed bar. + + Some downloaders can report completed slightly below total + before emitting the final "Downloaded" state. + """ + nonlocal current_total + if "total" in kwargs and kwargs["total"] is not None: + current_total = kwargs["total"] + + downloaded_state = kwargs.get("downloaded") + if downloaded_state in {"Downloaded", "Decrypted", "[yellow]SKIPPED"}: + kwargs["completed"] = current_total + progress.update(task_id=task_id, **kwargs) + + progress_callables.append(update_track_progress) track_table = Table.grid() track_table.add_row(str(track)[6:], style="text2") track_table.add_row(progress)