-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload_status.py
54 lines (41 loc) · 1.37 KB
/
upload_status.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from .status import Status
from bot.helper.ext_utils.bot_utils import MirrorStatus, get_readable_file_size, get_readable_time
from bot import DOWNLOAD_DIR
class UploadStatus(Status):
def __init__(self, obj, size, listener):
self.obj = obj
self.__size = size
self.uid = listener.uid
self.message = listener.message
def path(self):
return f"{DOWNLOAD_DIR}{self.uid}"
def processed_bytes(self):
return self.obj.uploaded_bytes
def size_raw(self):
return self.__size
def size(self):
return get_readable_file_size(self.__size)
def status(self):
return MirrorStatus.STATUS_UPLOADING
def name(self):
return self.obj.name
def progress_raw(self):
try:
return self.obj.uploaded_bytes / self.__size * 100
except ZeroDivisionError:
return 0
def progress(self):
return f'{round(self.progress_raw(), 2)}%'
def speed_raw(self):
"""
:return: Upload speed in Bytes/Seconds
"""
return self.obj.speed()
def speed(self):
return f'{get_readable_file_size(self.speed_raw())}/s'
def eta(self):
try:
seconds = (self.__size - self.obj.uploaded_bytes) / self.speed_raw()
return f'{get_readable_time(seconds)}'
except ZeroDivisionError:
return '-'