Minor Changes

Signed-off-by: anas <e.anastayyar@gmail.com>
This commit is contained in:
anas 2021-08-18 15:28:27 +03:00
parent dea472274d
commit e3998e5d5d
3 changed files with 67 additions and 59 deletions

View File

@ -73,24 +73,30 @@ class qbittorrent:
gid = ''.join(random.SystemRandom().choices(string.ascii_letters + string.digits, k=14))
with download_dict_lock:
download_dict[listener.uid] = QbDownloadStatus(gid, listener, self.ext_hash, self.client)
self.updater = setInterval(self.update_interval, self.update)
tor_info = tor_info[0]
LOGGER.info(f"QbitDownload started: {tor_info.name}")
self.updater = setInterval(self.update_interval, self.update)
if BASE_URL is not None and qbitsel:
if not is_file and (tor_info.state == "checkingResumeData" or tor_info.state == "metaDL"):
if is_file:
self.client.torrents_pause(torrent_hashes=self.ext_hash)
else:
meta = sendMessage("Downloading Metadata...Please wait then you can select files or mirror torrent file if it have low seeders", listener.bot, listener.update)
while True:
tor_info = self.client.torrents_info(torrent_hashes=self.ext_hash)
if len(tor_info) == 0:
deleteMessage(listener.bot, meta)
return False
try:
tor_info = tor_info[0]
if tor_info.state == "metaDL" or tor_info.state == "checkingResumeData":
time.sleep(1)
time.sleep(0.5)
else:
break
deleteMessage(listener.bot, meta)
self.client.torrents_pause(torrent_hashes=self.ext_hash)
deleteMessage(listener.bot, meta)
break
except:
deleteMessage(listener.bot, meta)
return False
for n in str(self.ext_hash):
if n.isdigit():
pincode += str(n)
@ -106,10 +112,7 @@ class qbittorrent:
buttons.sbutton("Done Selecting", donedata)
QBBUTTONS = InlineKeyboardMarkup(buttons.build_menu(2))
msg = "Your download paused. Choose files then press Done Selecting button to start downloading."
markup = sendMarkup(msg, listener.bot, listener.update, QBBUTTONS)
with download_dict_lock:
download = download_dict[listener.uid]
download.markup = markup
sendMarkup(msg, listener.bot, listener.update, QBBUTTONS)
else:
sendStatusMessage(listener.update, listener.bot)
except qba.UnsupportedMediaType415Error as e:
@ -126,7 +129,7 @@ class qbittorrent:
if len(tor_info) == 0:
self.updater.cancel()
return
else:
try:
tor_info = tor_info[0]
if tor_info.state == "metaDL":
self.stalled_time = time.time()
@ -175,6 +178,8 @@ class qbittorrent:
self.listener.onDownloadComplete()
self.client.torrents_delete(torrent_hashes=self.ext_hash, delete_files=True)
self.updater.cancel()
except:
self.updater.cancel()
def get_confirm(update, context):
@ -193,10 +198,10 @@ def get_confirm(update, context):
query.answer()
qdl.client.torrents_resume(torrent_hashes=data[2])
sendStatusMessage(qdl.listener.update, qdl.listener.bot)
deleteMessage(context.bot, qdl.markup)
query.message.delete()
else:
query.answer(text="This task has been cancelled!", show_alert=True)
query.delete_message()
query.message.delete()
def get_hash_magnet(mgt):

View File

@ -14,7 +14,6 @@ class QbDownloadStatus(Status):
self.__gid = gid
self.__hash = qbhash
self.client = client
self.markup = None
self.__uid = listener.uid
self.listener = listener
self.message = listener.message

View File

@ -79,6 +79,10 @@ class MirrorListener(listeners.MirrorListeners):
path = fs_utils.zip(name, m_path)
else:
path = fs_utils.tar(m_path)
try:
shutil.rmtree(m_path)
except:
os.remove(m_path)
except FileNotFoundError:
LOGGER.info('File to archive not found!')
self.onUploadError('Internal error occurred!!')
@ -242,10 +246,10 @@ def _mirror(bot, update, isTar=False, extract=False, isZip=False, isQbit=False):
if link == "qbs":
qbitsel = True
link = message_args[2]
if not bot_utils.is_magnet(link):
if bot_utils.is_url(link) and not bot_utils.is_magnet(link):
resp = requests.get(link)
if resp.status_code == 200:
file_name = str(time.time()).replace(".","") + ".torrent"
file_name = str(time.time()).replace(".", "") + ".torrent"
with open(file_name, "wb") as f:
f.write(resp.content)
link = f"/usr/src/app/{file_name}"