From 7b7e339966ed8024ef926e9f9a043038138d56a1 Mon Sep 17 00:00:00 2001 From: anasty17 Date: Wed, 24 Jan 2024 23:00:34 +0200 Subject: [PATCH] Minor fixes Signed-off-by: anasty17 --- bot/helper/ext_utils/status_utils.py | 6 +++--- bot/helper/mirror_utils/gdrive_utils/download.py | 2 +- bot/helper/mirror_utils/gdrive_utils/upload.py | 13 ++++++++++--- .../mirror_utils/status_utils/aria2_status.py | 1 - .../mirror_utils/status_utils/direct_status.py | 4 +--- bot/modules/rss.py | 2 +- bot/modules/status.py | 4 ++-- bot/modules/torrent_select.py | 2 +- 8 files changed, 19 insertions(+), 15 deletions(-) diff --git a/bot/helper/ext_utils/status_utils.py b/bot/helper/ext_utils/status_utils.py index c995bd0dcfd..ce9f7301b34 100644 --- a/bot/helper/ext_utils/status_utils.py +++ b/bot/helper/ext_utils/status_utils.py @@ -3,7 +3,7 @@ from time import time from bot import DOWNLOAD_DIR, task_dict, task_dict_lock, botStartTime, config_dict -from bot.helper.telegram_helper.bot_commands import BotCommands +from bot.helper.ext_utils.bot_utils import sync_to_async from bot.helper.telegram_helper.button_build import ButtonMaker SIZE_UNITS = ["B", "KB", "MB", "GB", "TB", "PB"] @@ -50,9 +50,9 @@ async def getAllTasks(req_status: str): return [ tk for tk in task_dict.values() - if tk.status() == req_status + if (st:= await sync_to_async(tk.status) == req_status) or req_status == MirrorStatus.STATUS_DOWNLOADING - and tk.status() not in STATUS_DICT.values() + and st not in STATUS_DICT.values() ] diff --git a/bot/helper/mirror_utils/gdrive_utils/download.py b/bot/helper/mirror_utils/gdrive_utils/download.py index 54c1cb6ba69..722420b7ca6 100644 --- a/bot/helper/mirror_utils/gdrive_utils/download.py +++ b/bot/helper/mirror_utils/gdrive_utils/download.py @@ -105,7 +105,7 @@ def _download_file(self, file_id, path, filename, mime_type): if self.is_cancelled: return fh = FileIO(f"{path}/{filename}", "wb") - downloader = MediaIoBaseDownload(fh, request, chunksize=100 * 1024 * 1024) + downloader = MediaIoBaseDownload(fh, request, chunksize=50 * 1024 * 1024) done = False retries = 0 while not done: diff --git a/bot/helper/mirror_utils/gdrive_utils/upload.py b/bot/helper/mirror_utils/gdrive_utils/upload.py index c489eebfb26..76e9ad3b926 100644 --- a/bot/helper/mirror_utils/gdrive_utils/upload.py +++ b/bot/helper/mirror_utils/gdrive_utils/upload.py @@ -70,7 +70,7 @@ def upload(self, unwanted_files, ft_delete): ospath.basename(ospath.abspath(self.listener.name)), self.listener.upDest, ) - result = self._upload_dir(self._path, dir_id, unwanted_files) + result = self._upload_dir(self._path, dir_id, unwanted_files, ft_delete) if result is None: raise Exception("Upload has been manually cancelled!") link = self.G_DRIVE_DIR_BASE_DOWNLOAD_URL.format(dir_id) @@ -140,7 +140,9 @@ def _upload_dir(self, input_directory, dest_id, unwanted_files, ft_delete): stop=stop_after_attempt(3), retry=(retry_if_exception_type(Exception)), ) - def _upload_file(self, file_path, file_name, mime_type, dest_id, ft_delete, in_dir=True): + def _upload_file( + self, file_path, file_name, mime_type, dest_id, ft_delete, in_dir=True + ): # File body description file_metadata = { "name": file_name, @@ -206,7 +208,12 @@ def _upload_file(self, file_path, file_name, mime_type, dest_id, ft_delete, in_d self.switchServiceAccount() LOGGER.info(f"Got: {reason}, Trying Again.") return self._upload_file( - file_path, file_name, mime_type, dest_id + file_path, + file_name, + mime_type, + dest_id, + ft_delete, + in_dir, ) else: LOGGER.error(f"Got: {reason}") diff --git a/bot/helper/mirror_utils/status_utils/aria2_status.py b/bot/helper/mirror_utils/status_utils/aria2_status.py index ccca2b09cac..5ab1dc7bee6 100644 --- a/bot/helper/mirror_utils/status_utils/aria2_status.py +++ b/bot/helper/mirror_utils/status_utils/aria2_status.py @@ -73,7 +73,6 @@ def uploaded_bytes(self): return self._download.upload_length_string() def seed_speed(self): - self._update() return self._download.upload_speed_string() def ratio(self): diff --git a/bot/helper/mirror_utils/status_utils/direct_status.py b/bot/helper/mirror_utils/status_utils/direct_status.py index 5c686926a0b..f37bc3cfec4 100644 --- a/bot/helper/mirror_utils/status_utils/direct_status.py +++ b/bot/helper/mirror_utils/status_utils/direct_status.py @@ -34,9 +34,7 @@ def size(self): def eta(self): try: - seconds = ( - self.listener.size - self._obj.processed_bytes - ) / self._obj.speed + seconds = (self.listener.size - self._obj.processed_bytes) / self._obj.speed return get_readable_time(seconds) except: return "-" diff --git a/bot/modules/rss.py b/bot/modules/rss.py index 1dffcd2838e..f0a4117f292 100644 --- a/bot/modules/rss.py +++ b/bot/modules/rss.py @@ -138,7 +138,7 @@ async def rssSub(_, message, pre_event): msg += f"\nLink: {last_link}" msg += f"\nCommand: {cmd}" msg += ( - f"\nFilters:-\ninf: {inf}\nexf: {exf}" + f"\nFilters:-\ninf: {inf}\nexf: {exf}" ) async with rss_dict_lock: if rss_dict.get(user_id, False): diff --git a/bot/modules/status.py b/bot/modules/status.py index 69f5c3bb78c..a9ecb6390c6 100644 --- a/bot/modules/status.py +++ b/bot/modules/status.py @@ -12,7 +12,7 @@ Intervals, bot, ) -from bot.helper.ext_utils.bot_utils import new_task +from bot.helper.ext_utils.bot_utils import new_task, sync_to_async from bot.helper.ext_utils.status_utils import ( MirrorStatus, get_readable_file_size, @@ -101,7 +101,7 @@ async def status_pages(_, query): seed_speed = 0 async with task_dict_lock: for download in task_dict.values(): - match download.status(): + match await sync_to_async(download.status): case MirrorStatus.STATUS_DOWNLOADING: tasks["Download"] += 1 dl_speed += speed_string_to_bytes(download.speed()) diff --git a/bot/modules/torrent_select.py b/bot/modules/torrent_select.py index 0ea4cc82a6e..d991b665444 100644 --- a/bot/modules/torrent_select.py +++ b/bot/modules/torrent_select.py @@ -57,7 +57,7 @@ async def select(_, message): ): await sendMessage(message, "This task is not for you!") return - if task.status() not in [ + if await sync_to_async(task.status) not in [ MirrorStatus.STATUS_DOWNLOADING, MirrorStatus.STATUS_PAUSED, MirrorStatus.STATUS_QUEUEDL,