Small optimisations all around
Signed-off-by: lzzy12 <jhashivam2020@gmail.com>
This commit is contained in:
parent
8e886a3030
commit
4e1f7a8a77
|
|
@ -55,21 +55,8 @@ def get_readable_file_size(size_in_bytes) -> str:
|
||||||
return 'File too large'
|
return 'File too large'
|
||||||
|
|
||||||
|
|
||||||
def get_download(message_id):
|
|
||||||
with download_dict_lock:
|
|
||||||
return download_dict[message_id].download()
|
|
||||||
|
|
||||||
|
|
||||||
def get_download_status_list():
|
|
||||||
with download_dict_lock:
|
|
||||||
return list(download_dict.values())
|
|
||||||
|
|
||||||
|
|
||||||
def get_progress_bar_string(status):
|
def get_progress_bar_string(status):
|
||||||
if status.status() == MirrorStatus.STATUS_UPLOADING:
|
completed = status.processed_bytes() / 8
|
||||||
completed = status.obj.uploaded_bytes / 8
|
|
||||||
else:
|
|
||||||
completed = status.download().completed_length / 8
|
|
||||||
total = status.size_raw() / 8
|
total = status.size_raw() / 8
|
||||||
if total == 0:
|
if total == 0:
|
||||||
p = 0
|
p = 0
|
||||||
|
|
@ -94,14 +81,6 @@ def get_download_index(_list, gid):
|
||||||
index += 1
|
index += 1
|
||||||
|
|
||||||
|
|
||||||
def get_download_str():
|
|
||||||
result = ""
|
|
||||||
with download_dict_lock:
|
|
||||||
for status in list(download_dict.values()):
|
|
||||||
result += (status.progress() + status.speed() + status.status())
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def get_readable_message():
|
def get_readable_message():
|
||||||
with download_dict_lock:
|
with download_dict_lock:
|
||||||
msg = ""
|
msg = ""
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
from bot import aria2, DOWNLOAD_DIR
|
from bot import aria2, DOWNLOAD_DIR
|
||||||
from bot.helper.ext_utils.bot_utils import get_readable_file_size, MirrorStatus, get_readable_time
|
from bot.helper.ext_utils.bot_utils import MirrorStatus
|
||||||
from .download_status import DownloadStatus
|
from .status import Status
|
||||||
|
|
||||||
|
|
||||||
def get_download(gid):
|
def get_download(gid):
|
||||||
return aria2.get_download(gid)
|
return aria2.get_download(gid)
|
||||||
|
|
||||||
|
|
||||||
class AriaDownloadStatus(DownloadStatus):
|
class AriaDownloadStatus(Status):
|
||||||
|
|
||||||
def __init__(self, gid, listener):
|
def __init__(self, gid, listener):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
@ -38,31 +38,31 @@ class AriaDownloadStatus(DownloadStatus):
|
||||||
"""
|
"""
|
||||||
return self.download().total_length
|
return self.download().total_length
|
||||||
|
|
||||||
|
def processed_bytes(self):
|
||||||
|
return self.download().completed_length
|
||||||
|
|
||||||
def speed(self):
|
def speed(self):
|
||||||
self.__update()
|
return self.download().download_speed_string()
|
||||||
return self.__download.download_speed_string()
|
|
||||||
|
|
||||||
def name(self):
|
def name(self):
|
||||||
self.__update()
|
return self.download().name
|
||||||
return self.__download.name
|
|
||||||
|
|
||||||
def path(self):
|
def path(self):
|
||||||
return f"{DOWNLOAD_DIR}{self.__uid}"
|
return f"{DOWNLOAD_DIR}{self.__uid}"
|
||||||
|
|
||||||
def size(self):
|
def size(self):
|
||||||
return self.__download.total_length_string()
|
return self.download().total_length_string()
|
||||||
|
|
||||||
def eta(self):
|
def eta(self):
|
||||||
self.__update()
|
return self.download().eta_string()
|
||||||
return self.__download.eta_string()
|
|
||||||
|
|
||||||
def status(self):
|
def status(self):
|
||||||
self.__update()
|
download = self.download()
|
||||||
if self.download().is_waiting:
|
if download.is_waiting:
|
||||||
status = MirrorStatus.STATUS_WAITING
|
status = MirrorStatus.STATUS_WAITING
|
||||||
elif self.download().is_paused:
|
elif download.is_paused:
|
||||||
status = MirrorStatus.STATUS_CANCELLED
|
status = MirrorStatus.STATUS_CANCELLED
|
||||||
elif self.__download.has_failed:
|
elif download.has_failed:
|
||||||
status = MirrorStatus.STATUS_FAILED
|
status = MirrorStatus.STATUS_FAILED
|
||||||
else:
|
else:
|
||||||
status = MirrorStatus.STATUS_DOWNLOADING
|
status = MirrorStatus.STATUS_DOWNLOADING
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
# Generic status class. All other status classes must inherit this class
|
# Generic status class. All other status classes must inherit this class
|
||||||
|
|
||||||
|
|
||||||
class DownloadStatus:
|
class Status:
|
||||||
|
|
||||||
def progress(self):
|
def progress(self):
|
||||||
"""
|
"""
|
||||||
|
|
@ -34,3 +34,7 @@ class DownloadStatus:
|
||||||
""":return String describing what is the object of this class will be tracking (upload/download/something
|
""":return String describing what is the object of this class will be tracking (upload/download/something
|
||||||
else) """
|
else) """
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def processed_bytes(self):
|
||||||
|
""":return The size of file that has been processed (downloaded/uploaded/archived)"""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
@ -1,13 +1,16 @@
|
||||||
from .download_status import DownloadStatus
|
from .status import Status
|
||||||
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
|
||||||
|
|
||||||
|
|
||||||
class TarStatus(DownloadStatus):
|
class TarStatus(Status):
|
||||||
def __init__(self, name, path, size):
|
def __init__(self, name, path, size):
|
||||||
self.__name = name
|
self.__name = name
|
||||||
self.__path = path
|
self.__path = path
|
||||||
self.__size = size
|
self.__size = size
|
||||||
|
|
||||||
|
# The progress of Tar function cannot be tracked. So we just return dummy values.
|
||||||
|
# If this is possible in future,we should implement it
|
||||||
|
|
||||||
def progress(self):
|
def progress(self):
|
||||||
return '0'
|
return '0'
|
||||||
|
|
||||||
|
|
@ -29,3 +32,5 @@ class TarStatus(DownloadStatus):
|
||||||
def status(self):
|
def status(self):
|
||||||
return MirrorStatus.STATUS_ARCHIVING
|
return MirrorStatus.STATUS_ARCHIVING
|
||||||
|
|
||||||
|
def processed_bytes(self):
|
||||||
|
return 0
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
from .download_status import DownloadStatus
|
from .status import Status
|
||||||
from bot.helper.ext_utils.bot_utils import MirrorStatus, get_readable_file_size, get_readable_time
|
from bot.helper.ext_utils.bot_utils import MirrorStatus, get_readable_file_size, get_readable_time
|
||||||
from bot import DOWNLOAD_DIR
|
from bot import DOWNLOAD_DIR
|
||||||
|
|
||||||
|
|
||||||
class UploadStatus(DownloadStatus):
|
class UploadStatus(Status):
|
||||||
def __init__(self, obj, size, uid):
|
def __init__(self, obj, size, uid):
|
||||||
self.obj = obj
|
self.obj = obj
|
||||||
self.__size = size
|
self.__size = size
|
||||||
|
|
@ -12,6 +12,9 @@ class UploadStatus(DownloadStatus):
|
||||||
def path(self):
|
def path(self):
|
||||||
return f"{DOWNLOAD_DIR}{self.uid}"
|
return f"{DOWNLOAD_DIR}{self.uid}"
|
||||||
|
|
||||||
|
def processed_bytes(self):
|
||||||
|
return self.obj.uploaded_bytes
|
||||||
|
|
||||||
def size_raw(self):
|
def size_raw(self):
|
||||||
return self.__size
|
return self.__size
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -242,7 +242,7 @@ class GoogleDriveHelper:
|
||||||
f"</a> (folder)"
|
f"</a> (folder)"
|
||||||
if INDEX_URL is not None:
|
if INDEX_URL is not None:
|
||||||
url = f'{INDEX_URL}/{file.get("name")}/'
|
url = f'{INDEX_URL}/{file.get("name")}/'
|
||||||
msg += f'| <a href="{url}"> Index URL</a>'
|
msg += f' | <a href="{url}"> Index URL</a>'
|
||||||
else:
|
else:
|
||||||
msg += f"⁍ <a href='https://drive.google.com/uc?id={file.get('id')}" \
|
msg += f"⁍ <a href='https://drive.google.com/uc?id={file.get('id')}" \
|
||||||
f"&export=download'>{file.get('name')}</a> ({get_readable_file_size(int(file.get('size')))})"
|
f"&export=download'>{file.get('name')}</a> ({get_readable_file_size(int(file.get('size')))})"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue