Fix onDownloadComplete not being called

Signed-off-by: lzzy12 <jhashivam2020@gmail.com>
This commit is contained in:
lzzy12 2019-09-28 02:42:44 +05:30
parent bce77735ce
commit c0a446749a
2 changed files with 25 additions and 25 deletions

View File

@ -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)

View File

@ -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 = '<a href="{}">{}</a>'.format(link, progress_status_list[index].name())