diff --git a/bot/helper/custom_filters.py b/bot/helper/custom_filters.py deleted file mode 100644 index 0b17f44..0000000 --- a/bot/helper/custom_filters.py +++ /dev/null @@ -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 - ) diff --git a/bot/helper/ext_utils/fs_utils.py b/bot/helper/ext_utils/fs_utils.py index a7e1a4b..f4043ad 100644 --- a/bot/helper/ext_utils/fs_utils.py +++ b/bot/helper/ext_utils/fs_utils.py @@ -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: diff --git a/bot/helper/mirror_utils/download_utils/qbit_downloader.py b/bot/helper/mirror_utils/download_utils/qbit_downloader.py index 44553b4..2dda24a 100644 --- a/bot/helper/mirror_utils/download_utils/qbit_downloader.py +++ b/bot/helper/mirror_utils/download_utils/qbit_downloader.py @@ -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() diff --git a/bot/modules/mirror.py b/bot/modules/mirror.py index 689ff7f..c65c597 100644 --- a/bot/modules/mirror.py +++ b/bot/modules/mirror.py @@ -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) diff --git a/requirements.txt b/requirements.txt index 3df8cd0..b07c49f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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