minor fixes

Signed-off-by: anas <e.anastayyar@gmail.com>
This commit is contained in:
anas 2021-08-08 04:42:23 +03:00
parent 16d91e36c4
commit 1373d5da05
5 changed files with 15 additions and 37 deletions

View File

@ -80,7 +80,7 @@ def getDownloadByGid(gid):
def getAllDownload():
with download_dict_lock:
for dlDetails in list(download_dict.values()):
for dlDetails in download_dict.values():
if dlDetails.status() == MirrorStatus.STATUS_DOWNLOADING or dlDetails.status() == MirrorStatus.STATUS_WAITING:
if dlDetails:
return dlDetails

View File

@ -17,7 +17,7 @@ from telegram.ext import CallbackQueryHandler
from bot import download_dict, download_dict_lock, BASE_URL, dispatcher, get_client
from bot.helper.mirror_utils.status_utils.qbit_download_status import QbDownloadStatus
from bot.helper.telegram_helper.message_utils import *
from bot.helper.ext_utils.bot_utils import setInterval, new_thread, MirrorStatus
from bot.helper.ext_utils.bot_utils import setInterval, new_thread, MirrorStatus, getDownloadByGid
from bot.helper.telegram_helper import button_build
LOGGER = logging.getLogger(__name__)
@ -147,29 +147,24 @@ def get_confirm(update, context):
user_id = query.from_user.id
data = query.data
data = data.split(" ")
qdl = None
with download_dict_lock:
for dl in download_dict.values():
if dl.status() == MirrorStatus.STATUS_PAUSE:
if dl.gid() == data[1]:
qdl = dl
break
qdl = getDownloadByGid(data[1])
if qdl is not None:
if user_id != qdl.listen().message.from_user.id:
if user_id != qdl.listener.message.from_user.id:
query.answer(text="Don't waste your time!", show_alert=True)
return
if data[0] == "pin":
query.answer(text=data[2], show_alert=True)
elif data[0] == "done":
query.answer()
qdl.qbclient().torrents_resume(torrent_hashes=data[2])
sendStatusMessage(qdl.listen().update, qdl.listen().bot)
deleteMessage(context.bot, qdl.mark())
qdl.client.torrents_resume(torrent_hashes=data[2])
sendStatusMessage(qdl.listener.update, qdl.listener.bot)
deleteMessage(context.bot, qdl.markup)
else:
query.answer(text="This task has been cancelled!", show_alert=True)
query.delete_message()
def get_hash_magnet(mgt):
if mgt.startswith('magnet:'):
_, _, _, _, query, _ = urlparse(mgt)

View File

@ -13,10 +13,10 @@ class QbDownloadStatus(Status):
super().__init__()
self.__gid = gid
self.__hash = qbhash
self.__client = client
self.client = client
self.markup = None
self.__uid = listener.uid
self.__listener = listener
self.listener = listener
self.message = listener.message
@ -65,11 +65,7 @@ class QbDownloadStatus(Status):
return status
def torrent_info(self):
tor_info = self.__client.torrents_info(torrent_hashes=self.__hash)
if len(tor_info) == 0:
return None
else:
return tor_info[0]
return self.client.torrents_info(torrent_hashes=self.__hash)[0]
def download(self):
return self
@ -80,16 +76,7 @@ class QbDownloadStatus(Status):
def gid(self):
return self.__gid
def listen(self):
return self.__listener
def qbclient(self):
return self.__client
def mark(self):
return self.markup
def cancel_download(self):
LOGGER.info(f"Cancelling Download: {self.name()}")
self.__listener.onDownloadError('Download stopped by user!')
self.__client.torrents_delete(torrent_hashes=self.__hash)
self.listener.onDownloadError('Download stopped by user!')
self.client.torrents_delete(torrent_hashes=self.__hash)

View File

@ -103,7 +103,7 @@ class MirrorListener(listeners.MirrorListeners):
path = f'{DOWNLOAD_DIR}{self.uid}/{name}'
up_name = pathlib.PurePath(path).name
up_path = f'{DOWNLOAD_DIR}{self.uid}/{up_name}'
LOGGER.info(f"Upload Name: {name}")
LOGGER.info(f"Upload Name: {up_name}")
drive = gdriveTools.GoogleDriveHelper(up_name, self)
size = fs_utils.get_path_size(up_path)
upload_status = UploadStatus(drive, size, gid, self)

View File

@ -40,12 +40,8 @@ def _watch(bot: Bot, update, isTar=False):
except IndexError:
name = ""
reply_to = update.message.reply_to_message
if reply_to is not None:
tag = reply_to.from_user.username
else:
tag = None
pswd = ""
listener = MirrorListener(bot, update, pswd, isTar, tag)
listener = MirrorListener(bot, update, pswd, isTar)
ydl = YoutubeDLHelper(listener)
threading.Thread(target=ydl.add_download,args=(link, f'{DOWNLOAD_DIR}{listener.uid}', qual, name)).start()
sendStatusMessage(update, bot)