Trying to fix bug
Signed-off-by: lzzy12 <jhashivam2020@gmail.com>
This commit is contained in:
parent
99efa2dacb
commit
b58cb47584
|
|
@ -17,7 +17,7 @@ def getConfig(name: str):
|
|||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
try:
|
||||
if bool(config['DEFAULT']['_____REMOVE_THIS_LINE_____']):
|
||||
if bool(getConfig('_____REMOVE_THIS_LINE_____')):
|
||||
logging.ERROR('The README.md file there to be read! Exiting now!')
|
||||
exit()
|
||||
except KeyError:
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
from bot import download_dict
|
||||
import logging
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MirrorStatus:
|
||||
|
||||
STATUS_UPLOADING = "Uploading"
|
||||
STATUS_DOWNLOADING = "Downloading"
|
||||
STATUS_WAITING = "Queued"
|
||||
|
|
@ -37,10 +39,10 @@ def get_download_status_list():
|
|||
|
||||
def get_progress_bar_string(status):
|
||||
if status.status() == MirrorStatus.STATUS_UPLOADING:
|
||||
completed = status.uploaded_bytes/8
|
||||
completed = status.uploaded_bytes / 8
|
||||
else:
|
||||
completed = status.download().completed_length/8
|
||||
total = status.download().total_length/8
|
||||
completed = status.download().completed_length / 8
|
||||
total = status.download().total_length / 8
|
||||
if total == 0:
|
||||
p = 0
|
||||
else:
|
||||
|
|
@ -48,10 +50,10 @@ def get_progress_bar_string(status):
|
|||
p = min(max(p, 0), 100)
|
||||
cFull = p // 8
|
||||
cPart = p % 8 - 1
|
||||
p_str = '█'*cFull
|
||||
p_str = '█' * cFull
|
||||
if cPart >= 0:
|
||||
p_str += PROGRESS_INCOMPLETE[cPart]
|
||||
p_str += ' '*(PROGRESS_MAX_SIZE - cFull)
|
||||
p_str += PROGRESS_INCOMPLETE[cPart]
|
||||
p_str += ' ' * (PROGRESS_MAX_SIZE - cFull)
|
||||
p_str = f"[{p_str}]"
|
||||
return p_str
|
||||
|
||||
|
|
@ -77,6 +79,7 @@ def get_readable_message(progress_list: list = download_dict.values()):
|
|||
msg += f'<b>Name:</b> {status.name()}\n' \
|
||||
f'<b>status:</b> {status.status()}\n' \
|
||||
f'<code>{get_progress_bar_string(status)}</code> {status.progress()} of {status.size()}\n' \
|
||||
f'<b>Speed:</b> {status.speed()}\n' \
|
||||
f'<b>ETA:</b> {status.eta()}\n'
|
||||
return msg
|
||||
f'<b>Speed:</b> {status.speed()}\n' \
|
||||
f'<b>ETA:</b> {status.eta()}\n'
|
||||
LOGGER.info(msg)
|
||||
return msg
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from time import sleep
|
|||
from bot import DOWNLOAD_DIR, DOWNLOAD_STATUS_UPDATE_INTERVAL, aria2
|
||||
from .download_status import DownloadStatus
|
||||
from .bot_utils import *
|
||||
from .exceptions import KillThreadException
|
||||
|
||||
|
||||
class DownloadHelper:
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
class DriveAuthError(Exception):
|
||||
pass
|
||||
|
||||
# Custom Exception class for killing thread as soon as they aren't needed
|
||||
|
||||
class KillThreadException(Exception):
|
||||
""" Custom Exception class for killing thread as soon as they aren't needed"""
|
||||
def __init__(self, message, error=None):
|
||||
super().__init__(message)
|
||||
self.error = error
|
||||
|
|
|
|||
|
|
@ -4,11 +4,12 @@ from google.auth.transport.requests import Request
|
|||
from googleapiclient.http import MediaFileUpload
|
||||
import pickle
|
||||
import os
|
||||
import time
|
||||
import logging
|
||||
from bot import LOGGER, parent_id, DOWNLOAD_DIR
|
||||
from .fs_utils import get_mime_type
|
||||
from .bot_utils import *
|
||||
import time
|
||||
import logging
|
||||
from .exceptions import KillThreadException
|
||||
|
||||
logging.getLogger('googleapiclient.discovery').setLevel(logging.ERROR)
|
||||
|
||||
|
|
@ -32,7 +33,8 @@ class GoogleDriveHelper:
|
|||
# File body description
|
||||
media_body = MediaFileUpload(file_path,
|
||||
mimetype=mime_type,
|
||||
resumable=True)
|
||||
resumable=True,
|
||||
chunksize=1024*1024)
|
||||
file_metadata = {
|
||||
'name': file_name,
|
||||
'description': 'mirror',
|
||||
|
|
@ -54,18 +56,23 @@ class GoogleDriveHelper:
|
|||
_list = get_download_status_list()
|
||||
index = get_download_index(_list, get_download(self.__listener.message.message_id).gid)
|
||||
uploaded_bytes = 0
|
||||
should_update = True
|
||||
while response is None:
|
||||
status, response = drive_file.next_chunk()
|
||||
time_lapsed = time.time() - self.start_time
|
||||
|
||||
if status:
|
||||
# The iconic formula of speed = distance / time :)
|
||||
LOGGER.info(status.progress() * 100)
|
||||
LOGGER.info(f'{file_name}: {status.progress() * 100}')
|
||||
chunk_size = status.total_size*status.progress() - uploaded_bytes
|
||||
uploaded_bytes = status.total_size*status.progress()
|
||||
download_dict[self.__listener.uid].uploaded_bytes += chunk_size
|
||||
download_dict[self.__listener.uid].upload_time = time_lapsed
|
||||
self.__listener.onUploadProgress(_list, index)
|
||||
if should_update:
|
||||
try:
|
||||
self.__listener.onUploadProgress(_list, index)
|
||||
except KillThreadException:
|
||||
should_update = False
|
||||
# Insert new permissions
|
||||
self.__service.permissions().create(fileId=response['id'], body=permissions).execute()
|
||||
# Define file instance and get url for download
|
||||
|
|
|
|||
|
|
@ -67,7 +67,10 @@ class MirrorListener(listeners.MirrorListeners):
|
|||
|
||||
def onUploadProgress(self, progress: list, index: int):
|
||||
msg = get_readable_message(progress)
|
||||
editMessage(msg, self.context, self.reply_message)
|
||||
try:
|
||||
editMessage(msg, self.context, self.reply_message)
|
||||
except BadRequest:
|
||||
raise KillThreadException('Message deleted. Do not call this method from the thread')
|
||||
|
||||
|
||||
@run_async
|
||||
|
|
|
|||
Loading…
Reference in New Issue