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():
|
def clean_all():
|
||||||
aria2.remove_all(True)
|
aria2.remove_all(True)
|
||||||
get_client().torrents_delete(torrent_hashes="all", delete_files=True)
|
get_client().torrents_delete(torrent_hashes="all", delete_files=True)
|
||||||
|
get_client().auth_log_out()
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(DOWNLOAD_DIR)
|
shutil.rmtree(DOWNLOAD_DIR)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ class qbittorrent:
|
||||||
return
|
return
|
||||||
if is_file:
|
if is_file:
|
||||||
op = self.client.torrents_add(torrent_files=[link], save_path=dire)
|
op = self.client.torrents_add(torrent_files=[link], save_path=dire)
|
||||||
|
LOGGER.info(op)
|
||||||
os.remove(link)
|
os.remove(link)
|
||||||
else:
|
else:
|
||||||
op = self.client.torrents_add(link, save_path=dire)
|
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)
|
tor_info = self.client.torrents_info(torrent_hashes=self.ext_hash)
|
||||||
if len(tor_info) == 0:
|
if len(tor_info) == 0:
|
||||||
while True:
|
while True:
|
||||||
if time.time() - self.meta_time >= 300:
|
if time.time() - self.meta_time >= 20:
|
||||||
sendMessage("The Torrent was not added. report when you see this error", listener.bot, listener.update)
|
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()
|
self.client.auth_log_out()
|
||||||
return False
|
return False
|
||||||
tor_info = self.client.torrents_info(torrent_hashes=self.ext_hash)
|
tor_info = self.client.torrents_info(torrent_hashes=self.ext_hash)
|
||||||
|
|
@ -72,6 +74,8 @@ class qbittorrent:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
sendMessage("This is an unsupported/invalid link.", listener.bot, listener.update)
|
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
|
return
|
||||||
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:
|
||||||
|
|
@ -118,7 +122,8 @@ class qbittorrent:
|
||||||
sendStatusMessage(listener.update, listener.bot)
|
sendStatusMessage(listener.update, listener.bot)
|
||||||
except qba.UnsupportedMediaType415Error as e:
|
except qba.UnsupportedMediaType415Error as e:
|
||||||
LOGGER.error(str(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()
|
self.client.auth_log_out()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOGGER.error(str(e))
|
LOGGER.error(str(e))
|
||||||
|
|
@ -228,19 +233,15 @@ def get_confirm(update, context):
|
||||||
def get_hash_magnet(mgt):
|
def get_hash_magnet(mgt):
|
||||||
if mgt.startswith('magnet:'):
|
if mgt.startswith('magnet:'):
|
||||||
_, _, _, _, query, _ = urlparse(mgt)
|
_, _, _, _, query, _ = urlparse(mgt)
|
||||||
|
|
||||||
qs = parse_qs(query)
|
qs = parse_qs(query)
|
||||||
v = qs.get('xt', None)
|
v = qs.get('xt', None)
|
||||||
|
|
||||||
if v == None or v == []:
|
if v == None or v == []:
|
||||||
LOGGER.error('Invalid magnet URI: no "xt" query parameter.')
|
LOGGER.error('Invalid magnet URI: no "xt" query parameter.')
|
||||||
return False
|
return
|
||||||
|
|
||||||
v = v[0]
|
v = v[0]
|
||||||
if not v.startswith('urn:btih:'):
|
if not v.startswith('urn:btih:'):
|
||||||
LOGGER.error('Invalid magnet URI: "xt" value not valid for BitTorrent.')
|
LOGGER.error('Invalid magnet URI: "xt" value not valid for BitTorrent.')
|
||||||
return False
|
return
|
||||||
|
|
||||||
mgt = v[len('urn:btih:'):]
|
mgt = v[len('urn:btih:'):]
|
||||||
return mgt.lower()
|
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"
|
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"{file_name}"
|
||||||
else:
|
else:
|
||||||
sendMessage("ERROR: link got HTTP response:" + resp.status_code, bot, update)
|
sendMessage("ERROR: link got HTTP response:" + resp.status_code, bot, update)
|
||||||
return
|
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 not bot_utils.is_url(link) and not bot_utils.is_magnet(link) or len(link) == 0:
|
||||||
if file is not None:
|
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)
|
listener = MirrorListener(bot, update, pswd, isTar, extract, isZip)
|
||||||
tg_downloader = TelegramDownloadHelper(listener)
|
tg_downloader = TelegramDownloadHelper(listener)
|
||||||
ms = update.message
|
ms = update.message
|
||||||
tg_downloader.add_download(ms, f'{DOWNLOAD_DIR}{listener.uid}/', name)
|
tg_downloader.add_download(ms, f'{DOWNLOAD_DIR}{listener.uid}/', name)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
if isQbit:
|
link = file.get_file().file_path
|
||||||
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
|
|
||||||
|
|
||||||
if not bot_utils.is_url(link) and not bot_utils.is_magnet(link):
|
if not bot_utils.is_url(link) and not bot_utils.is_magnet(link):
|
||||||
sendMessage('No download source provided', bot, update)
|
sendMessage('No download source provided', bot, update)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
aiohttp
|
aiohttp
|
||||||
anytree
|
anytree
|
||||||
aria2p
|
aria2p
|
||||||
|
attrdict
|
||||||
appdirs
|
appdirs
|
||||||
beautifulsoup4
|
beautifulsoup4
|
||||||
cloudscrape
|
cloudscrape
|
||||||
|
|
@ -28,6 +29,6 @@ speedtest-cli
|
||||||
telegraph
|
telegraph
|
||||||
tenacity
|
tenacity
|
||||||
TgCrypto
|
TgCrypto
|
||||||
torrentool
|
torrentool==1.1.0
|
||||||
urllib3
|
urllib3
|
||||||
youtube_dl
|
youtube_dl
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue