Fix/improve qbittorrent
-keep torrentool on 1.1.0 version Signed-off-by: anas <e.anastayyar@gmail.com>
This commit is contained in:
parent
2765c31f92
commit
942e22f4b3
|
|
@ -1,23 +0,0 @@
|
|||
from pyrogram import filters
|
||||
|
||||
def callback_data(data):
|
||||
def func(flt, client, callback_query):
|
||||
return callback_query.data in flt.data
|
||||
|
||||
data = data if isinstance(data, list) else [data]
|
||||
return filters.create(
|
||||
func,
|
||||
'CustomCallbackDataFilter',
|
||||
data=data
|
||||
)
|
||||
|
||||
def callback_chat(chats):
|
||||
def func(flt, client, callback_query):
|
||||
return callback_query.message.chat.id in flt.chats
|
||||
|
||||
chats = chats if isinstance(chats, list) else [chats]
|
||||
return filters.create(
|
||||
func,
|
||||
'CustomCallbackChatsFilter',
|
||||
chats=chats
|
||||
)
|
||||
|
|
@ -24,6 +24,7 @@ def start_cleanup():
|
|||
def clean_all():
|
||||
aria2.remove_all(True)
|
||||
get_client().torrents_delete(torrent_hashes="all", delete_files=True)
|
||||
get_client().auth_log_out()
|
||||
try:
|
||||
shutil.rmtree(DOWNLOAD_DIR)
|
||||
except FileNotFoundError:
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ class qbittorrent:
|
|||
return
|
||||
if is_file:
|
||||
op = self.client.torrents_add(torrent_files=[link], save_path=dire)
|
||||
LOGGER.info(op)
|
||||
os.remove(link)
|
||||
else:
|
||||
op = self.client.torrents_add(link, save_path=dire)
|
||||
|
|
@ -63,8 +64,9 @@ class qbittorrent:
|
|||
tor_info = self.client.torrents_info(torrent_hashes=self.ext_hash)
|
||||
if len(tor_info) == 0:
|
||||
while True:
|
||||
if time.time() - self.meta_time >= 300:
|
||||
sendMessage("The Torrent was not added. report when you see this error", listener.bot, listener.update)
|
||||
if time.time() - self.meta_time >= 20:
|
||||
sendMessage("The Torrent was not added. Report when you see this error", listener.bot, listener.update)
|
||||
self.client.torrents_delete(torrent_hashes=self.ext_hash, delete_files=True)
|
||||
self.client.auth_log_out()
|
||||
return False
|
||||
tor_info = self.client.torrents_info(torrent_hashes=self.ext_hash)
|
||||
|
|
@ -72,6 +74,8 @@ class qbittorrent:
|
|||
break
|
||||
else:
|
||||
sendMessage("This is an unsupported/invalid link.", listener.bot, listener.update)
|
||||
self.client.torrents_delete(torrent_hashes=self.ext_hash, delete_files=True)
|
||||
self.client.auth_log_out()
|
||||
return
|
||||
gid = ''.join(random.SystemRandom().choices(string.ascii_letters + string.digits, k=14))
|
||||
with download_dict_lock:
|
||||
|
|
@ -118,7 +122,8 @@ class qbittorrent:
|
|||
sendStatusMessage(listener.update, listener.bot)
|
||||
except qba.UnsupportedMediaType415Error as e:
|
||||
LOGGER.error(str(e))
|
||||
sendMessage("This is an unsupported/invalid link. {str(e)}", listener.bot, listener.update)
|
||||
sendMessage("This is an unsupported/invalid link: {str(e)}", listener.bot, listener.update)
|
||||
self.client.torrents_delete(torrent_hashes=self.ext_hash, delete_files=True)
|
||||
self.client.auth_log_out()
|
||||
except Exception as e:
|
||||
LOGGER.error(str(e))
|
||||
|
|
@ -228,19 +233,15 @@ def get_confirm(update, context):
|
|||
def get_hash_magnet(mgt):
|
||||
if mgt.startswith('magnet:'):
|
||||
_, _, _, _, query, _ = urlparse(mgt)
|
||||
|
||||
qs = parse_qs(query)
|
||||
v = qs.get('xt', None)
|
||||
|
||||
if v == None or v == []:
|
||||
LOGGER.error('Invalid magnet URI: no "xt" query parameter.')
|
||||
return False
|
||||
|
||||
return
|
||||
v = v[0]
|
||||
if not v.startswith('urn:btih:'):
|
||||
LOGGER.error('Invalid magnet URI: "xt" value not valid for BitTorrent.')
|
||||
return False
|
||||
|
||||
return
|
||||
mgt = v[len('urn:btih:'):]
|
||||
return mgt.lower()
|
||||
|
||||
|
|
|
|||
|
|
@ -252,7 +252,7 @@ def _mirror(bot, update, isTar=False, extract=False, isZip=False, isQbit=False):
|
|||
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}"
|
||||
link = f"{file_name}"
|
||||
else:
|
||||
sendMessage("ERROR: link got HTTP response:" + resp.status_code, bot, update)
|
||||
return
|
||||
|
|
@ -294,18 +294,18 @@ def _mirror(bot, update, isTar=False, extract=False, isZip=False, isQbit=False):
|
|||
|
||||
if not bot_utils.is_url(link) and not bot_utils.is_magnet(link) or len(link) == 0:
|
||||
if file is not None:
|
||||
if file.mime_type != "application/x-bittorrent":
|
||||
if isQbit:
|
||||
file_name = str(time.time()).replace(".", "") + ".torrent"
|
||||
file.get_file().download(custom_path=f"{file_name}")
|
||||
link = f"{file_name}"
|
||||
elif file.mime_type != "application/x-bittorrent":
|
||||
listener = MirrorListener(bot, update, pswd, isTar, extract, isZip)
|
||||
tg_downloader = TelegramDownloadHelper(listener)
|
||||
ms = update.message
|
||||
tg_downloader.add_download(ms, f'{DOWNLOAD_DIR}{listener.uid}/', name)
|
||||
return
|
||||
else:
|
||||
if isQbit:
|
||||
file.get_file().download(custom_path=f"/usr/src/app/{file.file_name}")
|
||||
link = f"/usr/src/app/{file.file_name}"
|
||||
else:
|
||||
link = file.get_file().file_path
|
||||
link = file.get_file().file_path
|
||||
|
||||
if not bot_utils.is_url(link) and not bot_utils.is_magnet(link):
|
||||
sendMessage('No download source provided', bot, update)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
aiohttp
|
||||
anytree
|
||||
aria2p
|
||||
attrdict
|
||||
appdirs
|
||||
beautifulsoup4
|
||||
cloudscrape
|
||||
|
|
@ -28,6 +29,6 @@ speedtest-cli
|
|||
telegraph
|
||||
tenacity
|
||||
TgCrypto
|
||||
torrentool
|
||||
torrentool==1.1.0
|
||||
urllib3
|
||||
youtube_dl
|
||||
|
|
|
|||
Loading…
Reference in New Issue