From c0a446749afad2c31d449ae707c033d26120543d Mon Sep 17 00:00:00 2001 From: lzzy12 Date: Sat, 28 Sep 2019 02:42:44 +0530 Subject: [PATCH] Fix onDownloadComplete not being called Signed-off-by: lzzy12 --- bot/helper/download_tools.py | 45 +++++++++++++++++++----------------- bot/mirror.py | 5 +--- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/bot/helper/download_tools.py b/bot/helper/download_tools.py index 7214e89..903c379 100644 --- a/bot/helper/download_tools.py +++ b/bot/helper/download_tools.py @@ -48,37 +48,40 @@ class DownloadHelper: def __update_download_status(self): status_list = get_download_status_list() index = get_download_index(status_list, self.__get_download().gid) + # This tracks if message exists or did it get replaced by other status message + should_update = True if self.__is_torrent: # Waiting for the actual gid new_gid = None while new_gid is None: - # Check every few seconds sleep(DOWNLOAD_STATUS_UPDATE_INTERVAL) - new_gid = self.__get_followed_download_gid() - try: - self.__listener.onDownloadProgress(get_download_status_list(), index) - except KillThreadException: - return + if should_update: + # Check every few seconds + new_gid = self.__get_followed_download_gid() + try: + self.__listener.onDownloadProgress(get_download_status_list(), index) + except KillThreadException: + should_update = False download_dict[self.__listener.update.update_id] = DownloadStatus(new_gid, self.__listener.update.update_id) # Start tracking the actual download previous = None download = self.__get_download() while not download.is_complete: - status_list = get_download_status_list() - index = get_download_index(status_list, self.__get_download().gid) - if self.__get_download().has_failed: - self.__listener.onDownloadError(self.__get_download().error_message, status_list[index]) - break - # TODO: Find a better way to differentiate between 2 list of objects - progress_str_list = get_download_str() - if progress_str_list != previous: - try: - self.__listener.onDownloadProgress(status_list, index) - except KillThreadException: - return - previous = progress_str_list - download = self.__get_download() + if should_update: + status_list = get_download_status_list() + index = get_download_index(status_list, self.__get_download().gid) + if self.__get_download().has_failed: + self.__listener.onDownloadError(self.__get_download().error_message, status_list[index]) + break + # TODO: Find a better way to differentiate between 2 list of objects + progress_str_list = get_download_str() + if progress_str_list != previous: + try: + self.__listener.onDownloadProgress(status_list, index) + except KillThreadException: + should_update = False + previous = progress_str_list + download = self.__get_download() sleep(DOWNLOAD_STATUS_UPDATE_INTERVAL) - self.__listener.onDownloadComplete(status_list, index) diff --git a/bot/mirror.py b/bot/mirror.py index 25fdea1..47fa3ca 100644 --- a/bot/mirror.py +++ b/bot/mirror.py @@ -25,9 +25,7 @@ class MirrorListener(listeners.MirrorListeners): raise KillThreadException('Message deleted. Terminate thread') def onDownloadComplete(self, progress_status_list, index: int): - msg = get_readable_message(progress_status_list) LOGGER.info("Download completed") - editMessage(msg, self.context, self.reply_message) gdrive = gdriveTools.GoogleDriveHelper(self) gdrive.upload(progress_status_list[index].name()) @@ -38,8 +36,7 @@ class MirrorListener(listeners.MirrorListeners): fs_utils.clean_download(progress_status_list[index].path()) def onUploadStarted(self, progress_status_list: list, index: int): - msg = get_readable_message(progress_status_list) - editMessage(msg, self.context, self.reply_message) + pass def onUploadComplete(self, link: str, progress_status_list: list, index: int): msg = '{}'.format(link, progress_status_list[index].name())