Skip to content

Commit

Permalink
aria eta, progress bar, readable time
Browse files Browse the repository at this point in the history
  • Loading branch information
5hojib committed Dec 6, 2024
1 parent 0afdab3 commit 0daca12
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
33 changes: 24 additions & 9 deletions bot/helper/ext_utils/status_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,28 @@ def get_readable_file_size(size_in_bytes):
return f"{size_in_bytes:.2f}{SIZE_UNITS[index]}"


def get_readable_time(seconds: int):
periods = [("d", 86400), ("h", 3600), ("m", 60), ("s", 1)]
def get_readable_time(seconds, full_time=False):
periods = [
("millennium", 31536000000),
("century", 3153600000),
("decade", 315360000),
("year", 31536000),
("month", 2592000),
("week", 604800),
("day", 86400),
("hour", 3600),
("minute", 60),
("second", 1),
]
result = ""
for period_name, period_seconds in periods:
if seconds >= period_seconds:
period_value, seconds = divmod(seconds, period_seconds)
result += f"{int(period_value)}{period_name}"
return result
plural_suffix = "s" if period_value > 1 else ""
result += f"{int(period_value)} {period_name}{plural_suffix} "
if not full_time:
break
return result.strip()


def time_to_seconds(time_duration):
Expand Down Expand Up @@ -157,12 +171,13 @@ def speed_string_to_bytes(size_text: str):


def get_progress_bar_string(pct):
pct = float(pct.strip("%"))
if isinstance(pct, str):
pct = float(pct.strip("%"))
p = min(max(pct, 0), 100)
cFull = int(p // 8)
p_str = "" * cFull
p_str += "" * (12 - cFull)
return f"[{p_str}]"
c_full = int((p + 5) // 10)
p_str = "" * c_full
p_str += "" * (10 - c_full)
return p_str


async def get_readable_message(sid, is_user, page_no=1, status="All", page_step=1):
Expand Down
3 changes: 2 additions & 1 deletion bot/helper/mirror_leech_utils/status_utils/aria2_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def size(self):
return self._download.total_length_string()

def eta(self):
return self._download.eta_string()
return get_readable_time(int(self._download.eta.total_seconds()))


def status(self):
self.update()
Expand Down

0 comments on commit 0daca12

Please sign in to comment.