Skip to content

Commit

Permalink
Fix/improve qbittorrent
Browse files Browse the repository at this point in the history
-keep torrentool on 1.1.0 version

Signed-off-by: anas <[email protected]>
  • Loading branch information
anasty17 committed Aug 29, 2021
1 parent 2765c31 commit 942e22f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 40 deletions.
23 changes: 0 additions & 23 deletions bot/helper/custom_filters.py

This file was deleted.

1 change: 1 addition & 0 deletions bot/helper/ext_utils/fs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 10 additions & 9 deletions bot/helper/mirror_utils/download_utils/qbit_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,26 @@ def add_torrent(self, link, dire, listener, qbitsel):
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)
if op.lower() == "ok.":
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)
if len(tor_info) > 0:
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:
Expand Down Expand Up @@ -118,7 +122,8 @@ def add_torrent(self, link, dire, listener, qbitsel):
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))
Expand Down Expand Up @@ -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()

Expand Down
14 changes: 7 additions & 7 deletions bot/modules/mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
aiohttp
anytree
aria2p
attrdict
appdirs
beautifulsoup4
cloudscrape
Expand Down Expand Up @@ -28,6 +29,6 @@ speedtest-cli
telegraph
tenacity
TgCrypto
torrentool
torrentool==1.1.0
urllib3
youtube_dl

0 comments on commit 942e22f

Please sign in to comment.