no-name-here commited on
Commit
8df0016
Β·
verified Β·
1 Parent(s): dcb9a47

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +14 -6
main.py CHANGED
@@ -115,7 +115,9 @@ def fmt_size(b: float) -> str:
115
  return f"{b:.1f} TB"
116
 
117
  def fmt_time(seconds: float) -> str:
118
- seconds = max(0, int(seconds))
 
 
119
  if seconds < 60:
120
  return f"{seconds}s"
121
  m, s = divmod(seconds, 60)
@@ -125,9 +127,10 @@ def fmt_time(seconds: float) -> str:
125
  return f"{h}h {m}m"
126
 
127
  def progress_bar(current: int, total: int, length: int = 10) -> str:
128
- if total <= 0:
129
- return "β–“" * length
130
- filled = int(length * current / total)
 
131
  empty = length - filled
132
  return "β–“" * filled + "β–‘" * empty
133
 
@@ -135,15 +138,20 @@ def build_progress_text(phase: str, current: int, total: int,
135
  speed: float, elapsed: float, filename: str) -> str:
136
  pct = min(100, int(current * 100 / total)) if total > 0 else 0
137
  bar = progress_bar(current, total)
138
- eta = fmt_time((total - current) / speed) if speed > 0 else "β€”"
 
 
 
 
139
  icons = {"download": "πŸ“₯", "upload": "πŸ“€"}
140
  icon = icons.get(phase, "βš™οΈ")
141
  label = "Downloading" if phase == "download" else "Saving"
 
142
 
143
  return (
144
  f"{icon} **{label}:** `{filename}`\n\n"
145
  f"`{bar}` **{pct}%**\n\n"
146
- f"**Done:** `{fmt_size(current)}` / `{fmt_size(total)}`\n"
147
  f"**Speed:** `{fmt_size(speed)}/s`\n"
148
  f"**ETA:** `{eta}`\n"
149
  f"**Elapsed:** `{fmt_time(elapsed)}`"
 
115
  return f"{b:.1f} TB"
116
 
117
  def fmt_time(seconds: float) -> str:
118
+ if seconds <= 0 or seconds != seconds: # handle 0, negative, NaN
119
+ return "β€”"
120
+ seconds = int(seconds)
121
  if seconds < 60:
122
  return f"{seconds}s"
123
  m, s = divmod(seconds, 60)
 
127
  return f"{h}h {m}m"
128
 
129
  def progress_bar(current: int, total: int, length: int = 10) -> str:
130
+ if not total or total <= 0 or current <= 0:
131
+ return "β–‘" * length # empty bar instead of full when unknown
132
+ pct = min(1.0, current / total)
133
+ filled = int(length * pct)
134
  empty = length - filled
135
  return "β–“" * filled + "β–‘" * empty
136
 
 
138
  speed: float, elapsed: float, filename: str) -> str:
139
  pct = min(100, int(current * 100 / total)) if total > 0 else 0
140
  bar = progress_bar(current, total)
141
+ # ETA only makes sense when we know total and have speed
142
+ if total > 0 and speed > 0 and current < total:
143
+ eta = fmt_time((total - current) / speed)
144
+ else:
145
+ eta = "β€”"
146
  icons = {"download": "πŸ“₯", "upload": "πŸ“€"}
147
  icon = icons.get(phase, "βš™οΈ")
148
  label = "Downloading" if phase == "download" else "Saving"
149
+ total_str = fmt_size(total) if total > 0 else "?"
150
 
151
  return (
152
  f"{icon} **{label}:** `{filename}`\n\n"
153
  f"`{bar}` **{pct}%**\n\n"
154
+ f"**Done:** `{fmt_size(current)}` / `{total_str}`\n"
155
  f"**Speed:** `{fmt_size(speed)}/s`\n"
156
  f"**ETA:** `{eta}`\n"
157
  f"**Elapsed:** `{fmt_time(elapsed)}`"