Minor Changes
Signed-off-by: anas <e.anastayyar@gmail.com>
This commit is contained in:
parent
dea472274d
commit
e3998e5d5d
|
|
@ -73,24 +73,30 @@ class qbittorrent:
|
||||||
gid = ''.join(random.SystemRandom().choices(string.ascii_letters + string.digits, k=14))
|
gid = ''.join(random.SystemRandom().choices(string.ascii_letters + string.digits, k=14))
|
||||||
with download_dict_lock:
|
with download_dict_lock:
|
||||||
download_dict[listener.uid] = QbDownloadStatus(gid, listener, self.ext_hash, self.client)
|
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]
|
tor_info = tor_info[0]
|
||||||
LOGGER.info(f"QbitDownload started: {tor_info.name}")
|
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 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)
|
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:
|
while True:
|
||||||
tor_info = self.client.torrents_info(torrent_hashes=self.ext_hash)
|
tor_info = self.client.torrents_info(torrent_hashes=self.ext_hash)
|
||||||
if len(tor_info) == 0:
|
if len(tor_info) == 0:
|
||||||
deleteMessage(listener.bot, meta)
|
deleteMessage(listener.bot, meta)
|
||||||
return False
|
return False
|
||||||
|
try:
|
||||||
tor_info = tor_info[0]
|
tor_info = tor_info[0]
|
||||||
if tor_info.state == "metaDL" or tor_info.state == "checkingResumeData":
|
if tor_info.state == "metaDL" or tor_info.state == "checkingResumeData":
|
||||||
time.sleep(1)
|
time.sleep(0.5)
|
||||||
else:
|
else:
|
||||||
break
|
|
||||||
deleteMessage(listener.bot, meta)
|
|
||||||
self.client.torrents_pause(torrent_hashes=self.ext_hash)
|
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):
|
for n in str(self.ext_hash):
|
||||||
if n.isdigit():
|
if n.isdigit():
|
||||||
pincode += str(n)
|
pincode += str(n)
|
||||||
|
|
@ -106,10 +112,7 @@ class qbittorrent:
|
||||||
buttons.sbutton("Done Selecting", donedata)
|
buttons.sbutton("Done Selecting", donedata)
|
||||||
QBBUTTONS = InlineKeyboardMarkup(buttons.build_menu(2))
|
QBBUTTONS = InlineKeyboardMarkup(buttons.build_menu(2))
|
||||||
msg = "Your download paused. Choose files then press Done Selecting button to start downloading."
|
msg = "Your download paused. Choose files then press Done Selecting button to start downloading."
|
||||||
markup = sendMarkup(msg, listener.bot, listener.update, QBBUTTONS)
|
sendMarkup(msg, listener.bot, listener.update, QBBUTTONS)
|
||||||
with download_dict_lock:
|
|
||||||
download = download_dict[listener.uid]
|
|
||||||
download.markup = markup
|
|
||||||
else:
|
else:
|
||||||
sendStatusMessage(listener.update, listener.bot)
|
sendStatusMessage(listener.update, listener.bot)
|
||||||
except qba.UnsupportedMediaType415Error as e:
|
except qba.UnsupportedMediaType415Error as e:
|
||||||
|
|
@ -126,7 +129,7 @@ class qbittorrent:
|
||||||
if len(tor_info) == 0:
|
if len(tor_info) == 0:
|
||||||
self.updater.cancel()
|
self.updater.cancel()
|
||||||
return
|
return
|
||||||
else:
|
try:
|
||||||
tor_info = tor_info[0]
|
tor_info = tor_info[0]
|
||||||
if tor_info.state == "metaDL":
|
if tor_info.state == "metaDL":
|
||||||
self.stalled_time = time.time()
|
self.stalled_time = time.time()
|
||||||
|
|
@ -175,6 +178,8 @@ class qbittorrent:
|
||||||
self.listener.onDownloadComplete()
|
self.listener.onDownloadComplete()
|
||||||
self.client.torrents_delete(torrent_hashes=self.ext_hash, delete_files=True)
|
self.client.torrents_delete(torrent_hashes=self.ext_hash, delete_files=True)
|
||||||
self.updater.cancel()
|
self.updater.cancel()
|
||||||
|
except:
|
||||||
|
self.updater.cancel()
|
||||||
|
|
||||||
|
|
||||||
def get_confirm(update, context):
|
def get_confirm(update, context):
|
||||||
|
|
@ -193,10 +198,10 @@ def get_confirm(update, context):
|
||||||
query.answer()
|
query.answer()
|
||||||
qdl.client.torrents_resume(torrent_hashes=data[2])
|
qdl.client.torrents_resume(torrent_hashes=data[2])
|
||||||
sendStatusMessage(qdl.listener.update, qdl.listener.bot)
|
sendStatusMessage(qdl.listener.update, qdl.listener.bot)
|
||||||
deleteMessage(context.bot, qdl.markup)
|
query.message.delete()
|
||||||
else:
|
else:
|
||||||
query.answer(text="This task has been cancelled!", show_alert=True)
|
query.answer(text="This task has been cancelled!", show_alert=True)
|
||||||
query.delete_message()
|
query.message.delete()
|
||||||
|
|
||||||
|
|
||||||
def get_hash_magnet(mgt):
|
def get_hash_magnet(mgt):
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ class QbDownloadStatus(Status):
|
||||||
self.__gid = gid
|
self.__gid = gid
|
||||||
self.__hash = qbhash
|
self.__hash = qbhash
|
||||||
self.client = client
|
self.client = client
|
||||||
self.markup = None
|
|
||||||
self.__uid = listener.uid
|
self.__uid = listener.uid
|
||||||
self.listener = listener
|
self.listener = listener
|
||||||
self.message = listener.message
|
self.message = listener.message
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,10 @@ class MirrorListener(listeners.MirrorListeners):
|
||||||
path = fs_utils.zip(name, m_path)
|
path = fs_utils.zip(name, m_path)
|
||||||
else:
|
else:
|
||||||
path = fs_utils.tar(m_path)
|
path = fs_utils.tar(m_path)
|
||||||
|
try:
|
||||||
|
shutil.rmtree(m_path)
|
||||||
|
except:
|
||||||
|
os.remove(m_path)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
LOGGER.info('File to archive not found!')
|
LOGGER.info('File to archive not found!')
|
||||||
self.onUploadError('Internal error occurred!!')
|
self.onUploadError('Internal error occurred!!')
|
||||||
|
|
@ -242,10 +246,10 @@ def _mirror(bot, update, isTar=False, extract=False, isZip=False, isQbit=False):
|
||||||
if link == "qbs":
|
if link == "qbs":
|
||||||
qbitsel = True
|
qbitsel = True
|
||||||
link = message_args[2]
|
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)
|
resp = requests.get(link)
|
||||||
if resp.status_code == 200:
|
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:
|
with open(file_name, "wb") as f:
|
||||||
f.write(resp.content)
|
f.write(resp.content)
|
||||||
link = f"/usr/src/app/{file_name}"
|
link = f"/usr/src/app/{file_name}"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue