Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
Signed-off-by: anasty17 <[email protected]>
  • Loading branch information
anasty17 committed Jan 24, 2024
1 parent ef4cd89 commit 7b7e339
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 15 deletions.
6 changes: 3 additions & 3 deletions bot/helper/ext_utils/status_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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()
]


Expand Down
2 changes: 1 addition & 1 deletion bot/helper/mirror_utils/gdrive_utils/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 10 additions & 3 deletions bot/helper/mirror_utils/gdrive_utils/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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}")
Expand Down
1 change: 0 additions & 1 deletion bot/helper/mirror_utils/status_utils/aria2_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 1 addition & 3 deletions bot/helper/mirror_utils/status_utils/direct_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "-"
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/rss.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ async def rssSub(_, message, pre_event):
msg += f"\nLink: <code>{last_link}</code>"
msg += f"\n<b>Command: </b><code>{cmd}</code>"
msg += (
f"\n<b>Filters:-</b>\ninf: <code>{inf}</code>\nexf: <code>{exf}<code/>"
f"\n<b>Filters:-</b>\ninf: <code>{inf}</code>\nexf: <code>{exf}</code>"
)
async with rss_dict_lock:
if rss_dict.get(user_id, False):
Expand Down
4 changes: 2 additions & 2 deletions bot/modules/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/torrent_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7b7e339

Please sign in to comment.