From 4fa2e71e9882dbf565b443e0c985364bb29b6498 Mon Sep 17 00:00:00 2001 From: lzzy12 Date: Sat, 12 Oct 2019 22:12:07 +0530 Subject: [PATCH] Show upload ETA in appropriate time units Signed-off-by: lzzy12 --- bot/helper/ext_utils/bot_utils.py | 16 ++++++++++++++++ bot/helper/mirror_utils/download_status.py | 5 +++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/bot/helper/ext_utils/bot_utils.py b/bot/helper/ext_utils/bot_utils.py index e752ef9..68a2f6b 100644 --- a/bot/helper/ext_utils/bot_utils.py +++ b/bot/helper/ext_utils/bot_utils.py @@ -92,6 +92,22 @@ def get_readable_message(progress_list: list = None): return msg +def get_readable_time(seconds: int) -> str: + result = '' + (days, remainder) = divmod(seconds, 86400) + if days != 0: + result += f'{days}d' + (hours, remainder) = divmod(remainder, 3600) + if hours != 0: + result += f'{hours}h' + (minutes, seconds) = divmod(remainder, 60) + if minutes != 0: + result += f'{minutes}m' + + result += f'{seconds}s' + return result + + def is_url(url: str): # TODO: Find the proper way to validate the url if url.startswith('https://') or url.startswith('http://'): diff --git a/bot/helper/mirror_utils/download_status.py b/bot/helper/mirror_utils/download_status.py index c036725..184a583 100644 --- a/bot/helper/mirror_utils/download_status.py +++ b/bot/helper/mirror_utils/download_status.py @@ -1,5 +1,5 @@ from bot import aria2, DOWNLOAD_DIR -from bot.helper.ext_utils.bot_utils import get_readable_file_size, MirrorStatus +from bot.helper.ext_utils.bot_utils import get_readable_file_size, MirrorStatus, get_readable_time def get_download(gid): @@ -71,7 +71,8 @@ class DownloadStatus: self.__update() if self.status() == MirrorStatus.STATUS_UPLOADING: try: - return f'{round((self.__size() - self.uploaded_bytes) / self.__upload_speed(), 2)} seconds' + seconds = round((self.__size() - self.uploaded_bytes) / self.__upload_speed(), 2) + return f'{get_readable_time(seconds)}' except ZeroDivisionError: return '-' return self.__download.eta_string()